Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers AppGameKit Corner / Works DeleteSprite(id) correctly?

Author
Message
c0d3r9
Recently Online
Joined: 2nd Oct 2017
Location:
Posted: 17th Feb 2018 21:04 Edited at: 17th Feb 2018 21:11
I draw some tiles in a function.
And on the start of the function i delete all the sprites with that


For testing i take a look what index id are given intern.
With DeleteAllSprites() all finde, but it seems that The For-Next loop above don´t delete the auto generated sprite indexes.
Whats wrong?

My Problem is that i have to delete ~100 sprites every functioncall.But only these sprites.
kaband
15
Years of Service
User Offline
Joined: 22nd May 2003
Location: Chicago
Posted: 17th Feb 2018 21:20 Edited at: 17th Feb 2018 21:21
How do you know what Sprite ID has been given to your sprite? if it were me, I'd create an array of generated Tile Sprite ID's and not even worry about the actual ID # is.


So now you have an array of all the Sprite ID's. To delete you can do something like.



You don't have to worry about the actual ID's being assigned to the sprite. I used to manually assign all my sprite ID's which caused me too many headaches. Hopefully my syntax above is right.
c0d3r9
Recently Online
Joined: 2nd Oct 2017
Location:
Posted: 17th Feb 2018 21:51 Edited at: 18th Feb 2018 00:11
First if the sprites get an automated index it starts with 100000.....
Have test this.
Second: Your array have 10 slots....

In my game i have a tilemap and the tiles have a different count every call.
For other thing i give the sprite index manually and so i thought i can delete sprites with index 100000-x easy.

okay i tried your way but it doesn´t work correctly.
Btw. automated indexes startet on 100000 and so it should be possible to delete from that as startposition.I think in my situation the easiest way ....if it work.

If nothing helps i create all sprites to the end of the loop every call and so on.(and deleteallsprites() at the start of the mainloop.
edit: wrong way....if i do that i have problems with physics.....so i must save all states of the moved sprites with physical interaction.
sleep a night over it, maybe i have a better idea tomorrow

test it now with the linklist.agc found here on the forum....runs fine....so it was maybe a bug on my array routine.try it later again.want to code it completly myself
PHeMoX
User Offline
Joined: 9th Jan 2018
Location:
Posted: 18th Feb 2018 00:55
Quote: "First if the sprites get an automated index it starts with 100000....."


That depends how you generate the tiles though (I'm pretty sure the 100001+ thing happens when the ID is a name or string;
Quote: " mysprite1 = CreateSprite(LoadImage("mysprite.png"))"
and the ID numbers might change to something higher than the range you assume. You need code that stores the ID numbers created by adding 1 whenever you create a new sprite. Then reset that when you delete them all.

Also something to note, if you add any other sprites before your current code using the syntax example I quoted, the ID number of what you call 'automated' indexed will change accordingly.
c0d3r9
Recently Online
Joined: 2nd Oct 2017
Location:
Posted: 18th Feb 2018 01:29 Edited at: 18th Feb 2018 01:51
well...couldn´t sleep.
hope its not to confusing ´cause i have deleted my german comments
draws the partial tilemap -> sync -> delete all tilemapsprites and the array

thats all needed because i have created a playersprite for testing before the main loop starts....but i have to delete all mapsprites in every mainloop for the scrolling(combination of view+'only_draw_what_you_see').
And if i delete all sprites all sprite physic is away(terrible because the player and other things are dynamic)....but now....it runs fine....for the moment and the actual state.
after some following steps i would write a little tutorial for scrolling.(maybe in german but google translater helps translate to a near as good english)
i think some beginner have problems with that(in past me too).

And guys: thanks for the help.special kaband.
And now i must sleep...my child will wake up in a few hours.

IronManhood
3
Years of Service
User Offline
Joined: 6th Feb 2015
Location: Over there...
Posted: 18th Feb 2018 05:37
Do you need to delete/create the sprites? You could create all of your sprites and just reposition/change sprite images without deleting them.
TomToad
User Offline
Joined: 6th Jan 2018
Location:
Posted: 18th Feb 2018 09:43
I see a small, potential problem with your code. IDs are autogenerated starting at ID 100,001 and increase by 1 every time. Once an ID is generated, it is never generated again, even when the sprite is deleted. That means eventually you will run out of IDs. I say the problem is small, because even with 1000 tiles each frame at 60 frames per second, it will still take you 9 hours to go through all the IDs. It might be better, though, to create a pool of IDs that you can reuse every frame. You not only avoid the possibility of running out during long gaming sessions, but will probably increase performance as well.
c0d3r9
Recently Online
Joined: 2nd Oct 2017
Location:
Posted: 18th Feb 2018 09:55 Edited at: 18th Feb 2018 11:42
@IronManHood: than i need ever the maximum amount of every tile on screen.(partial outside the screen) i think create/delete/create ist the est way in my case.
@TomToad: Okay....thats a reason to change my code.
That was never in my mind.

Thank you for this

Login to post a reply

Server time is: 2018-06-24 21:17:15
Your offset time is: 2018-06-24 21:17:15