HitTestObject issues

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;
}

Answers


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.


Need Your Help

SUM a list of values (contain sub query)

sql sql-server sql-server-2012

I currently have a bit of code that fetches the latest Exchange Rates and converts a list of values, as some of the values are in GBP already then I am using a CASE statement...

PHP date time format - 2012-08-16T21:14:03.447?

php mysql

What format is this date time in PHP 2012-08-16T21:14:03.447?

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.