grow heap on load several bitmap- scale bitmap to screen size

uni00

Junior Member
Nov 13, 2017
4
0
1
in my game i use surfaceview And Canvas to draw sprites on screen for achiving this in all screen size: i test two way:

first: when canvase want to draw Framebuffer(final bitmap) on screen, scale this framebuffer by using

canvas.drawBitmap(framebuffer, null, dstRect, paint);

but frame per second(fps) reduce And game dont run smooth( smaller screen = smoother game runing)

two: if i load And scale all photo in start of game accordindg to screen size --> Grow heap increase use this in this way:

canvas.drawBitmap(framebuffer, 0, 0, paint);

All of images are Maximum 480*800 pixel

(**an image without scale, allocate 1.5 mb And with scale for a 1080*1920 device allocate about 10mb *)
 

Cogman

Lifer
Sep 19, 2000
10,278
126
106
What is the question?

Is it, "How can I handle resources without eating a lot of memory?"

If so, I would suggest that you apply some smarts to your game. Easiest thing to do with be use an LRU and save off the results of the scaling in the LRU. That would save on most scaling computations while keeping down the memory (you only see a dip when new sprites enter the screen).

Another approach would depend on what your game is. An LRU might be wasteful and might not take advantage of breaks in your game. For example, if you are doing an RPG type game, then maybe you only need to scale the tiles nearest to the character. If it is a space sim arcade shooter type game, you could simply scale the upcoming space ships and hold on to them until they are x seconds from appearing.

Of course, some of this depends on if you are doing stuff like double buffering. Often time, the hard part of rendering canvases is that every call to "draw X" ends up blocking and waiting on the video card to actually push those values out to the screen. Many canvas based games get around that by writing to a non-rendered canvas and then swapping. That way, you can push out all of your bytes without waiting on the to screen turn around.

Finally, if you really want speed, then swapping out a canvas render for WebGL + shaders is going to be your best bet. It is a harder API, but much faster as it is much closer to the GPU.
 
Reactions: uni00

uni00

Junior Member
Nov 13, 2017
4
0
1
thank for reply..
1.about loading image:
LRU can be good but when i cant load 100 bitmap, as a result i dont have those bitmap to caching
yes i try to load bitmap for every page of my game and then nullify those bitmap and try to load bitmap if i need that.
i wonder how other games (with very sprites) load their image and run normally in most device?!!
2.about game speed
in my game i load my image base on 480*800 screen and draw frame buffer according to screen size as a result i have 50-60 FPS in 480*800 device but 20-30 FPS in 1200*720 device (bigger device = more flicker).
you suggest me use open Gl , in open Gl how framebuffer scale and fit to screen size? this scaling procces doesnt reduce FPS?
 

uni00

Junior Member
Nov 13, 2017
4
0
1
What is the question?

Is it, "How can I handle resources without eating a lot of memory?"

If so, I would suggest that you apply some smarts to your game. Easiest thing to do with be use an LRU and save off the results of the scaling in the LRU. That would save on most scaling computations while keeping down the memory (you only see a dip when new sprites enter the screen).

Another approach would depend on what your game is. An LRU might be wasteful and might not take advantage of breaks in your game. For example, if you are doing an RPG type game, then maybe you only need to scale the tiles nearest to the character. If it is a space sim arcade shooter type game, you could simply scale the upcoming space ships and hold on to them until they are x seconds from appearing.

Of course, some of this depends on if you are doing stuff like double buffering. Often time, the hard part of rendering canvases is that every call to "draw X" ends up blocking and waiting on the video card to actually push those values out to the screen. Many canvas based games get around that by writing to a non-rendered canvas and then swapping. That way, you can push out all of your bytes without waiting on the to screen turn around.

Finally, if you really want speed, then swapping out a canvas render for WebGL + shaders is going to be your best bet. It is a harder API, but much faster as it is much closer to the GPU.

thank for reply..
 

Cogman

