Using OpenGL in 2D games

I’m well down the road of developing my first android game, which uses fairly fast moving sprites and rectangle collision detection etc.

I’m just using surfaceview and canvas at the moment and so far my prototype is running fine at 60 fps on the Nexus 7 and HTC Desire (although I did try a Wildfire and it struggled so not sure if I will support ldpi devices yet).

Obviously it would be nice to get it moving as silky smooth as possible. Since I can’t draw for toffee it has an 8-bit graphics feel (also I like the retro look). :slight_smile:

My questions are:

  1. Is it worth going down the road of using something like glsurfaceview to get access to hardware acceleration for a 2D game?

  2. Is that the best way to do it or are there any recommended libraries/frameworks?

Thanks in advance. There doesn’t appear to be an awful lot out there about doing 2D stuff with OpenGL.

Hello!

For the second question i recommend AndEngine! Great free game engine for 2d games with active community.

And I recommend libGDX. :slight_smile:

I think libgdx is better than AndEngine because it give you more freedom and because of the possibility to test without emulator :slight_smile:

Is it difficult to put advertising in your game, if you use AndEngine or libgdx? Does using these engines limit the ad networks available to you?

You need to follow a tutorial on libgdx but no limitations. :slight_smile:

I also prefer libGDX - there is no limitation for advertisement - you can think of a “libgdx-view” (like a surfaceview) and can just handle it like that when it comes to put ads in or around.

Im starting with Andengine, and Im love it! But there are very little documentation and the andengine comunity is active but the not reply usually the questions :frowning: If andendgine had a Wiki, all be colorfull (sorry for my english!)

AndEngine is tempting me too… but from my reading, you can’t load images from the res/drawable/hdpi, res/drawable/mdpi (etc) folders? I know the engine scales the images, but I would think the performance wouldn’t be great if you try to use an hdpi image on an ldpi phone. The smaller phones may not have enough heapsize, for example. (Surprisingly, there are people using my app on 240x320 phones.)

even the small phones have good amount of mem space … btw. textures are not located in the heap :slight_smile:

Worm Puncher is using three(!) 1024x1024 (dynamically mipmapped! so x2) textures loaded all into gfx mem - and it works even on very old phones. not sure if libgdx has any influence on the actual mem usage.

Robo Miner has some serious heap issues because the game world is hold in the heap (without fragmentation) - so it force closes at different levels because out of mem :slight_smile: to be honest, newer phones does not really struggle with that

Thanks for all the info… I have lots to learn. I find myself wondering which would be harder - learning OpenGL ES and coding in “pure Android”, or learning AndEngine/libgdx and making the frameworks bend to what I want (like trying out ad networks, leaderboards or whatever).

use a library … especially for 2D :slight_smile: they spare you a lot of time and care heavily for performance issues. libgdx as an extra let you built your game to a java programm (3 lines of code extra + some clicks) which you can run on your desktop which speeds up development and debuging immensly. that’s my main reason, why I use libgdx.

Thanks for the info guys. I think I`ll definitely be giving lib-gdx a look.

I`ve had a flick through some of the tutorials and it would mean redoing the structure of my app quite a bit, but as most of the logic is kept within the entities themselves it should hopefully be doable without too much of a rewrite.

How does lib-gdx work with different activities, or is the whole thing set up within one lib-gdx view? Just a thought since my current vanilla implementation has 3 activities: main menu -> game screen -> results screen.

you have 1 libgdx “view” … which is actually an opengl view :slight_smile:

libgdx does internally feature the screen-class … never used them, I am oldschool, but you can have different screens and just switch them to render

I suggest to check here:
http://steigert.blogspot.it/