Monthly Archives: September 2013

Buoyancy in Box2D – Multiple Pools

An earlier post covered the basics of using the buoyancy controller in Box2D. In that example there was one buoyancy controller and all bodies were added to it by default. But you may want control when a body is added to a buoyancy controller, for example if your player is jumping into or out of a body of water. You may even have different water obstacle at different vertical positions in your game. This post shows you how to manage multiple buoyancy controllers and how to determine when to add or remove bodies to them. Continue reading Buoyancy in Box2D – Multiple Pools

Buoyancy in Box2D – The Basics

Who doesn’t like playing with water? There’s something childishly enjoyable about watching objects bobbing around on the surface or horror of something quickly sinking in to the the dark abyss. Box2D makes simulating buoyancy  simple with help of the b2BuoyancyController. But keep in mind, this Box2D only simulates buoyancy not all the a liquid, so don’t expect it to make waves. That is some magic you will need to work out yourself.  Continue reading Buoyancy in Box2D – The Basics

Start here

Introduction

For every problem there is – usually – more than one solution. There are solutions that solve one particular problem and there are general solutions that can be applied more generally. And you will probably choose the one that suits your current needs. The purpose of this site is not to tell you which solution is right or wrong. Isn’t that what requirement specifications are for?

What you will find here are solutions to:

  • Problems for which I have not found good or complete solutions.
  • Problems for which I have found a solution, but the solution was provided in a different programming language and needed to be ported to the one I was using.
  • Needle in haystack solutions. Gems (e.g. code snippets) hidden in the rough that are good to bring into the light.

Hopefully you will find something that will help you or inspire you tackle new problems. Feel free to use, modify or extend code you find here.

Uncertainty is certain. It is not clear which subjects will be covered in this blog in the long-term. But I am certain that in the short-term it will focus on Javascript, HTML5, and Box2D. Which put together spells out GAMES. Box2D is currently my preferred physics simulator to achieve believable real-life behavior between physics bodies. Created and maintained by Eric Catto originally in C++, it has been ported to a number of other languages, including Javascript.

Prerequisites

You should be familiar with at least Javascript and the basics of Box2D. But you should be able to figure out a lot of the basics via the provided example code. Check out the References page for some links to other sites that will help you get on track to learn the basics.

The nice thing about Javascript and Box2D is that you don’t need a server. Unless otherwise mentioned, the examples should run directly in your browser without needing a www-server or Internet connection.

When things don’t work

It doesn’t take long to notice that Javascript isn’t implemented the same on all browsers. In fact all browsers have their own flavor of something or another. Some browsers don’t yet fully support HTML5 which means the canvas object won’t work at all…Most of the code will be tested in newer versions on Safari, Firefox and Chrome. But let me know if it’s not working in your browser. The ambition is to provide code that is as ubiquitous as possible.