How do I select single object?

Get help using Construct 2

Post » Wed Sep 23, 2015 9:15 pm

Hi all. I have an event as follows,

Every Tick
When right mouse button is down
'Build_Collision' Object is overlapping 'Block' Object
>
Set 'Block' position to mouse.x mouse.y

I'm trying to figure out a way to only select 1 'Block' object when the collision is overlapping. Any ideas? Ive only managed to create a big mess so far. Thanks
B
9
S
3
Posts: 104
Reputation: 1,033

Post » Wed Sep 23, 2015 10:53 pm

If I understand you correctly,

You don't need "every tick". Try reversing your condition.

Block object is overlapping Build_Collision
Image
B
75
S
23
G
3
Posts: 673
Reputation: 9,273

Post » Wed Sep 23, 2015 11:11 pm

I didn't explain myself very well sorry.

What i'm trying to do is, when the 'Build_Collision' overlaps more than one 'Block', only 1 instance of the 'Block' object is set the the mouse position.

At the moment it selects all instances of the 'Block' object overlapping the 'Build_Collision'. I just need 1 at a time.

I've tried a few things, but cant get my head around it.
B
9
S
3
Posts: 104
Reputation: 1,033

Post » Thu Sep 24, 2015 7:18 am

You can use "Pick random instance" condition after overlap condition.

Edit: Just realized this wouldn't work as this would pick new random instance every tick. You will need more comlicated set of events and conditions to pick only once.

I'm not quite sure I understand what you are trying to do. Maybe it would be better to perform action when mouse button is clicked insteas of while pressed.
Lokkim Games: Constructor Dude - Fun platformer game, PuzCro - Difficult puzzle game demo
B
9
S
3
G
1
Posts: 38
Reputation: 795

Post » Thu Sep 24, 2015 10:37 pm

Yeah its a tricky one for me.

Imagine you have some square blocks, when the mouse is down it creates an invisible object set to cursor position.
When the invisible object overlaps the block, the block is set also set to cursor position. After the first block is set to mouse position, no further blocks are affected by the invisible collision.

I've tried giving the collision object a variable called 'picked', when the block overlaps it, set the variable to 1. On release set it back to 0. This doesn't seem to work.

ill gladly try an ideas.
B
9
S
3
Posts: 104
Reputation: 1,033

Post » Fri Sep 25, 2015 12:07 am

Could you post your Capx file?
B
15
S
6
Posts: 105
Reputation: 1,356

Post » Fri Sep 25, 2015 8:12 am

OK. Now I understand it better.

You should give instance variable 'picked' for block (not for your collision object). Then when mouse is clicked use overlap and pick random instance conditions to pick one of the blocks that are overlapping the collision object. Set variable 'picked' to true for picked 'block'.

Then make two separate events:
'Block' is 'picked' -> Set 'Block' position to mouse.x mouse.y
Mouse On button released -> 'Block' Set 'picked' to false

The basic idea is to pick one block when mouse is clicked. Keep moving it to mouse position as long as the 'picked' variable is true. And finally set 'picked' variable false for all blocks when mouse button is released.

Instead picking random you can pick nearest if it works better for your game.
Lokkim Games: Constructor Dude - Fun platformer game, PuzCro - Difficult puzzle game demo
B
9
S
3
G
1
Posts: 38
Reputation: 795

Post » Fri Sep 25, 2015 8:23 am

Thanks! How would i go about selecting the closest instance of an object to the mouse cursor? ill give it a try this evening and let you know how it goes.
B
9
S
3
Posts: 104
Reputation: 1,033

Post » Fri Sep 25, 2015 8:26 am

try using the system event pick by comparing, and then use when on mouse over uritem pick by comparing z index is greater then uritem.zindex that way will automatically pick the item u hover that is above
B
70
S
20
G
67
Posts: 1,315
Reputation: 42,303

Post » Sat Sep 26, 2015 5:41 am

Sorted it!

I was trying to cram too much into one event as usual. Having the block to 'Picked' on mouse down, and setting the position when block is 'Picked' was the way to go.

Thanks a bunch.
B
9
S
3
Posts: 104
Reputation: 1,033


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 14 guests