Lifer
Sep 19, 2000
10,278
126
106
thank for reply..
1.about loading image:
LRU can be good but when i cant load 100 bitmap, as a result i dont have those bitmap to caching
yes i try to load bitmap for every page of my game and then nullify those bitmap and try to load bitmap if i need that.
i wonder how other games (with very sprites) load their image and run normally in most device?!!
2.about game speed
in my game i load my image base on 480*800 screen and draw frame buffer according to screen size as a result i have 50-60 FPS in 480*800 device but 20-30 FPS in 1200*720 device (bigger device = more flicker).
you suggest me use open Gl , in open Gl how framebuffer scale and fit to screen size? this scaling procces doesnt reduce FPS?

To the first question, depends on the game. AFAIK, most games do a sprite sheet. That is to say, they put all of their sprites into one image and then crop to the desired sprite. This saves on GPU back and forth (see an example here http://www.williammalone.com/articles/create-html5-canvas-javascript-sprite-animation/ )

To the second. OpenGL handles it by not doing the scaling on the CPU. Instead it passes it off to the GPU. GPUs have dedicated hardware to do things like image scaling and they can do it really fast. So you would still scale on demand but use the GPU to do your scaling.
 
Reactions: uni00

uni00

Junior Member
Nov 13, 2017
4
0
1
To the first question, depends on the game. AFAIK, most games do a sprite sheet. That is to say, they put all of their sprites into one image and then crop to the desired sprite. This saves on GPU back and forth (see an example here http://www.williammalone.com/articles/create-html5-canvas-javascript-sprite-animation/ )

To the second. OpenGL handles it by not doing the scaling on the CPU. Instead it passes it off to the GPU. GPUs have dedicated hardware to do things like image scaling and they can do it really fast. So you would still scale on demand but use the GPU to do your scaling.

thanks for good link,it help me
** u mean if i create a 1000*1000 pixel bitmap it's better than creating 10 numbers 100*100 pixel bitmap?
android tell a bitmap allocation = Width pixel*Height pixel*4 bytes(if used is ARGB_8888) , i think it's not different! is n't it?

** thank for your advice , i try to use openGl for my next game so I can get rid of FPS problems
 
sale-70-410-exam    | Exam-200-125-pdf    | we-sale-70-410-exam    | hot-sale-70-410-exam    | Latest-exam-700-603-Dumps    | Dumps-98-363-exams-date    | Certs-200-125-date    | Dumps-300-075-exams-date    | hot-sale-book-C8010-726-book    | Hot-Sale-200-310-Exam    | Exam-Description-200-310-dumps?    | hot-sale-book-200-125-book    | Latest-Updated-300-209-Exam    | Dumps-210-260-exams-date    | Download-200-125-Exam-PDF    | Exam-Description-300-101-dumps    | Certs-300-101-date    | Hot-Sale-300-075-Exam    | Latest-exam-200-125-Dumps    | Exam-Description-200-125-dumps    | Latest-Updated-300-075-Exam    | hot-sale-book-210-260-book    | Dumps-200-901-exams-date    | Certs-200-901-date    | Latest-exam-1Z0-062-Dumps    | Hot-Sale-1Z0-062-Exam    | Certs-CSSLP-date    | 100%-Pass-70-383-Exams    | Latest-JN0-360-real-exam-questions    | 100%-Pass-4A0-100-Real-Exam-Questions    | Dumps-300-135-exams-date    | Passed-200-105-Tech-Exams    | Latest-Updated-200-310-Exam    | Download-300-070-Exam-PDF    | Hot-Sale-JN0-360-Exam    | 100%-Pass-JN0-360-Exams    | 100%-Pass-JN0-360-Real-Exam-Questions    | Dumps-JN0-360-exams-date    | Exam-Description-1Z0-876-dumps    | Latest-exam-1Z0-876-Dumps    | Dumps-HPE0-Y53-exams-date    | 2017-Latest-HPE0-Y53-Exam    | 100%-Pass-HPE0-Y53-Real-Exam-Questions    | Pass-4A0-100-Exam    | Latest-4A0-100-Questions    | Dumps-98-365-exams-date    | 2017-Latest-98-365-Exam    | 100%-Pass-VCS-254-Exams    | 2017-Latest-VCS-273-Exam    | Dumps-200-355-exams-date    | 2017-Latest-300-320-Exam    | Pass-300-101-Exam    | 100%-Pass-300-115-Exams    |
http://www.portvapes.co.uk/    | http://www.portvapes.co.uk/    |