So I’m new to flashpunk and I’ve been following the official tutorials. Everything was fine until I got to using spritemaps. When I use add(new Player()); the player gets created and updates, but is not actually added to the world. It’s nothing to do with the change to a using a spritemap, as I changed it back to using a single image and it still happened.
Main.as:
package
{
import net.flashpunk.Engine;
import net.flashpunk.FP;
/**
* ...
* @author Alice Davies
*/
public class Main extends Engine
{
public function Main():void
{
super(800, 600, 60, false);
FP.world = new MainMenu;
}
override public function init():void
{
}
}
}
MainMenu.as:
package
{
import net.flashpunk.World;
/**
* ...
* @author Alice Davies
*/
public class MainMenu extends World
{
public function MainMenu()
{
add(new Player());
}
}
}
Player.as:
package
{
import net.flashpunk.Entity;
import net.flashpunk.graphics.Image;
import net.flashpunk.graphics.Spritemap;
import net.flashpunk.utils.Input;
/**
* ...
* @author Alice Davies
*/
public class Player extends Entity
{
[Embed(source = "assets/player.png")]
private const SPRITE_SHEET:Class;
public var sprPlayer:Spritemap = new Spritemap(SPRITE_SHEET, 128, 128);
private var speed:Number;
private var targetX:Number;
private var targetY:Number;
public function Player()
{
sprPlayer.add("idle", [0, 1], 2, true);
sprPlayer.add("runLeft", [2, 3], 2, true);
sprPlayer.add("runRight", [4, 5], 2, true);
graphic = sprPlayer;
sprPlayer.play("idle");
trace("Player constructor");
speed = 5;
name = "player";
type = "player";
}
override public function update():void
{
if (Input.mousePressed)
{
trace("move command");
targetX = Input.mouseX
targetY = Input.mouseY;
}
moveTowards(targetX, targetY, speed, null, false);
}
}
}
Maybe I’m missing something but looking at the tutorials it doesn’t seem like I’m doing anything wrong.