2D Side scrolling - Draw objects on Buffer

Apprentice
Posts: 5
Joined: 2008.10
Post: #1
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.
http://www.idevgames.com/forum/showthread.php?t=16031
Quote this message in a reply
Apprentice
Posts: 10
Joined: 2008.12
Post: #2
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.

-Al

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).
Quote this message in a reply
Apprentice
Posts: 5
Joined: 2008.10
Post: #3
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?
Quote this message in a reply
Apprentice
Posts: 10
Joined: 2008.12
Post: #4
Not if you want large levels. That'd take away the whole purpose of a scrolling tilemap.
Quote this message in a reply
Sage
Posts: 1,232
Joined: 2002.10
Post: #5
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.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Vertex buffer objects in OpenGL ES on iPhone ZooMan 5 7,641 Feb 4, 2009 07:00 PM
Last Post: ZooMan