FP
has the ability to rotate the graphics of any Entity
so you don’t necessarily need to use the Prerotation
class if all you want to do is rotate an Entity’s graphic
property.
In most instances you would probably extend Entity
and have a variable hold the graphic resource that is your Entity
's graphic and provide a getter and setter for it’s angle like so:
package
{
import net.flashpunk.Entity;
import net.flashpunk.graphics.Image;
public class Enemy extends Entity
{
protected var _gfk:Image;
public function Enemy()
{
super();
graphic = _gfk = new Image(Assets.SPR_IMG);
_gfk.centerOO();
}
public function set angle(angle:Number):void
{
_gfk.angle = angle;
}
public function get angle():Number
{
return _gfk.angle;
}
}
}
Then somewhere (like in your world class) you can adjust the angle like so:
_enemyInstance.angle = 45;
This would just set the rotation of the graphic to 45 degrees so you wouldn’t see any animation. To see it rotate as an animation you would need to adjust the angle over n frames, most likely you would do this in your World
's update override like so:
override public function update():void
{
super.update();
_enemyInstance.angle++;
}
With all that said, the Prerotation
class will take in your graphic and generate a sort of runtime Spritesheet of your graphic rotated at n angles depending on the frame count. The default is 36 so it will create a 36 frame Spritesheet where each frame is your graphic rotated 10 degrees (360 / 36 = 10)
. You can use this Protation
type in place of the Image
type in the same code above.
Setting the angle of the Entity
's graphic will still be done in the same way except that the graphic will show only those prerendered rotations. So lets say that on any given frame the angle property of the Entity
's graphic is 12.265 degrees, it will display the frame that is closest to that value, so in this case it would be the frame rendered at 10 degrees (assuming were using the default frame count).
The Prerotation
class is usefull for reducing calculation in the game loop. Blitting a prerendered image is a lot faster than having to calculate the transformation of an image before blitting, but know that you trade memory for speed with this technique.