How would you duplicate the same sprite to a random location. For example if I wanted 50 strawberries on the screen in a random location.for the x and y, use RND and add new sprites then offset them to the random x and y
Duplicating Sprites
Root / Programming Questions / [.]
bluemonkey1111Created:
How would you duplicate the same sprite to a random location. For example if I wanted 50 strawberries on the screen in a random location.
What if I want there to be an infinite number of sprites, but it has a delay of 1 second. Let's say an I don't know... Agario type thing where there can be an infinite amount. (I did a crappy example).
WAIT 60
What if I want there to be an infinite number of sprites, but it has a delay of 1 second. Let's say an I don't know... Agario type thing where there can be an infinite amount. (I did a crappy example).Firstly, there's a limit of sprites in sb secondly, WAIT 60 is used by professionalsWAIT 60
Thank you for trying.
Alright time for some corrections here, WAIT 60 would simply stop your program fully for about one second, which if you would want an agario type of effect it would be very to say the least not playable in a game.
Also there is a limit to 512 sprites to be used at once, however if it was for an agario type of game you could simply spawn more sprites as you go and delete the ones behind you, while you could not go back to see the same sprites it would auto generate them for you instead of having to wait one second for each one.
Alright so how this would be done takes some effort but is worth it, lets start with the basics, the want to be able to scroll the map with sprites on it i will assume, right?
Do you know how to do so or do you need me to explain how to do this?
>Tbc whenever you answer
"Professional" example code:
FOR I=0 TO 100 'Increase for more sprites, up to 512 (causes lag) SPSET I,0 'Set sprite to strawberry texture (unless that's the peach) SPOFS I,RND(400),RND(240) 'Set a sprite in a random location NEXTThat randomly creates a bunch of sprites. This next bit of code can be put in a game but you must save some sprites for something else if you want to keep some for other sprite stuff:
CHANCE=RND(50) 'Higher for a lower chance IF CHANCE==1 THEN 'Can be any number FOR I=0 TO 100 'Number of allocated sprites for use with this IF !SPUSED(I) THEN 'If sprite I is not used then execute the code SPSET I,0 SPOFS I,RND(400),RND(240) ENDIF NEXT ENDIFDon't forget to clear sprites that aren't on screen or not needed anymore so you can have "infinite" sprites. My game Space Rocks includes some functions to draw "entities" onscreen and clears their sprites when they go off screen. You can check it out if you want but the code needs to be organized and it may not be a good example.
chicken exmaple
very tasty much miiverse
(note: trying to make it nearly infinite (above the 512 sprite limit) would probably involve some godforsaken mixture of graphics and arrays that no one on o3DS could, would, or should play.)
OCNT=MAINCNT `this maincnt var is a system variable, it increases by one each frame WHILE TRUE IF MAINCNT-OCNT >= 60 then `duplication stuff here i guess OCNT=MAINCNT `resetting the โtimerโ ENDIF VSYNC WEND
Infinite (not really) sprites isn't actually that difficult since you can store more coordinates than sprites. Just clear sprites that aren't on screen and aren't completely covered by other sprites.