2D Side scrolling - Draw objects on Buffer - Printable Version
+- iDevGames Forums (http://www.idevgames.com/forums)
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: iPhone, iPad & iPod Game Development (/forum-11.html)
+--- Thread: 2D Side scrolling - Draw objects on Buffer (/thread-2100.html)
2D Side scrolling - Draw objects on Buffer - codetiger - Nov 28, 2008 03:50 AM
Being a J2ME programmer, am trying to understand the new platform.
I am developing a 2D platform, side scrolling game. The platform is constructed from a data file which has the array that represents different objects. Now the platform has to move very fast from right to left when the player moves. First time when I tried, I used OpenGL 2D and drew images for each tile. The tile size is around 10x10 PNG file. As I draw the tiles every frame the game seems to be really slow and not playable.
Now I am planning to have the platform pre-rendered on an image and I'll be drawing the image for every frame and the image will be constructed as the player passes a particular distance.
Now how do I draw something on an image, or is there anyother way doing it.
This thread however gives me a way for drawing it faster, but all that I need is draw it on an image so that is much faster.
2D Side scrolling - Draw objects on Buffer - SafariAl - Dec 10, 2008 09:26 AM
Sorry for the bump, but I have a solution to your unanswered problem. Right now I'm assuming your following that example exactly as it is. Now if you think about how that works, it draws the screen's size in tiles each and every frame, which would indeed end up appearing slow. I worked on a tilemap engine a bit back for the PSP (now I've just started moving onto the iPhone ), and I ran into the same problem. What you need to do is calculate each tile position and coordinate, and store them in two arrays - one for position and one for the image's texture coordinates (that is, if your planning on using a tilesheet as opposed to separate images). Then you use glDrawArrays to blit it all at once, rather than tile by tile. Hope this helped, if you have or notice some problems with this suggestion, I'd be glad to help and/or fix them. I hope this helps anyone else with this issue as well.
PS: if you need a coded example, I'd be glad to make one for you (but most likely not for the iPhone, as I'm just getting into everything).
2D Side scrolling - Draw objects on Buffer - codetiger - Jan 2, 2009 12:28 AM
Is there a way, I can render an image with all the platform of the game and then just draw the image once and not draw it everytime the screen updates?
2D Side scrolling - Draw objects on Buffer - SafariAl - Jan 2, 2009 10:19 PM
Not if you want large levels. That'd take away the whole purpose of a scrolling tilemap.
2D Side scrolling - Draw objects on Buffer - arekkusu - Jan 3, 2009 12:45 PM
Cache the rendering in a texture attached to a framebuffer object. It works fine for large scrolling levels-- just update the exposed strip(s) when you scroll.
See previous thread.
If you're doing a simple 2D side scroller where everything moves one pixel at a time then this may be overkill. But if you want the scroll in fractional amounts, or rotate or zoom the layer, then you need to render to a texture like this to handle the filtering between tiles.