Need to delete overlapping sprites of various types that are procedurally spawned in within zones

0 favourites
  • 9 posts
From the Asset Store
Change delay, create new lines, "backspace" the text
  • Sorry for the long title that still didn't explain much. I am new to Construct, I have been fumbling my way around and getting most things to "work" (maybe not very efficiently, but they "work"). That is except for this super annoying issue that I spent most of today trying, and failing, to solve.

    The game procedurally generates spawn zone for enemies, items, and environmental sprites/objects. The environmental sprites come in five sizes and are separate objects. They are created through the following:

    + System: For each EnvironmentalSpawnZone -> System: Set RandEnvSpawnAmount to int(random(1,6)) ----+ System: For "n" from 1 to RandEnvSpawnAmount -----> System: Set RandomSpawnCreator to int(random(1,6)) --------+ System: RandomSpawnCreator = 1 ---------> System: Create object TinyObj on layer 0 at (random(EnvironmentalSpawnZone.BBoxLeft+TinyObj.Width,EnvironmentalSpawnZone.BBoxRight-TinyObj.Width), random(EnvironmentalSpawnZone.BBoxTop+TinyObj.Height,EnvironmentalSpawnZone.BBoxBottom-TinyObj.Height)), create hierarchy: False, template: "" ---------> TinyObj: Set angle to int(random(0,360)) degrees --------+ System: RandomSpawnCreator = 2 ---------> System: Create object SmallObj on layer 0 at (random(EnvironmentalSpawnZone.BBoxLeft+SmallObj.Width,EnvironmentalSpawnZone.BBoxRight-SmallObj.Width), random(EnvironmentalSpawnZone.BBoxTop+SmallObj.Height,EnvironmentalSpawnZone.BBoxBottom-SmallObj.Height)), create hierarchy: False, template: "" ---------> SmallObj: Set angle to int(random(0,360)) degrees --------+ System: RandomSpawnCreator = 3 ---------> System: Create object LongObj on layer 0 at (random(EnvironmentalSpawnZone.BBoxLeft+LongObj.Width,EnvironmentalSpawnZone.BBoxRight-LongObj.Width), random(EnvironmentalSpawnZone.BBoxTop+LongObj.Height,EnvironmentalSpawnZone.BBoxBottom-LongObj.Height)), create hierarchy: False, template: "" ---------> LongObj: Set angle to int(random(0,360)) degrees --------+ System: RandomSpawnCreator = 4 ---------> System: Create object LargeObj on layer 0 at (random(EnvironmentalSpawnZone.BBoxLeft+LargeObj.Width,EnvironmentalSpawnZone.BBoxRight-LargeObj.Width), random(EnvironmentalSpawnZone.BBoxTop+LargeObj.Height,EnvironmentalSpawnZone.BBoxBottom-LargeObj.Height)), create hierarchy: False, template: "" ---------> LargeObj: Set angle to int(random(0,360)) degrees --------+ System: RandomSpawnCreator = 5 ---------> System: Create object HugeObj on layer 0 at (random(EnvironmentalSpawnZone.BBoxLeft+HugeObj.Width,EnvironmentalSpawnZone.BBoxRight-HugeObj.Width), random(EnvironmentalSpawnZone.BBoxTop+HugeObj.Height,EnvironmentalSpawnZone.BBoxBottom-HugeObj.Height)), create hierarchy: False, template: "" ---------> HugeObj: Set angle to int(random(0,360)) degrees

    The issue is that means that the environmental objects (Huge, large, long, small, tiny) can and are overlapping each other sometimes. I have tried the similar loops for each object to the following in an attempt to correct this issue with no success:

    + System: For each HugeObj ----+ HugeObj: Is overlapping HugeObj ----+ OR HugeObj: Is overlapping LargeObj ----+ OR HugeObj: Is overlapping LongObj ----+ OR HugeObj: Is overlapping SmallObj ----+ OR HugeObj: Is overlapping TinyObj -----> HugeObj: Toggle Overlap ----+ HugeObj: Is Overlap -----> HugeObj: Destroy

    What am I doing wrong here? I have also tried to destroy without using the boolean.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I mean the stuff above is kind of unreadable and I'm also not sure on the purpose of deleting them or if it's part of the design, but... you can try putting all the objects that spawn in a Family. Then you can say if 'HugeObj on created, if overlapping Family delete HugeObj and same for the other objects.

  • Sorry that it is ineligible. The forum doesn't seem to like copy/paste from Construct into code blocks... Odd.

    If I delete the family won't that delete all objects of the same type?

  • Yeah no problem, sometimes a screenshot is useful! it will pick the Family instance that it is overlapping and delete only that. If you have on created + the object is overlapping family condition.

  • This doesn't work. What am I doing wrong?

  • The top condition you are looking for is 'HugeObj on created', then the second condition should be HugeObj is overlapping Fam.

  • Okay, I got around to testing your suggestion; It didn't work. I believe there may be something more fundamental that I am doing incorrectly. Because of that, I took a variety of screenshots that will hopefully make my mistake more obvious.

    This is where the objects are being created randomly within specified spawn zones:

    This is where I then am using your "On created/check if overlapping" suggestion and then delete the object:

    Here is the family group:

    Hopefully this is me being an idiot, but I am beating my skull against a brick wall trying to figure out what is going wrong.

  • I FIGURED IT OUT!!! You were right (and I was right about me being an idiot)! In poking around, I noticed that the family, "EnvObjFam" had the setting "Layer" set as "Various". After switching this to "MainGameLayer", it worked. Foolish mistake!

  • No idea what that setting is but glad it's working now :)

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