Skip to content

Instantly share code, notes, and snippets.

@videlais
Created October 18, 2013 03:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save videlais/7035869 to your computer and use it in GitHub Desktop.
Save videlais/7035869 to your computer and use it in GitHub Desktop.
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