Ensuring two sprites are in same place

Get help using Construct 2

Post » Fri Feb 01, 2013 8:06 pm

A simplified version of what I'm trying to achieve.

I have a 7x7x7 grid and I need to make sure that only one of a certain object can occupy a grid location.

So I pick my object, decide where I want to put it, then I need to check all of the other objects to make sure they're not in that same location. Since I've already picked one object, I'm not sure how to repick them all without losing my first pick - and since I've already picked one object, I can't pick the whole lot now anyway.

So my attempt to solve this was to create a 7x7x7 array, do a loop where each object puts a '1' in the place it's occupying, then when I place the new object, compare against the array. If there's a 1 there, it's occupied.

For some reason that I can't fathom that doesn't work.

I may be overcomplicating this, any ideas?

B
25
S
5
G
3
Posts: 446
Reputation: 5,633

Post » Fri Feb 01, 2013 9:39 pm

Yeah you could simply do a quick test if a spot is taken or not by examining what's under the mouse at all times. So your game would always know if the space is taken or not before the player clicks.

system every tick
mouse is over "sprite"
set global variable "taken" to 1

if "taken" = 0 then allow player to place piece where they clicked.



justifun2013-02-01 21:40:18
B
50
S
21
G
8
Posts: 844
Reputation: 10,299

Post » Fri Feb 01, 2013 10:35 pm

That was just an example really, my own code is a bit more complex. This all needs to happen internally, not something that can be worked around on the screen. I basically need to know how I can test an object against all of the other objects of the same type, since once you've picked an object, how can you then pick all the others and compare them against the first?
B
25
S
5
G
3
Posts: 446
Reputation: 5,633

Post » Fri Feb 01, 2013 11:04 pm

Put the sprite in a family and do comparisons between the sprite and family.
B
54
S
28
G
18
Posts: 1,520
Reputation: 24,990

Post » Fri Feb 01, 2013 11:11 pm

Yeah I guess that would work. It's already in a family but I suppose you could do another family just for this purpose? Cheers, hadn't thought of that.
B
25
S
5
G
3
Posts: 446
Reputation: 5,633


Return to How do I....?

Who is online

Users browsing this forum: Radulepy and 5 guests