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 badabam

I want to move a character to some waypoints.

These waypoints are each represented by a blinking box. Right now, they all blink in total disorder, because the are spawned each on a click by the user and start with the animation when the get initialized.

How is it possible to let them blink all together, i.e. synchronized? I thought of a global timer and set the animationframe on update, on a specific delta and reset that timer globally.

But maybe there is a better way! Do you have any suggestions?

Thank you very much!

- Jerry

1 decade ago by dominic

I think having a global timer would be the easiest solution. You could just create a timer as a class property of your Waypoint Entity and set the animation's timer to this one.

I.e. something like this:
EntityWaypoint = ig.Entity.extend({
	init: function( x, y, settings ) {
		this.parent( x, y, settings );
		
		this.addAnim( 'blink', 0.5, [0,1] );

		// Set the animation's timer to the global one
		this.anims.blink.timer = EntityWaypoint.animationTimer;
	},
});

// Create a global timer as class var
EntityWaypoint.animationTimer = new ig.Timer();

1 decade ago by badabam

Yeah, thank you very much, Dominic!
I didn't know an animatino has its own timer variable that i can set ... I guess I have to get more familiar with the source!

- Jerry

1 decade ago by vincentpiel

It would be even simpler to have all entities share the same animation.
And clearer to do have it done in init.

EntityWaypoint = ig.Entity.extend({
          animSheet : new ig.AnimationSheet( 'sheet.png', 16, 16 ),
    init: function( x, y, settings ) {
                          this.parent( x, y, settings );
                          if ( ! EntityWaypoint.blinkAnim) 
  {  EntityWaypoint.blinkAnim =  new ig.Animation(this.animSheet,  0.5, [0,1] )  }
                          this.anims['blink']=EntityWaypoint.blinkAnim;
    }
})

Rq : 0.5 is a 'big' time for an anim. You should try something like
0.1, [0,0,0,0,0,1,1,1,1,1] you'd be surprised how sensitive is the eye/brain
to the small timing errors a big animation frame time induces.
Page 1 of 1
« first « previous next › last »