Impact

This forum is read only and just serves as an archive. If you have any questions, please post them on github.com/phoboslab/impact

1 decade ago by congwang0517

I try to " entity.animSheet = new ig.AnimationSheet..." and entity.addAnim('idle',60,[0]);
But it can't work.

1 decade ago by gxxaxx

Below is the code for a penquin I'm using in one of my games.
This code is extending my basic Creature. You will probably be using
ig.Entity

Hope this helps.

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] );
	}
	
});

});

To have changing animation I would do something like:


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();
		}
	}	
});

});

This is not running code. Just an example. Which means don't be surprised if there is a typo (or idiot mistake). But it does illustrate the kind of thing I do.

1 decade ago by dominic

The entity&039;s #addAnim() function is just a shorthand for the ig.Animation constructor that always uses the .animSheet property of the entity.

To specify different animation sheets, use the 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] );
	}
});

1 decade ago by gxxaxx

Q: Then the anims object can contain animations from a mixture of AnimationSheets?

This will surely simplify things. Thanks. For the answer and for the nice underlying code in the engine.

1 decade ago by brainversation

THANKS!!!!!!!!!
Page 1 of 1
« first « previous next › last »