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.