Hello guys, how do I check if an object is on top of another?
Printable View
Hello guys, how do I check if an object is on top of another?
Use movieclip.getDepth() to get the depth and compare it to the depth of any other clip on the stage.
See https://www.kirupa.com/developer/act...pt/depths2.htm for more information.
sometimes getdepth wont work without this at the top:
import mx.managers.DepthManager;
Hmm.. I will chek it, thank you guys.
Sorry for the spam, but, I dont understand how to compare the Depth of two objects. What I try is simple, check if the player is up of a ball, if this is true, enable a var and the function to enter in the tank when click the space key.
Hi,
You can try to get what you need from this.
PHP Code:trace("Orignal Depths\nball: " + ball.getDepth() + " \nplayer: " + player.getDepth());
function newDepths():Void
{
ball.swapDepths(this.getNextHighestDepth());
player.swapDepths(this.getNextHighestDepth());
var a:Number = ball.getDepth();
var b:Number = player.getDepth();
trace("\n\nNew Depths\nball: " + a + " \nplayer: " + b);
if (b > a)
{
trace("\nYou can now set your var");
}
}
newDepths();
Hello guy, I test this code but dont work correctly. I want this:
Attachment 75679
Attachment 75681
Understand?
Man, I was working with the wrong code. The correct is use the hitTest function. Thanks anyway!