I'm making a simple 2d game in OpenGL ES and I want to add movement buttons to it. What's the best way of going about this? In previous projects I've simply added UIButtons to the view but I hear there are performance implications in doing so with OpenGL ES so I'm wondering what the possible alternatives are if so.
2 Answers
If you can detect the user tapping on the screen, and know how to draw a simple textured 'quad' (two textured triangles or a triangle strip/fan) then the simplest button is just a combination of the two.
Draw a quad on the screen, texture it with your button's image, then do a simple bounding box test to see if the user has tapped inside it.
Be careful researching about 'OpenGL GUIs' and the like, it can get horrifically complex very quickly. Write your game with the simplest thing that works rather than setting out to design your own GUI library.
I don't want to sound snarky, but have you actually profiled the performance of using a UIButton? Sometimes the simplest answer is the more appropriate. If the full on UIView is too much, maybe just using Core Graphics alone on a CAShapeLayer is good enough and would be less code. Don't just throw out all the stuff Apple gives you, leverage what's there when it makes sense.