Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
ActionScript 3 Example 4 PlayerSprite Version 1
package
{
/**
* ...
* @author Dan Cox
*/
import org.flixel.*;
public class PlayerSprite extends FlxSprite
{
[Embed(source = "data/walk.png")] private var WalkPng:Class;
public function PlayerSprite(X:Number = 0, Y:Number = 0)
{
super(X, Y);
loadGraphic(WalkPng, true, false);
addAnimation("Down", [0, 1, 2], 10, false);
addAnimation("Right", [3, 4, 5], 10, false);
addAnimation("Left", [6, 7, 8], 10, false);
addAnimation("Up", [9, 10, 11], 10, false);
}
override public function update():void
{
super.update();
if (FlxG.keys.W || FlxG.keys.UP)
{
y -= 3;
play("Up");
}
else if (FlxG.keys.S || FlxG.keys.DOWN)
{
y += 3;
play("Down");
}
else if (FlxG.keys.A || FlxG.keys.LEFT)
{
x -= 3;
play("Left");
}
else if (FlxG.keys.D || FlxG.keys.RIGHT)
{
x += 3;
play("Right");
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.