Surely there are ways not to redraw a static monotonous background, but only to change the position of objects on it. How is this done? I draw on the canvas.
- why do you think there is a way? - Mikhail Vaysman
- Because this thing will significantly relieve the load and with my approximate ideas about technology, I assume that there should be a similar mechanism. And secondly, I read articles briefly somewhere, where there was a conversation about layers, about what can be not redrawn, about certain pools so as not to delete old objects. So I wonder firstly what ways are there on the canvas. So what is invented in opengl - Turalllb
- ru.stackoverflow.com/questions/237805 for example - Turalllb
- OpenGL with canvas has nothing to do. OpenGL draws straight to video memory. A canvas is an abstraction that can be implemented as you please. - Eugene Krivenja
- It is clear that this is not the same thing, but they both draw, and I wonder how you can draw without drawing the entire background. It is better, of course, to find out how to do this on a canvas, but if the canvas does not provide such opportunities, then opengl remains. It's clear that everything possible in libraries has already been implemented, but looking under the engine hood is not so easy to understand how it performs this - Turalllb
2 answers
If the background does not move at all, then take a piece of the background, restore it at the place where the sprite was, and draw the sprite at the new place.
On the canvas a lot of things you can imagine. Here for example:
https://ru.wikipedia.org/wiki/%D0%94%D0%B2%D0%BE%D0%B9%D0%BD%D0%B0%D1%8F_%D0%B1%D1%83 % 84% D0% B5% D1% 80% D0% B8% D0% B7% D0% B0% D1% 86% D0% B8% D1% 8F
Android started with 4.0 has hardware double buffer as I remember.
- Well, yes, this is the first thing that comes to mind. And if you think about it, then creating the bottom layer and redrawing objects on it basically happens in the same way, on the spot where the sprite was drawing the background again. But after all, there should be a code that does all this cleverly, using as few resources as possible, without creating a new patch for the background each time, but taking the finished one that is stored in memory. On the outline you can’t talk, but what can we think of? What remains is opengl, right? And what are the possible schemes there? - Turalllb
- Find any library for 2D graphics, everything has already been decided. - Eugene Krivenja
- You know, having opened the AndEngine library is not so easy to understand how this issue is solved there, for that, at least, you need to know about how it is solved in order to pick the engine in the right place. - Turalllb
Found an article about reducing the frequency of redrawing. https://xamdev.ru/layout-performance-on-android/ And the drawing of the game background is proposed to divide the screen into eggs and draw only those that have changed. In general, solutions for special cases.
- The question arises, what if the background itself is set in the xml markup to set this background, and not reload itself each time in the onDraw - Turalllb method