Hi,
I was wondering if there is a way to check if something (Player) enters a perimeter of another object, just like having a circular hitbox or a rounded mask, thank you.
Hi,
I was wondering if there is a way to check if something (Player) enters a perimeter of another object, just like having a circular hitbox or a rounded mask, thank you.
Theres always a way.
The simplest way is to use a pixelmask.
var bitmapData:BitmapData = new BitmapData(2*RADIUS, 2*RADIUS, true, 0);
Draw.setTarget(bitmapData);
Draw.circle(RADIUS, RADIUS, RADIUS);
var pixelmask:Pixelmask = new Pixelmask(bitmapData);
mine.mask = pixelmask;
Obviously, changle RADIUS
for your radius. If you want to use the exact same radius multiple times, use the same pixelmask.
That’s a good way to put it, i also went for Draw.circlePlus to be able to set the fill attribute ^^.
Thanks man.
Although @Copying’s solution is much more efficient, in case you can’t use a pixelmask you can always check the actual distance.
if(FP.distance(object.x, object.y, player.x, player.y) < RADIUS) {
//Do stuff
}
@Copying’s solution is absolutely not more efficient. Your way is much better.
Actually there the improved version should be:
public static function insideRadius(objectX:Number, objectY:Number, playerX:Number, playerX:Number, radius:Number):Boolean
{
var x:Number = playerX - objectX;
var y:Number = playerY - objectY;
return (x * x + y * y) < (radius * radius);
}
This solution is more efficient but ignores the player mask and it’s a distance to a fixed point.
… That’s a great idea, i didn’t know about the FP.distance, that’s very straight forward :), the same thing about the use of the Pythagore equation ^^, thanks guys.