how to determine when an area is already populated

0 favourites
  • 14 posts
  • https://db.tt/4sRWDHHW

    I have 6 sprites ( invisible) ( yellow boxes)

    I also have 6 sprites ( numbered 1-6 ) ( various colors)

    The 6 invisible sprites are placed on my layout at specific locations. ( I have them close to each other for this question)

    The 6 invisible sprites are also 1 single sprite copied 6 times

    The 6 colored sprites are set to appear on top of any of the 6 invisible sprites randomly

    They appear for a few seconds and then disappear.

    There is no set pattern of where any of the 6 sprites appear which is what I want, however, that also means that any of the 6 sprites could appear together on top of each other.

    Right now I am using overlap to determine if a sprite is already in that position and then destroying one of the sprites.

    ( If sprite 1 is overlapping sprite 2 then destroy sprite 2)

    That seems like a waste of time.

    What I would like to know is how I can tell when any of my 6 sprites are already being occupied on top of any of the 6 sprites.

    Something that knows when there is already a sprite on top of one of the invisible sprites and won't let any other sprites go into that position.

    This is the way I have my sprites show up on top of the invisible boxes:

    https://db.tt/FzUiGDM3

  • update: I've tried some boolean variables but an't get the hang of it.

    I'll keep trying

  • You can add all your 6 sprites into a Family.

    Then use Family is overlaping 'spriteHolder' (sprite holder being the invisible sprites)

  • families is not available in free version

  • c'mon now. 33 views as of now and only 1 response?

    I'm still playing around using variables which is what I think I need to do. I am slowly learning how they work but still don't know how to get this to work the way I want.

  • When you pick the invisible sprite you want to spawn on, couldn't you check to see if it's overlapping before spawning the new one, and then look for a different one if it is occupied?

    Another way is to put a Boolean variable on the invisible sprite, marking if its "on" for spawning. when you spawn one there, turn it off. when that one no longer overlaps, turn it on.

    Edit:

    Oh, are they separate sprites or all animations in the same sprite?

    That may be what you are looking for, put all those sprites in the same sprite with different instances playing the different animations. It's how we used to do that before we had families.

    (pick an invisible sprite, check if it's overlapping that sprite holding all the animations, and if not spawn it and pick an animation to play.)

    If you need to check for a specific one, you can check which animation is playing.

  • "Another way is to put a Boolean variable on the invisible sprite, marking if its "on" for spawning. when you spawn one there, turn it off. when that one no longer overlaps, turn it on."

    That's what I'm trying to do but I can't wrap my head around it. I'm not sure how to word it

    they are all separate sprites with no animations.

    I've tried the overlapping bit but it just seems like there is a better way.

    Basically, I'm just looking for a way to tell the invisible sprite that if it already has an object overlapping it to not let anything else overlap.

    Not sure if I need to use variables or not.

    I am trying different options but so far I can't figure it out

  • I have a variable attached to my invisible sprites called 'occupied"

    value is zero

    I I set a condition of:

    box equal to or less than 0...do something

    I can get that to work

    What I can't figure out is how to tell it that if something is there already, prevent anything else from going there....

    My brain hurts but I'll keep trying

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • bumpitty bump

  • ok.Maybe this will help someone help me.

    This is a trimmed down basic idea of what I'm talking about.

    https://db.tt/SgcnlgN1

  • Here an example of what i evented togther running-

    Detecting Occupancy

    HERE IS THE EVENT SETUP

    Setting the boolean instance variable for checking--

    In the event sheet a while loop was created to look until a spawner instance variable for occupy was 'false' and once it placed something there is switched it to say something was there. When the object destroyed itself it re-selected the spawner that created it cause it was overlapping and change the Boolean for occupy variable back to 'false'.

    I can only assume that this is what you want couldn't open you capx... guess you have the beta version installed. But if so you can look over this.

    A few areas can be fixed for redundancy but 'Families' would make it more cleaner.

  • I have the free version so families are out of the question.

    I will look this over and see if I can wrap my head around it and incorporate your direction into my own project.

    Thank you so much for responding.

  • Here it is with all of them in one sprite. I didn't understand your timer, so it's currently disabled, and wait statements are the delays while on and while off.

    edit: Actually if you delete everything but that one event, it runs exactly the same.

  • That's EXACTLY what I was looking for!

    I have been struggling with this for days trying to figure it out.

    Thank you so much Paradox!

    Learning as I go thanks to people like you

    So simple. I knew there had to be an easier and more efficient way of doing this.

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