T
thken
Guest
Hello everyone, I am new for Game maker and I am making a tower defense game with game maker studio 1.4.
However I encountered a problem when i am making the tower control menu
(you can treat it as a menu next to any tower on the field with buttons "Upgrade tower", "Repair Tower", "Sell Tower", "Sell Tower". However, whether I put the code into my towerParent object or objectController object, there are always problems.
Be specific, when I put two towers from Tower Selection Menu to the field, I can open the Tower Control Menu when I click the last tower I put, but I cannot open the Tower Control Menu when I click the first tower I put.
Anyone with experience making tower defense game can help for this? Any hints for critical functions I should input or any approach are all appreciated.
My code is as follow:
In object objTowerParent, global left pressed event:
However I encountered a problem when i am making the tower control menu
(you can treat it as a menu next to any tower on the field with buttons "Upgrade tower", "Repair Tower", "Sell Tower", "Sell Tower". However, whether I put the code into my towerParent object or objectController object, there are always problems.
Be specific, when I put two towers from Tower Selection Menu to the field, I can open the Tower Control Menu when I click the last tower I put, but I cannot open the Tower Control Menu when I click the first tower I put.
Anyone with experience making tower defense game can help for this? Any hints for critical functions I should input or any approach are all appreciated.
My code is as follow:
In object objTowerParent, global left pressed event:
Code:
if(position_meeting(mouse_x,mouse_y,self))
{
if(instance_exists(objTowerBattleMenu))
{
with(objTowerBattleMenu)
{
instance_destroy();
}
with(objSell)
{
instance_destroy();
}
with(objUpgrade)
{
instance_destroy();
}
with(objRepair)
{
instance_destroy();
}
with(objDestroy)
{
instance_destroy();
}
}
else
{
instance_create(x,y,objTowerBattleMenu);
objTowerBattleMenu.depth=-1000;
instance_create(x+36,y,objSell);
instance_create(x-36,y,objUpgrade);
objSell.depth=-1100 ;
objUpgrade.depth=-1100;
instance_create(x+14,y+22,objDestroy);
instance_create(x-14,y+22,objRepair);
objDestroy.depth=-1100 ;
objRepair.depth=-1100;
}
}
else
{
if(position_meeting(mouse_x,mouse_y,objUpgrade)){}
else if(position_meeting(mouse_x,mouse_y,objSell)){}
else if(position_meeting(mouse_x,mouse_y,objDestroy)){}
else if(position_meeting(mouse_x,mouse_y,objRepair)){}
else
if(!position_meeting(mouse_x,mouse_y,objTowerBattleMenu))&&!(position_meeting(mouse_x,mouse_y,objUpgrade))&&!(position_meeting(mouse_x,mouse_y,objSell))
{
if(instance_exists(objTowerBattleMenu))
{
with(objTowerBattleMenu)
{
instance_destroy();
}
with(objSell)
{
instance_destroy();
}
with(objUpgrade)
{
instance_destroy();
}
with(objRepair)
{
instance_destroy();
}
with(objDestroy)
{
instance_destroy();
}
}
}
}
Attachments
-
11.4 KB Views: 6