cannot do cached image on android
Monkey Forums/Monkey Programming/cannot do cached image on android
| ||
hi I have a question regarding caching images on android. If I draw image outside screen during loading and then try to enter the screen when this image is draw, then first entry takes much more time to draw then the next ones. I think it is because i cached image from image bank and then assign it to local TGameImage variable on different screens, so its different variable but same reference. Should I draw every image separately even if this is same reference ? Any ideas what can be wrong ? '******************************* '* '******************************* Method Render:Void() 'cache images if(graphicsCached = 0 And loadingIsOver = 1) For Local AA:String = eachin game.images.Keys Local II:TGameImage = GetGfx(AA) II.Draw(-50,-50) Next graphicsCached = 1 End 'draw background Cls() DrawImage(back,0,0) 'draw starting screen with loading / completed if(loadingIsOver = 1 And graphicsCached = 1) DrawImage(loadDone,SCREEN_WIDTH2, SCREEN_HEIGHT2*3/2,0) Else DrawImage(loadStart,SCREEN_WIDTH2, SCREEN_HEIGHT2*3/2,0) end End '******************************* '* '******************************* Method Update:Void() 'load data if(loadingIsOver = 0) game.LoadData() loadingIsOver = 1 end 'end loading and caching if(loadingIsOver = 1 And graphicsCached = 1) 'just play click sound if(delay = 0) PlayClickSound() End delay = delay + 1 if(delay > game.FPS) SetColor(255,255,255) LoadStateAll() game.CreateScreens() End End End |
| ||
Android requires time to load the images onto the GPU... what I normally do is once all the images are loaded I display all of them off screen, which forces the images into VRAM, so the next time you use them you dont have the delay. |
| ||
I had the same problem, and based on therevills post I now simply draw all my sprites once before starting the game. I hide the output by drawing the splash screen over the top. It seems to work well, as I now have no delay at all when I play the level for the first time. Does anyone know if this is just a problem with Android, or do we have this problem with other targets? |
| ||
guys i am doing exaclty what You did, i draw all images at the splash screenif(graphicsCached = 0 And loadingIsOver = 1) For Local AA:String = eachin game.images.Keys Local II:TGameImage = GetGfx(AA) II.Draw(-50,-50) Next graphicsCached = 1 End but when i use this image as a reference into other image then this effect is lost and i dont understand why. Could You please paste Your sample code ? |
| ||
Hi, I know this sounds stupid, but in your render method draw all your images after the CLS command, and then draw your splash screen to cover them all up. I found when drawing immediately before the CLS command the images didnt seem to be loaded into the VRAM. |
| ||
thanks this could be it, this is my scenario and second issue. If i am using many subimages on one image should I cache all of them ? |
| ||
Just tested that. If you are using a drawImageRect command, then it seems all you need to do is draw the main image to cache it. |
| ||
no i am not using this command i think, i just load image as animation and then DrawImage with proper animation index to get into proper image in this should I draw all frames for all animations ? |
| ||
Im not sure as I don't load images like that so can't test. Im using a single sheet (sprite atlas) and then just use drawimagerect to draw the frames I want. Should be easy enough for you to test though. Would be interested to hear your results. |
| ||
oh .. in a single sheet ? what is a size of that sheet ? i would need at least 4096x4096 for all my graphics at 320x480 resolution. |
| ||
i do the same as uncle but sometimes need more than one large spritesheet as i can use a lot of graphics.when i do the initial drawing i display them offscreen then i dont get any delays later on when a new image is introduced,ive not encountered any problems with this yet. |
| ||
I found when drawing immediately before the CLS command the images didnt seem to be loaded into the VRAM. Good to know. I just had to switch from V40 to V44, and suddenly the image caching failed. I removed the cls after it, and it works. |
| ||
i just removed cls and it worked just fine, thanks !! you were 8 minutes before me... crap :P |
| ||
after suspend all images must be cached again so if somebody rings or you enter a website from application then you must cache images again this really sucks, i have about 1 MB which are loaded on my samsung at least 6 secs |
| ||
guys please could you post what is Your approximate time to load 1 MB of png files into phone memory. For my galaxy ace samsung its about 6 seconds (to load them less then 1 sec and them to cache them its about 5). I am not using image atlas but have separate backgrounds (at least 7 of them) for each resolution (so total 5 MB in 3 separate apk files). I am using image atlas for all small button and other icons. This time is only for 320x480 and i dont have phone to check others. PS: can I please move this topic to Android, thanks |