This is the Bullet.as class
package {
import net.flashpunk.Entity;
import net.flashpunk.Graphic;
import net.flashpunk.FP;
import net.flashpunk.graphics.Image;
/**
* ...
* @author GranitBa
*/
public class Bullet extends Entity {
[Embed(source="media/Bullet.png")]
public const BULLET:Class;
public function Bullet() {
x = 250;
y = 100;
setHitbox(12, 15);
type = "bullet";
graphic = new Image(BULLET);
}
public function destroy():void {
FP.world.remove(this);
}
}
}
And this is the class where i handle the collision
package {
import net.flashpunk.Entity;
import net.flashpunk.graphics.Image;
import net.flashpunk.utils.Input;
import net.flashpunk.utils.Key;
/**
* ...
* @author GranitBa
*/
public class Player extends Entity {
[Embed(source="media/Ship.png")]
private const PLAYER:Class;
public function Player() {
graphic = new Image(PLAYER);
setHitbox(50, 50);
}
override public function update():void {
var b:Bullet = collide("bullet", x, y) as Bullet;
if (b) {
trace("Collided!");
}
if (Input.check(Key.LEFT)) {
x -= 4.5;
}
if (Input.check(Key.RIGHT)) {
x += 4.5;
}
if (Input.check(Key.DOWN)) {
y += 3;
}
if (Input.check(Key.UP)) {
y -= 5;
}
}
}
}
In the gameworld class i just add them both to the world and in the main class i set up that world.
It could also be the player.as fault.