Entity states, animations, and other random stuff

Posted on April 1, 2012 | 2 minute read

Busy day yesterday! Got a lot done. Switching light source from one entity to another proved to be surprisingly quick and easy. I was done with my emitter attribute in no time.

Then it was time to finish implementing “states” for a couple of entities. So now when the player goes up to the light source in the first level and picks it up, the light source is killed and the player is switched from the default state to the withLightSource state, which not only changes it to now become the light source but also changes its animation.

Other progress included creating a title screen level, a pointer entity to handle clicking, the first in-game item (which when picked up influences the light), and some other stuff.

Getting up

One of the most interesting challenges yesterday was putting in a placeholder “Getting up” animation. When the player spawns in level 1 they get up from the ground before going into their regular idle animation. The trick was waiting for the getting up animation to finish playing completely before going into regular idle. I implemented this as follows:

  1. When the level is spawned, the player’s state is set to “new”.

  2. The following code runs in the player’s update() function:

       // GET UP 
       if (this.state == 'new') {
           this.currentAnim = this.anims.defaultGetUp;
           if ( this.currentAnim == this.anims.defaultGetUp ){
               if ( this.currentAnim.loopCount ) {
                   //Get up animation finished. Go to idle animation
                   this.state = 'default';
               }
           }
       }
        	
       // ANIMATIONS IN DEFAULT STATE
       else if (this.state === 'default') {
               // Regular animations triggered here
       }
    

So as you can see when the get up animation has finished, the state is switched to “default”, which proceeds to trigger regular animations.

A few people commented on a couple of blog posts like this one about how reading these entires has made them want to start their own blogs to record their progress (or even start coding again!), which is awesome. I love reading other people’s game related blogs/journals/whatever, so if you happen to have a public dev blog, Twitter feed, YouTube channel, or some other method of recording your game (or software in general) development progress, please leave a comment (or email me).




Categories:game dev dev games
comments powered by Disqus