I’m a new FlashPunk developer and I have a very noob issue. By the way please apologize my english grammar (you can write your complaints to the Google Translator team if you have one :D)
I have 2 entities acting as a buttons, these two objects sometimes may be overlapped and when I want to click one of them (in this case the entity that is on top) if the entity that is behind of it is in certain position, it also receives the click event and as result I have two clicks “events” in one Mouse Click…
The code that I’m using is the following:
if (collidePoint(x, y, Input.mouseX, Input.mouseY))
{
if (Input.mouseReleased)
{
clicked();
}else if (Input.mouseDown)
{
mouseDown();
}else {
mouseOver();
}
}
I’ve solved this issue by adding one static boolean var and the result is (In my Entities)
if (collidePoint(x, y, Input.mouseX, Input.mouseY))
{
if (Input.mouseReleased)
{
if(Button.!isClicked){ Button.isClicked = true; clicked(); }
}else if (Input.mouseDown)
{
mouseDown();
}else {
mouseOver();
}
}
(In my WORLD update)
override public function update():void
{
super.update();
if (Button.isClicked) { Button.isClicked = false; }
}
The thing is that I’m developing a RTS game and I may have two or more units overlapped in a certain moment and if the player try to click one unit to select will select the whole units in one click and I’m not sure if my solution is the best for this situation.