Reputation: 1
I have a problem where in a game. when I make in a place the first tower the GUI works fine, but when I place the second tower the GUI only works for that second tower, and it just goes on and on for each newest tower my place.
Step Event:
if placed != false
{
image_alpha = 1;
if collision_circle(x,y,200,oEnemy,false,true)
{
if instance_exists(oEnemy)
{
target = instance_nearest(x,y,oEnemy)
if target.x < x
{
direction = point_direction(x-18,y,target.x,target.y);
}
else
{
direction = point_direction(x+18,y,target.x,target.y);
}
if alarm[0] = -1
{
alarm[0] = 60;
}
}
}
if mouse_check_button(mb_any)
{
if !position_meeting(mouse_x,mouse_y,self)
{
GuiOpen = false;
}
else
{
GuiOpen = true
}
}
}
else
{
x = mouse_x;
y = mouse_y;
image_alpha = 0.5;
}
if GuiOpen = true
{
instance_create_layer(x,y-65,"Instances2",o_Tower1Upgrade);
}
else
{
instance_destroy(o_Tower1Upgrade);
instance_destroy(o_tower1upgradebutton1);
}
I tried my best to figure out the bug but i really just can't, theres no errors in the output or anything i could find thats wrong with my code.
Upvotes: 0
Views: 38
Reputation: 2122
Instead of position_meeting
you might wanna try instance_position
.
The reason for this is because "_meeting" means if any object of that type will fullfill their role, rather than the specific object you want to get.
I based this off a similair experience I had with place_meeting
and instance_place
. The problem and solution looks pretty similair:
https://gamedev.stackexchange.com/questions/158359/when-there-are-multiple-objects-of-the-same-type-how-do-i-know-which-one-i-am-c
Upvotes: 0