how to spawn exact amt of sprites w/o overlapping another ob

0 favourites
  • 7 posts
From the Asset Store
Create your own wss server and ws server with ssl and without ssl.
  • Hello, my problem is how to spawn exact amount of sprites without overlapping another object.... I tried to reposition the spawned sprite if it is overlapping another object.... For example, I have to spawn 5 sprites anywhere, but 1 of the sprites spawned on top of another object. The problem is how will I reposition that object so that it won't be overlapping another object?? Pls help. thanks a lot...

    PS I've seen skymania's thread... it was helpful. it gave me some idea but I still can't solve the problem wherein i must spawn the exact amount of sprites

    PPS I found another way of solving my problem, by destroying the object that got overlapped by the spawned sprites, but that's not what i want to happen. xD so if anyone out there can help me, i'd be very thankful. <img src="{SMILIES_PATH}/icon_e_biggrin.gif" alt=":D" title="Very Happy" />

    PPS I posted my problem in Game Dev., Design and Ideas but i think it was wrong so im deleting my post there. HAHAHA!! Sorry moderator.

    PPPS I'll be posting my "new" code because i've been trying to solve this problem.. xD

    dropbox.com/s/w1ytmnbtoflaa ... t.png?dl=0 >>>> event sheet

    dropbox.com/s/zii3b7iu2nbcu ... s.png?dl=0 >>>>> output

    dropbox.com/s/8u07ezz3jopss ... T.png?dl=0 >>> NewOutput

    dropbox.com/s/siqi1n08wog1w ... E.png?dl=0 >>>>newEventSheet

    dropbox.com/s/8u07ezz3jopss ... T.png?dl=0

    So as you can see there... I'm still not good at using the function and the for loops. xD I still don't know what I'm doing.... I'm just using any commands in Construct2 as long as it runs. xD

    By the way, credits to Kyatric, i used his idea on centering the spawned sprite on a single square.

    I tried the while(but it doesn't load, and im getting errors xD), the compare instance variable too just so if anyone will ask... but maybe I wasn't able to utilize it. hahaha!! so please help me here. <img src="{SMILIES_PATH}/icon_e_biggrin.gif" alt=":D" title="Very Happy" />

  • Message: wakiki31 can only post plain text URLS until they have 500 rep. 4 URLS modified.

    The URLS can not be viewed

  • Message: wakiki31 can only post plain text URLS until they have 500 rep. 4 URLS modified.

    The URLS can not be viewed

    xD I don't know what's happening either. xD guess I'll just have to write my event sheet. xD

  • Hello, my problem is how to spawn exact amount of sprites without overlapping another object.... I tried to reposition the spawned sprite if it is overlapping another object.... For example, I have to spawn 5 sprites anywhere, but 1 of the sprites spawned on top of another object. The problem is how will I reposition that object so that it won't be overlapping another object?? Pls help. thanks a lot...

    PS I've seen skymania's thread... it was helpful. it gave me some idea but I still can't solve the problem wherein i must spawn the exact amount of sprites

    PPS I found another way of solving my problem, by destroying the object that got overlapped by the spawned sprites, but that's not what i want to happen. xD so if anyone out there can help me, i'd be very thankful. <img src="{SMILIES_PATH}/icon_e_biggrin.gif" alt=":D" title="Very Happy" />

    PPS I posted my problem in Game Dev., Design and Ideas but i think it was wrong so im deleting my post there. HAHAHA!! Sorry moderator.

    PPPS I'll be posting my "new" code because i've been trying to solve this problem.. xD

    https://www.dropbox.com/s/w1ytmnbtoflaa ... t.png?dl=0 >>>> event sheet

    https://www.dropbox.com/s/zii3b7iu2nbcu ... s.png?dl=0 >>>>> output

    https://www.dropbox.com/s/8u07ezz3jopss ... T.png?dl=0 >>> NewOutput

    https://www.dropbox.com/s/siqi1n08wog1w ... E.png?dl=0 >>>>newEventSheet

    https://www.dropbox.com/s/8u07ezz3jopss ... T.png?dl=0

    So as you can see there... I'm still not good at using the function and the for loops. xD I still don't know what I'm doing.... I'm just using any commands in Construct2 as long as it runs. xD

    By the way, credits to Kyatric, i used his idea on centering the spawned sprite on a single square.

    I tried the while(but it doesn't load, and im getting errors xD), the compare instance variable too just so if anyone will ask... but maybe I wasn't able to utilize it. hahaha!! so please help me here. <img src="{SMILIES_PATH}/icon_e_biggrin.gif" alt=":D" title="Very Happy" />

    xD okay, so another problem here. xD The link that I posted cannot be viewed and I dont know why. so I'just write my code here.

    system > on start of layout > function call "spawning" ()

    [GROUP] SPAWNER

    function On "spawning"

    -> system >> for "spawn" from 1 to spawnedSprite.limit >> system >> create obj spawnedSprite on layer at

    random(0,480),random(480,0))

    sprite 2 >> on created >> spawnedSprite >> set position to int(self.x/32) * 32 +16, int(self.y/32) * 32 +16

    first thing first, i created a map wherein there are lots of blocks everywhere, I also created a sprite called "spawnedSprite" that has an instance variable of "limit". i used that "limit" as my end index in my for loop...So what's happening here in my code is that it spawn the 20 instance of my created sprite anywhere in the map... My problem is that I don't want my sprites to be overlapping any blocks....

    so I modified my event sheet... here's the new one

    global number maxval = 1

    on start of layout > function call "spawning" ()

    [GROUP] SPAWNER

    function On "spawning"

    -> system >> for "spawn" from maxval to spawnedSprite.limit >> system >> create obj spawnedSprite on layer at

    (random(0,480),random(480,0))

    >> add 1 to maxval

    -> spawnedSprite is overlapping at offset block1 >> spawnedSprite > destroy

    or

    spawnedSprite is overlapping at offset block2

    sprite 2 >> on created >> spawnedSprite >> set position to int(self.x/32) * 32 +16, int(self.y/32) * 32 +16

    So, on my revised event sheet, i created a global variable "maxval". I used it as my counter to be used in for loop(i still don't understand how the for loop works but i gave it a try and how I understand the for loop is like it'll continue doing its function as soon as the condition is achieved)... so everytime i spawn a sprite, i add 1 to "maxval"... i also added another condition to check whether the spawned sprite is overlapping any blocks, and if it overlaps any block, it will get deleted automatically and will subtract 1 to "maxval"(i added a subtract 1 to maxval because, according to my understanding of the for loop, it will subtract 1 to maxval and it's like it'll keep on resetting until the spawned sprite is in a satisfying condition, only that tym the max val will get increase ).... i thought it'll solve the problem but still doesn't. xD what actually happend is that it only deletes the spawned sprites that are overlapping and as a result, it does not reach 20. xD help me pls.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • hello again... so i made another adjustment to my event sheet... here it is..

    sprite 2 >> on created >> spawnedSprite >> set position to int(self.x/32) * 32 +16, int(self.y/32) * 32 +16

    system >> on start of layout > function call "spawning" ()

    system >> for each spawnedSprite

    -> spawnedSprite is overlapping block1at offset(0,0) >> set position to random(0,480), random(480,0)

    "or" >> set position to int(self.x/32) * 32 +16, int(self.y/32) * 32 +16

    block2 at offset(0,0)

    "or"

    spawnedSprite at offset(0,0)

    [GROUP] SPAWNER

    function On "spawning"

    -> system >> repeat 20 times >> system >> create obj spawnedSprite on layer at random(0,480),random(480,0))

    so now, it's somehow working but it's still not 100% so this is still a very bad event sheet. xD Sometimes it spawn all 20 without overlapping any objects but sometimes, it does not spawn all 20 spawnedSprite... so pls help me find as to what is wrong with this... or just read this as it might help you. ;D happy reading.

  • Nice one! Bob Marley said on one of his live music and I too will say nice one for i have solved my problem. happy reading. i also noticed that i should type it more clearly since the editor will remove any useless space. xD

  • system >> on start of layout > function call "spawning" ()

    system >> for each spawnedSprite

    -> spawnedSprite [INVERTED][is overlapping block1"or" block2"or" spawnedSprite at offset(0,0)]>>spawnedSprite>>set position to int(self.x/32) * 32 +16, int(self.y/32) * 32 +16

    system >> else

    ->spawnedSprite is overlapping block1"or" block2"or" spawnedSprite at offset(0,0) >> spawnedSprite>>set position to random(0,480), random(480,0)

    [GROUP] SPAWNER

    function On "spawning"

    -> system >> repeat 20 times >> system >> create obj spawnedSprite on layer at random(0,480),random(480,0))

    so explaining my code again....

    I removed "on create" command since it is redundant with my "for each" loop... so as to how i understand my code, what's happening here is first i create 20 instances of spawnedSprite, then once finished, the for loop will test each of spawned sprite whether it is overlapping any object or not. If it does not overlap any object then it'll place the spawnedSprite on the center of the square that it occupied. If it overlaps another object, then it'll find another space and it'll get tested again in the for loop until it does not overlap any object. Once the spawnedSprite does not overlap any blocks, it'll get centered on the square it is occupying and the for loop will go to the next spawnedSprite and it'll repeat the process until all spawnedSprite are not overlapping any blocks or itself. OR ITSELF... im sorry i forgot about that. I also took the precautionary measure as to whether it might overlap itself, so there you have it. I hope that you learned something.

    thanks to skymania, he gave me some ideas on his snake like game.

    PS it's been fun typing here, I'd just like to tell the other devs out there that has problems of their own that if nobody helped you then there's always yourself whom you can count on... also, don't blame others if they don't help you, just think that if you overcome your present problem, then there's another that needs to be solved all by yourself... AHAHAHAHA!! i suppose you get it.

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