Friday 11 January 2013

Levelhelper introduction


LevelHelper API
            In order to have a good user experience, LevelHelper come with its own API. 
The API is added to the project trough LevelHelper itself, and is automatically installed. It acts as a wrapper for Box2D and Cocos2d.
            LevelHelper’s API contains the LHSprite class. This can be seen as a CCSprite with a physics body attached to it. This means that when creating an LHSprite object, the updating of the texture to the body’s position is automatically handled.
            For the loading of levels and the creation of sprites, the LevelHelperLoader class is used. This class also allows us to set up collision callbacks (methods triggered when a collision between bodies occurs).
            Furthermore, the LevelHelper API lets us set up tags and custom properties for our game. Tags are used to identify groups of objects. For instance, for checking whether a building of tag bunker should be destroyed or not, Tank Rampage checks the following statement:
for (LHSprite*bunker in [lh spritesWithTag:BUNKER]) {

        if ([bunker.userInfo Lives]<=0&&![bunker.userInfo Destroyed]){

            [self destroyBunker:bunker];

        }

    }










Notice the second if-statement. Here it’s checked whether the custom property Lives is equal or lower than zero. LevelHelper allows us to make custom user classes (with their own properties) and assign them to a sprite. In our levels, all bunker type buildings are from the user class LevelPartClass, which has a property of type number called Lives. Being able to do this inside LevelHelper allows us to attach values to a sprite without having to write a single line of code.

No comments:

Post a Comment