Tap object not working as intended.

Discussion and feedback on Construct 2

Post » Thu Feb 16, 2017 11:19 am

Hi, i have a strange issue. I have a sprite, when you tap on it a new sprite with a magnifying glass should appear on it, clicking on it a text box is created with description and magnifyng glass sprite is destroied. problem is that when you tap, the magnifying glass sprite won't appear because the same tap is triggered for both action, so only text will appear on top...
I tried to solve adding a 0,01 wait, but then when i click on m. glass, the TAP will be triggered both for that sprite and the one underneath, creating again the m. Glass sprite on it... do not know if i've explained it well (sorry for my bad english...)
B
6
S
1
Posts: 75
Reputation: 575

Post » Thu Feb 16, 2017 2:15 pm

If I understood your problem right, then change the event's like this:
Tap on object - create magnifying glass
Tap on magnifying glass - destroy it
B
137
S
33
G
17
Posts: 1,560
Reputation: 20,797

Post » Thu Feb 16, 2017 3:46 pm

@pcprice76
I was dealing with a similar mouse issue last night - I was doing something when the left mouse button was clicked on an object. But I was also doing something while the left button was down in another fuction. Out of curiosity, I put a counter in that button down function, and it was getting called on average 9 times along with the first routine. And that was just a normal short mouse click.

Things generally happen a lot quicker than you think. I bet C2 thinks your "touch" event happens for quite a few ticks. On the first tick of the touch it creates the m.Glass, then the next tick thinks you are touching the m.Glass. so starts running that code. The 0.01 second delay may not be long enough.

Another issue I ran into months ago is that a tap on objects that overlap registers as a tap on all of them. So, you need to make a way to disable the first sprite while the m.Glass sprite is visible. Then re-enable it when you destroy the m.Glass one. Making the first sprite invisible will not work - the tap will still be processed for it. you have to disable the events where it processes the tap, or move the sprite off screen, or add conditions that say not to process the tap if the m.Glass sprite is overlapping or visible.
B
99
S
35
G
20
Posts: 438
Reputation: 17,910

Post » Thu Feb 16, 2017 4:24 pm

If you have both mouse and tap commands in your game they read as the same command for tap on object and click on object.

On Tap On Object............ Create MagnifyingGlass on Position Object
----------------------------------- Destroy Object

On Tap On Magnifying Glass- Open Textbox
----------------------------------------- Create object on Position MagnifyingGlass
------------------------------------------ Destroy MagnifyingGlass


I think that is what you are trying to do?
Banned User
B
28
S
7
G
58
Posts: 1,229
Reputation: 34,830

Post » Thu Feb 16, 2017 5:31 pm

AllanR wrote:@pcprice76
I was dealing with a similar mouse issue last night - I was doing something when the left mouse button was clicked on an object. But I was also doing something while the left button was down in another fuction. Out of curiosity, I put a counter in that button down function, and it was getting called on average 9 times along with the first routine. And that was just a normal short mouse click.

Things generally happen a lot quicker than you think. I bet C2 thinks your "touch" event happens for quite a few ticks. On the first tick of the touch it creates the m.Glass, then the next tick thinks you are touching the m.Glass. so starts running that code. The 0.01 second delay may not be long enough.

Another issue I ran into months ago is that a tap on objects that overlap registers as a tap on all of them. So, you need to make a way to disable the first sprite while the m.Glass sprite is visible. Then re-enable it when you destroy the m.Glass one. Making the first sprite invisible will not work - the tap will still be processed for it. you have to disable the events where it processes the tap, or move the sprite off screen, or add conditions that say not to process the tap if the m.Glass sprite is overlapping or visible.

YES! You got it... my problem is the sum of your two ones.
I realized that more then one tap was triggered and i think that with WAIT was solved, because after that the M. Glass was showing up normally. The second issue is that clicking on it,it triggered both overlapping sprites, so, at the same time:
1) Function description, that describes object and destroy sprite m. Glass
2) Function object select that triggers the tap on underneath object and creates again the M. Glass on it.
So the M. Glass remain always on top of the object, never being destroyed (or, better, being destroyed and recreated at the same time)
In this case WAIT is useless because the problem is that TAP takes both objects and triggers 2 functions.
I could make the M. Glass appear shifted to the side of touch.X but would prefer to find a way to solve this porblem, 'cause i'm sure that can be useful in future.. :)
B
6
S
1
Posts: 75
Reputation: 575

Post » Fri Feb 17, 2017 4:15 am

@pcprice76

There are a bunch of ways to make it do what you want... it depends on how complex your project is. If there is a lot going on, and you want to pause all that and enter a different state, then you would want to put code in different groups and disable groups you don't want running. (that would disable the sprite that creates the m.Glass one, so you don't have to worry about it processing a tap).

The most simple way is to just make sure the m.Glass sprite is not overlapping the other sprite. I made a quick example of that...

http://www.rieperts.com/games/forum/Tap.capx
B
99
S
35
G
20
Posts: 438
Reputation: 17,910

Post » Sun Feb 26, 2017 10:27 am

AllanR wrote:@pcprice76

There are a bunch of ways to make it do what you want... it depends on how complex your project is. If there is a lot going on, and you want to pause all that and enter a different state, then you would want to put code in different groups and disable groups you don't want running. (that would disable the sprite that creates the m.Glass one, so you don't have to worry about it processing a tap).

The most simple way is to just make sure the m.Glass sprite is not overlapping the other sprite. I made a quick example of that...

http://www.rieperts.com/games/forum/Tap.capx

Hi, sorry for replying you late, but you gave me really good hints! :)
I will for sure use the Group disable feature in some parts of the game, i nvere noticed that before :/
My first idea was to make M.Glass appear beside the touch.x, but i want to solve the issue the same, because it will appear overlapping some other objects.
I tried now to put another confition (if M.GLASS is not on layout 0) but... is really, strange, it doesn't work even if is correct...
M.Glass is not on layout and event is not triggering the same.... really weird...
B
6
S
1
Posts: 75
Reputation: 575


Return to Construct 2 General

Who is online

Users browsing this forum: No registered users and 10 guests