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 / [SOLVED] using creatsprite(loadimage()) or createsprite(preloadedimg)?

Author
Message
dandrews
4
Years of Service
User Offline
Joined: 26th Jun 2020
Location:
Posted: 23rd May 2023 03:37
if i have a bunch of sprites using the same image like so...

will that code load the same image multiple times unnecessarily or is it essentially the same as loading an img like: preloadimg = (loadimage"") then using "preloadimg " every time i create the sprite?

The author of this post has marked a post as an answer.

Go to answer

Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 23rd May 2023 03:44 Edited at: 23rd May 2023 03:48
This post has been marked by the post author as the answer.
Quote: "that code load the same image multiple times unnecessarily"

yes it does. only load a given image file once; more than that is wasteful.

and, since that's a spritesheet, you'd be better off Cloning the original so that it carries over the animation and other traits vs setting it all up again.
dandrews
4
Years of Service
User Offline
Joined: 26th Jun 2020
Location:
Posted: 23rd May 2023 03:47
thank you nomad. so it just copies the already loaded image for the new sprites created with it?
Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 23rd May 2023 03:50 Edited at: 23rd May 2023 03:52
updated my first post with further advice.

Quote: "so it just copies the already loaded image"

it doesn't copy it (or duplicate it in memory). it references it. but, yes
dandrews
4
Years of Service
User Offline
Joined: 26th Jun 2020
Location:
Posted: 23rd May 2023 03:52
ok cool then i guess my questions is im assuming if i where to deletesprite(spriteid) then deleteimage(spriteid) it would delete the preloaded image and not just what is being used for that sprite?
Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 23rd May 2023 04:12 Edited at: 23rd May 2023 04:25
correct. the image remains available (using its ID) until you explicitly delete it.
deleting the sprite only deletes the sprite/reference to it.



btw, if you use Discord, it may be easier for you/us to chat

Login to post a reply

Server time is: 2024-11-21 10:00:06
Your offset time is: 2024-11-21 10:00:06