HaxeFlixel Logo HaxeFlixel Snippets
  • About
  • Back to HaxeFlixel.com
    • Screen
    • Adding
    • Alive
    • Health
    • Making Sprites
    • Loading Sprites
    • Animation
    • Alpha
    • Color
    • Facing
    • Scale
    • Baked Rotations
    • FlxText
    • FlxBitmapText
    • Velocity
    • Acceleration
    • MaxVelocity
    • Gravity
    • Jumping
    • Angle
    • Angular Velocity
    • Angular Acceleration
    • Basic Group
    • Typed Group
    • Recycling
    • Sorting
    • Tileblock
    • Tilemap
    • Ray
    • tileProperties
    • Autotiles
    • Simple Overlap
    • Overlap Callbacks
    • 1-to-1 Collision
    • Immovable
    • Tilemap Collision
    • Moving Platforms
    • Flash
    • Fade
    • Shake
    • Follow
    • scrollFactor
    • Basics
    • Keyboard
    • Gamepad
    • Mouse
    • Button
    • FlxSound
    • FlxState
    • FlxSubState
    • Tween
    • Angle
    • Color
    • Motion
    • Num
    • Callbacks
    • FlxTimer
    • FlxSignal
    • moveTowards
    • Distance
    • velocityFromAngle
    • timeScale
    • drawLine

Baked Rotations

Using baked rotations is a great way to improve graphical performance when dealing with rotating sprites. Load your the graphic for your FlxSprite by using FlxSprite.loadRotatedGraphic(), and the system will generate a sprite sheet for your sprite that has frames for all of the possible angles. When you set the angle of a FlxSprite which is using baked rotations, it will choose the frame(s) that are closest to your specified angle.

// sprite's graphic will be baked using 16 rotations.
sprite.loadRotatedGraphic('path/to/image.png', 16);

Demonstration

Source

View Source on GitHub

package;

import flixel.FlxG;
import flixel.FlxSprite;
import flixel.FlxState;

class PlayState extends FlxState
{
	var sprite:FlxSprite;

	override public function create()
	{
		bgColor = 0;

super.create();

		sprite = new FlxSprite();
		sprite.loadRotatedGraphic("assets/arrow.png", 16);
		sprite.screenCenter();
		add(sprite);
	}

	override public function update(elapsed:Float)
	{
		sprite.angle++;

		super.update(elapsed);
	}
}

Tags

sprites graphics
Powered By HaxeFlixel Logo HaxeFlixel