1 decade ago by congwang0517
I try to " entity.animSheet = new ig.AnimationSheet..." and entity.addAnim('idle',60,[0]);
But it can't work.
But it can't work.
This forum is read only and just serves as an archive. If you have any questions, please post them on github.com/phoboslab/impact
ig.module( 'game.entities.penguin' ) .requires( 'game.entities.special.creature' ) .defines(function(){ EntityPenguin = EntityCreature.extend({ animSheet: new ig.AnimationSheet( 'media/sprites/penguin.png', 64, 74 ), init: function( x, y, settings ) { this.parent( x, y, settings ); this.addAnim( 'idle', this.framerate, [0, 1, 2, 3] ); } }); });
ig.module( 'game.entities.penguin' ) .requires( 'game.entities.special.creature' ) .defines(function(){ EntityPenguin = EntityCreature.extend({ animNormal: new ig.AnimationSheet( 'media/sprites/penguin.png', 64, 74 ), animFly: new ig.AnimationSheet( 'media/sprites/penguinfly.png', 64, 74 ), animSheet: null, init: function( x, y, settings ) { this.parent( x, y, settings ); this.animSheet = this.animNormal; this.addAnim( 'idle', this.framerate, [0, 1, 2, 3] ); }, setAnimFly: function() { this.animSheet = this.animFly; this.addAnim( 'idle', this.framerate, [0, 1, 2, 3] ); }, setAnimNormal: function() { this.animSheet = this.animNormal; this.addAnim( 'idle', this.framerate, [0, 1, 2, 3] ); }, update: function() { if (something or other) { this.setAnimNormal(); } if (something or other) { this.setAnimFly(); } } }); });
039;s #addAnim()
function is just a shorthand for the ig.Animation
constructor that always uses the .animSheet
property of the entity.ig.Animation
constructor directly:EntityTest = ig.Entity.extend({ runAnimSheet: new ig.AnimationSheet( 'media/run.png', 8, 8 ), idleAnimSheet: new ig.AnimationSheet( 'media/idle.png', 8, 8 ), init: function( x, y, settings ) { this.parent( x, y, settings ); this.anims.run = new ig.Animation( this.runAnimSheet, 0.2, [0,1,2] ); this.anims.idle = new ig.Animation( this.idleAnimSheet, 0.2, [0,1,2] ); } });