Game Development Community

Changing sprite size on the fly

by Todd Pickens · in Torque Game Builder · 11/28/2006 (12:16 pm) · 6 replies

I am trying to figure out how to have an animated sprite change size over the course of an animation.

The cell art for my units animation is based on 128x128 pixels, the unit fills up most of this. But in the case of the loop animation, I am using 256x256 pixel frames so that I have room for the unit to change size.

Creating the art was easy, basically I have my unit flying along and when you hit a key, it does a loop up toward the camera. In the art for the loop animation, I have the unit scale up as if it were actually getting closer to the camera, and return to its normal size by the end of the animation.

The problem is that in the TGB script, the unit is defined as being a specific size, so when the "loop" animation plays, the 256x256 art gets scaled down to fit in the same space as the 128x128 sprites.

Does any one know a solution for this?

Any help is deeply appreciated.

#1
11/29/2006 (7:09 am)
Just under the "setanimation" or "playanimation", do this :

//double the size
%this.setsize(%this.getsize() * 2);
//double the collision polygon accordinly to size
%this.setcollisionpolyscale(2, 2);

It might work.

After this, to go back to 128*128 redo the same but replace all the 2 by 0.5.
#2
11/29/2006 (8:58 am)
Thanks very much Benjamin, I'll give it a try.
#3
11/29/2006 (2:05 pm)
Ah, Sorry, I forgot that "%this.setcollisionpolyscale" is only a number between 0.0 and 1.0... the thing I did was to set it to 0.5 when I double the size, so the collision polygon do not get streched too. I now remember.

So what you would want to do would be

//double the size
%this.setsize(%this.getsize() * 2);
//keep the collision polygon at the same size
%this.setcollisionpolyscale(0.5, 0.5);

and to go back to 128*128

//divide the size
%this.setsize(%this.getsize() / 2);
//Return collision poly to its normal scale
%this.setcollisionpolyscale(1, 1);
#4
11/29/2006 (2:22 pm)
Thanks very much Benjamin,

I will point my coder at this and see if he can implement it.

For what we are doing, the collision is actually not important because the unit is invulnerable during the animation in question.
#5
11/30/2006 (3:21 am)
One interesting aspect of changing the size on the fly would be to give the 2d level some "depth".. By allocating say layers 10-20 then from 16-20 shrink and 15-10 grow you could have a top down airplane/spaceship (or even dropped items (bombs)) appear to be in 3d space.

I haven't tested this.. its just a theory :)
#6
11/30/2006 (8:46 am)
@ Thank,

Thats exactly what we are doing :O)