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.

AppGameKit Classic Chat / [SOLVED] Memory Usage Increasing Due to Sprites?

Author
Message
nickshepherd
10
Years of Service
User Offline
Joined: 19th Jun 2013
Location: The Land of Game Development
Posted: 5th Jul 2018 21:21
Hello,

I am making a slot machine app that basically moves a sprite down the screen and when it is out of view I call the function NewIcon() which changes the sprite image to be that which corresponds to the symbol set to pay. However, my memory usage increases as I continue running the program until it slows and crashes. Am I going about this incorrectly? Thank you!



Function NewIcon()
if getspriteexists(spot1.spr) = 1 then deletesprite(spot1.spr)
if spot1t = 1
hat.img = LoadImage( "icon_1.png" )
spot1.spr = CreateSprite( hat.img )
endif

if spot1t = 2
axe.img = LoadImage( "icon_2.png" )
spot1.spr = CreateSprite( axe.img )
endif
Endfunction

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

Go to answer

IronManhood
9
Years of Service
User Offline
Joined: 6th Feb 2015
Location: US
Posted: 5th Jul 2018 22:19
This post has been marked by the post author as the answer.
You are using LoadImage() incorrectly. Move that outside any loop and only call it once. If you need to use the same variable to load a different image, make sure to delete the previously loaded image before loading any other image. Also, you could just use SetSpriteImage() instead of deleting the sprite and recreating it every time you need to change sprite images.



nickshepherd
10
Years of Service
User Offline
Joined: 19th Jun 2013
Location: The Land of Game Development
Posted: 6th Jul 2018 19:08
Thank you, that makes sense!

Login to post a reply

Server time is: 2024-04-20 10:36:22
Your offset time is: 2024-04-20 10:36:22