Spritemap/Timer question!


(Nate ) #1

I have a player class for my game, I create a variable of the player as a spritemap, then set graphic = playerSprite! The only two images I have for him so far are, alive and dead.

When the player dies in the game it shows the death image for like a milisecond then it immediately respawns him.

I am looking to have it so the death image can be seen for at least two seconds, then the respawn takes place. I used to know how to do this with timers and timer listeners in AS3 but was wondering what the general protocol would be for Flashpunk!

Thanks guys! :smiley: :sunny: :wink:


(Jacob Albano) #2

This really isn’t a question about Spritemaps, it’s a logic issue.

If you want to set up timed events, check out the Alarm class.


(Nate ) #3

Okay thank you Jacob!


(Nate ) #4

Hey Jacob I am trying to set up my alarm for the death image, let me know what you think please. Here is all of the alarm related stuff I have:

import net.flashpunk.tweens.misc.Alarm; private var alarm:Alarm;

override public function added():void { alarm = new Alarm(2, Respawn, 0); }

public function Death():void { death = false; lives–;

alarm.start; }

public function Respawn():void { x = spawnX; y = spawnY;

alarm.reset; }


(Jacob Albano) #5

It looks like your main problem here is that you haven’t added the Alarm to the entity. Alarm is a tween class, so it has to be added to a tweener in order to update.

import net.flashpunk.tweens.misc.Alarm;

//	...

private var alarm:Alarm;

//	...
override public function added():void
{
	//	setting it to persist will leave the alarm in the tweener after
	//	it finishes, so you can use it again
	alarm = new Alarm(2, Respawn, PERSIST);
	addTween(alarm);
}

public function Death():void
{ 
	death = false;
	lives--;
	alarm.start();
}

public function Respawn():void
{
	x = spawnX;
	y = spawnY;

	alarm.reset();
}

I’m not sure if it was just a problem with the way the forum handled your code, but you were missing parentheses after the the calls to alarm.reset and alarm.start. That would definitely be a problem too!


(Nate ) #6

Thank you Jacob. I was missing the parens after start and reset. I just set it up as you have outlined above, however I am getting a lone error of:

“col:11 Error: Incorrect number of arguments. Expected 1.”

And that just seems to be about the reset call?


(Jacob Albano) #7

Sorry, that’s my fault. I was just fixing up formatting and didn’t realize it needed an argument to run. You don’t actually even want to call reset() there, as it starts the alarm again. Leaving it out shouldn’t cause any problem.


(Nate ) #8

Okay perfect thank you so much! :smiley: