Reputation: 63
I have a bit of a problem with hitTestObject
in Flash.
I have these tiles generated on the screen and I have a player added to the tiles. I created an invisible square bitmap for the player, which is the size of the tile so it can register whether it is hitting the tile completely. The problem is, it is registering hit test from tiles that aren't even next to the player. The link below, My mouse is over the tile that is highlighted, and I have a trace that checks the hitTest between the player and the current Tile that it's on.
http://postimg.org/image/6so3npm19/
Here is the code for the bitmap. I've been playing around with the x and y position and the size of it.
visionArea.graphics.beginFill(0x00FF00, 1.0);
visionArea.graphics.drawRect(0, 0, 85, 85);
visionArea.graphics.endFill();
var matrix:Matrix = new Matrix();
matrix.rotate(Math.PI / 4);
matrix.scale(1, 0.5);
visionArea.transform.matrix = matrix;
addChild(visionArea);
visionArea.mouseEnabled = false;
visionArea.visible = false;
visionArea.x = 4;
visionArea.y = -21;
When I click a tile and the player is next to it, I move it to that tile.
if (player.visionArea.hitTestObject(event.currentTarget as Tile))
{
player.x = (event.currentTarget.x)+55;
player.y = (event.currentTarget.y)+20;
}
I also have an enemy on the screen (the green tile). I'm trying to have the player not be able to go on the tile that the enemy is on, but sometimes it would work, sometimes it wouldn't.
if (enemy.enemyVisionArea.hitTestObject(event.currentTarget as Tile))
{
player.x != (event.currentTarget.x)+55;
player.y != (event.currentTarget.y)+20;
}
Upvotes: 0
Views: 260
Reputation: 887
if (player.visionArea.hitTestObject(event.currentTarget as Tile) && !enemy.enemyVisionArea.hitTestObject(event.currentTarget as Tile))
{
player.x = (event.currentTarget.x)+55;
player.y = (event.currentTarget.y)+20;
}
I've never seen anyone use != as an assignment operator.
Upvotes: 1