"Animating" Entity by editing ScaleY


(Secret) #1

Hi guys.

So I have this entity which represents a tile which should flip when it is clicked on and reveal its other side. Now for the animation of “flipping” I figured I’d use ScaleY and scale it to 0 the back to 1 but with a different graphic.

Here is the code:

override public function update():void
	{
		if((collidePoint(x,y,FP.world.mouseX, FP.world.mouseY)) && !(_animating)) {
			_animating = true;
			flipTile();
		}
	}

The _animating is there so that it would only call the flipTile function once as needed.

public function flipTile():void
	{

		while(_Spritesheet.scaleY > 0){
			_Spritesheet.scaleY -= 1 * FP.elapsed;
		}

		if(_faceDown) _Spritesheet.play(_tileID + "_face");
		else _Spritesheet.play("back_face");

		_Spritesheet.scaleY=0;
		
		while(_Spritesheet.scaleY < 1){
			_Spritesheet.scaleY += 1 * FP.elapsed;
		}
		_Spritesheet.scaleY=1;
		
		_animating = false;
	}

Now in my head I thought it should work but when I run it, it takes about 2 seconds(expectedly) to change to the new graphic, however it doesn’t actually "animate’ the flip. to shrink and then expand. I’m not sure if I’m doing it correctly and what I should do to have the correct behavior.


(Jonathan Stoler) #2

It looks like you’re missing a super.update() in your update() function.


(Abel Toy) #3

while doesn’t work this way. while executes all at once on a single frame.

I recommend you to read basic AS3 tutorials and get a grasp of the language and how it works first.

Then, in order to make the animation, you need to use if conditionals instead of while, because the code will execute every frame and you want to know what action to do on each state of the animation.


(Secret) #4

Thanks. I got it working :slight_smile:


Help with a Delay