mouse clicked/mouse over-difference?

For questions about using Classic.

Post » Sun Dec 13, 2009 5:38 pm

The problem I have is: when I hover (no click) over a sprite, all spawned instances react, instead of only that one sprite.

[code:309roz2z]MouseKeyboard: On Left Clicked on Sprite
> Sprite set opacity to 20[/code:309roz2z]
With 4 instances spawned, no problems here. Only the instance I clicked on gets the opacity-change.


[code:309roz2z]MouseKeyboard: Mouse is over Sprite
> Sprite set opacity to 20[/code:309roz2z]
Problem here is: all 4 instances get an opacity of 20, instead of the 1 instance I am pointing at.

How should I change the code so that I can point at 1 instance and only that pointed on instance gets the opacity change?
B
16
S
5
G
7
Posts: 599
Reputation: 5,000

Post » Sun Dec 13, 2009 5:52 pm

Mouse & Keyboard should be picking the affected sprites properly. However, you could try working around it by throwing a "For each sprite" condition above it.
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,580

Post » Sun Dec 13, 2009 6:09 pm

I changed the use of private variable (the Sprite) to global variable, as switch and it works now.
I didn't know this had impact on the decision making of Construct.

The setup was:
- switch turned on (private variable sprite set to "1")
- mouse over 1 of the 4 instances of sprite: they all responded.

The setup is now:
- switch turned on (global variable set to "1")
- mouse over 1 of the 4 instances of sprite: only the pointed at-sprite responds.

Thanks for reading and the reply.
B
16
S
5
G
7
Posts: 599
Reputation: 5,000

Post » Sun Dec 13, 2009 9:04 pm

[quote="rogerty":14zw2f25]
The setup was:
- switch turned on (private variable sprite set to "1")
- mouse over 1 of the 4 instances of sprite: they all responded.
[/quote:14zw2f25]

Try reversing the order of the conditions to:

- if mouse is over sprite
- private variable sprite is set to 1

Also make sure that the pv you're checking for is 1, not "1".

Edit: In the example you mentioned, how many sprites had a pv=1? Each extra condition works as an "and". If there were no sprites with a pv=1, this could have happened:

If pv=1 (if there are none, construct picks no sprites)
AND
mouse is over sprite (there were no sprites chosen from the previous condition - therefore still no sprites chosen because no sprites meet BOTH conditions)

Then the object list has no picked sprites, so when you tell construct to set the opacity, it sets the opacity of all of them.
Moderator
B
88
S
32
G
33
Posts: 3,005
Reputation: 27,432

Post » Sun Dec 13, 2009 9:07 pm

Thanks, I'll try it
B
16
S
5
G
7
Posts: 599
Reputation: 5,000


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 6 guests