Thanks alot for this. It looks pretty logic and its very educational.
But i was wondering whats with that “this” in the public function?
Also i think the way with the one spritesheet is much more comfortable for me in this particular. im not so sure about the memory usage if that may cause unnecessary delays since thats my second project (first were the tutorials from here). but i think i can use this for the switch between walking and running i will try to figure it out on my own so my brain doesnt get to rusty and habituate on asking for every problems solution in here ;D
to make my step to the one spritesheet clear i post my code (i’ve got from another extern tutorial)
i think its more comfortable because i need the switch to the standing sprites if the entity is stop running
package
{
// import not included
public class Hero extends Entity
{
[Embed(source="../assets/sprGehen.png")]private const sprMoriGehen:Class;
public var MoriGehen:Spritemap = new Spritemap(sprMoriGehen, 31, 56);
public var curAnimation:String = "MstehtS";
public var speedGehen:Number = 30;
public function Hero()
{
setupSpritesheet();
graphic = MoriGehen;
type = "mori";
Input.define("MoveLeft", Key.A, Key.LEFT);
Input.define("MoveUp", Key.W, Key.UP);
Input.define("MoveDown", Key.S, Key.DOWN);
Input.define("MoveRight", Key.D, Key.RIGHT);
}
override public function update():void
{
var horizontalBewegung:Boolean = true;
var verticalBewegung:Boolean = true;
MoriGehen.play(curAnimation);
if (Input.check("MoveLeft"))
{
x -= speedGehen * FP.elapsed;
curAnimation = "MgehtW";
}
else if (Input.check("MoveRight"))
{
x += speedGehen * FP.elapsed;
curAnimation = "MgehtO";
}
else horizontalBewegung = false;
if (Input.check("MoveUp"))
{
y -= speedGehen * FP.elapsed;
curAnimation = "MgehtN";
}
else if (Input.check("MoveDown"))
{
y += speedGehen * FP.elapsed;
curAnimation = "MgehtS";
}
else verticalBewegung = false;
if ((!verticalBewegung) && (!horizontalBewegung))
{
switch(curAnimation)
{
case "MgehtN": curAnimation = "MstehtN"; break;
case "MgehtS": curAnimation = "MstehtS"; break;
case "MgehtW": curAnimation = "MstehtW"; break;
case "MgehtO": curAnimation = "MstehtO"; break;
}
}
}
private function setupSpritesheet():void
{
MoriGehen.add("MstehtN", [0], 0, false);
MoriGehen.add("MgehtN", [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16], 16, true);
MoriGehen.add("MstehtS", [17], 0, false);
MoriGehen.add("MgehtS", [18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33], 16, true);
MoriGehen.add("MstehtW", [34], 0 , false);
MoriGehen.add("MgehtW", [35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50], 16, true);
MoriGehen.add("MstehtO", [51], 0, false);
MoriGehen.add("MgehtO", [52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67], 16, true);
}
}
}