I have a problem when rotating an entitys sprite and its collision. It seems like I cant get the collision right. Here you can play an example: [Here][1][1]: https://dl.dropboxusercontent.com/u/37437508/Test.swf
Use wsad or arrows and space to move
The collision seems to be happening to early if the collision happens on the right side.
Here is part of the class that is shooting the bullet:
public function Shooter(xPos:int, yPos:int, speed:Number, isRotating:String, angle:String)
{
x = xPos+ (width/2);
y = yPos+ (height/2);
fireSpeed = speed/100;
pixelMask.originX = 16;
layer = -2;
graphic = pixelMask;
if(isRotating == "False")
this.isRotating = false;
else if(isRotating == "True")
this.isRotating = true;
angle = angle.replace(angle.charAt(1), ".");
this.angle = (Number(angle)*(180/Math.PI));
type = "shooter";
pixelMask.originX = width / 2;
pixelMask.originY = height / 2;
}
And:
if (player != null) {
if(timer >= 1){
bulletAngle = pixelMask.angle-90;
FP.world.add(new Bullet(x, y, bulletAngle));
timer = 0;
}
timer += fireSpeed;
}
And here is part of the bullet class:
public function Bullet(xPos:int, yPos:int, angle:Number, isSearching:Boolean = false, ignoreCollision:Boolean = false )
{
this.angle = angle;
x = xPos;
y = yPos;
BULLET_SPEED = 10;
this.isSearching = isSearching;
this.ignoreCollision = ignoreCollision;
xVel = BULLET_SPEED * Math.cos(angle * FP.RAD);
yVel = BULLET_SPEED * Math.sin(angle * FP.RAD);
sprite.centerOrigin();
sprite.angle = angle;
type = "bulletDamage";
graphic = sprite;
mask = new Pixelmask(sprite.getBuffer());
}
override public function update(): void {
lifeTime += FP.elapsed;
if (lifeTime > 15) {
FP.world.recycle(this);
}
moveBy(xVel, yVel, ["level", "damage", "player"]);
}
override public function moveCollideX(e:Entity):Boolean {
if (!collide("level", x, y) && !collide("damage", x, y) && !collide("player", x, y)) {
return false;
}else {
FP.world.recycle(this);
return true;
}
}
override public function moveCollideY(e:Entity):Boolean {
if (!collide("level", x, y) && !collide("damage", x, y) && !collide("player", x, y)) {
return false;
}else {
FP.world.recycle(this);
return true;
}
}
I also have modified the Image class so I can acces the buffer.
Anyody got any ideas?