Ensuring two sprites are in same place

0 favourites
  • 5 posts
From the Asset Store
Forgotten Place - Melodic ambiance, background music, Synth
  • 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?

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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.

  • 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?

  • Put the sprite in a family and do comparisons between the sprite and family.

  • 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.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)