Posts

Showing posts from August, 2014

How to render Parallax Background and Foreground Layers Completely in the Shader [Tutorial]

Image
EDIT Oct 16 2014 : Changed precision to lowp for fragment shader. Consider using this as a default for mobile, unless you really need something better.  I saw a 2x speed increase on Kindle by doing so. Hi all! Here's a quick little diddy for anyone curious on a quick way to get a layered effect in your 2D game (note: we are still using 3D vertices): I did a little more progress on Hoarder Monkey   and I am happy to have parallax backgrounds working all in the shader and in 1 draw call per object type (static VBO, dynamic sprites, Semi-transparent VBO, semi-transparent sprites).  :) The background scrolling is all handled in the shader, and works surprisingly well.  I also do some color tweaking to make things a little darker in the foreground and blue-ish in the background: Notice the closest graphics are darker Notice the background objects are a more blue/white hue. In case your curious the shader code is pretty simple (as it should b...

How To Set Up Your Game Event Queue (Threaded) [Tutorial]

Image
Hi all, Finally back with a simple, but hopefully helpful, tutorial for you all to get an working event queue in a threaded environment.  In this case I will be using Android C++ and JNI as my playground to demonstrate. What is an event queue An event queue is a list of events that has occurred since your last game loop iteration.  Possible Events are: Button presses on game controllers Screen touch events (press up/down, multi touch, etc). Keyboard events So what is the point of this anyhow?   Many times events will occur in the middle of your game loop, asynchronously.  In Android, they occur on a different thread by default, usually called the "UI thread". If you process them as they come in on your "UI Thread" you could end up with some nasty concurrency bugs and crashes due to processing the event (in your game etc) right while the game loop thread is updating the same data. This leads to some epic head scratching and lovely...