I am trying to make it so you select the base by pressing it and then the arrow pops up when its selected, and goes away when you de-select it by pressing it again. I made an instance variable called selected to make it work, please tell me what im doing wrong! Below is a capture of the event.
Spawning on layer 0 which is the bottom layer. Might be behind another object.
No idea what you are doing wrong, but here is a workaround.
Pin the Checkmark to the objects you want selectable, when you spawn them.
At spawn turn the checks invisible.
On mouse over set it to Visible 50%
On mouseover and left click, set to visible 100%
Invert a mouse over the checkmark, and set to invisible.
TL;DR, Use visibility, and toggle it on and off with clicks rather than trying to spawn one every time you need it.
If you add the Checkmark to a container, it will automatically destroy with the object it is parented to.
Hope that helps, my english is not so good.
Your second Touch event is triggering after your first on the same touch - so you touch it, the variable changes to 1, then the next event in the line triggers and since Selected is now 1 it fires and destroys the other sprite immediately.
Try only having one touch event and have sub events to check the instance variable, like so:
Edit: the Move to Top of Layer thing isn't necessary, I just had it in to make sure it wasn't spawning behind the first sprite (it wasn't)
Wertle I tried that and now the arrow will pop up, but wont go away when i click it again :/
and the main thing I need working is the selecting, the arrow is just for visuals. Only a selected base sends troops so it is huge that I get it working properly!
Develop games in your browser. Powerful, performant & highly capable.
something was wrong with the touch, I made it wait 1/8 of a second before doing anything after the touch and it fixed it. thanks for your help everyone
yeah in future you can debug check variables with text objects so that you know for sure they are being set correctly.