Hey guys! It’s been a while!
I am getting back into FlashPunk and working on a very simple project. I am attempting to use create/destroy/recycle as I know that is the best way to handle things.
I have a player and I want him to throw coins up on the Y axis.
Here is the relevant player code in the player update:
if(Input.pressed(Key.SPACE))
{
var _coin:theCoin = FP.world.create(theCoin) as theCoin;
_coin.setMovement(this.y);
trace("coin created");
}
Here is the coin.as class:
package entities {
import net.flashpunk.Entity;
import net.flashpunk.FP;
import net.flashpunk.graphics.Image;
public class theCoin extends Entity
{
[Embed(source = '../assets/coin.png')]
public static const COIN:Class;
private var moveY:Number = 0;
public function theCoin()
{
graphic = new Image(COIN);
setHitbox(8, 8);
type = "coin";
layer = 0;
}
public function setMovement(_y:Number = 0):void
{
moveY = _y;
}
override public function update():void
{
y -= moveY * FP.elapsed;
}
public function destroy():void
{
FP.world.recycle(this);
}
}}
Not sure what I am doing incorrectly, sorry in advance for sloppy code.
Thank you!