Sorry for what is probably a very silly question, I’ve just started using Flashpunk/AS3/coding in general. Currently I have written some code that moves my player about (not code below). I want the movement to be like Snake though, which I can’t seem to do.
So far, I have:
package { import net.flashpunk.Entity; import net.flashpunk.graphics.Image; import net.flashpunk.utils.Input; import net.flashpunk.utils.Key;
public class SnakePlayer extends Entity
{[Embedded images...]}
public function SnakePlayer()
{
graphic = new Image(PLAYERUP);
x = 300;
y = 400;
}
var speedx:int;
var speedy:int;
override public function update():void
{
speedx = 0;
speedy = -3;
x += speedx
y += speedy
if (Input.check(Key.LEFT)) { speedx = 3; speedy = 0; graphic = new Image(PLAYERLEFT); } ...
}
}
}
It starts off moving straight upwards.
Essentially, when I press LEFT I want speedx to be assigned a new value, i.e. speedx=3; likewise I want to change speedy to 0. However, it doesn’t do anything other than change the image (from the graphic=new… as it’s supposed to). I think I need to loop it somehow, or use an update function somewhere?
I tried using while loops, but I haven’t got the hang of them yet and they stop the flash player working.
Please explain as simply as possible if answering.