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 Graphikos

I have a basic moving platform entity that I want to change the appearance of. How can I change the currentAnim of a new entity?

I was able to do it after the spawn.

var platform = this.spawnEntity( EntityPlatform, x, y );
platform.currentAnim = platform.anims.red;

Can you not do it with the settings of spawnEntity()?

Thanks!

1 decade ago by MikeL

Here is one method. I have a game now which has buidlings which are essentially the same except for the color. The init is something like this:

    animSheet: new ig.AnimationSheet( 'media/building-btms.png', 220, 21),
   color: "orange",

   init: function( x, y, settings ) {
        this.parent( x, y, settings );
      
        this.addAnim( 'orange', 1, [0] );
        this.addAnim( 'blue', 1, [1] );
        this.addAnim( 'purple', 1, [2] );
        this.addAnim( 'red', 1, [3] );

        this.currentAnim = this.anims[this.color];
   }

Now if you spawn an entity like this:
ig.game.spawnEntity(x, y, {color: "blue"});

then you get a blue building. Otherwise it defaults to orange. The advantage to this also is that you can set color directly in Weltmeister as well.

1 decade ago by MikeL

I should also mention that each building color is in a different frame of the same png. I added it to the code above.

1 decade ago by Graphikos

Thanks MikeL! That's a good way of doing it!
Page 1 of 1
« first « previous next › last »