Project update #2

Done on April 16, 2017 – Player controller


For this second update I took care of the following things:

  • Limited the frame rate and passed it to the Update method
  • Created a Player controller with multiple states (Idle, Run and Attack)
  • Improved the Animation class (first draft from the update #1)

Here’s what the Player’s Load method looks like:

bool Player::Load()
    bool success = true;

    // Load the idle animation
    if (!m_animations[PlayerState_Idle].LoadFromFile("Data/Textures/Scavengers_SpriteSheet.png", 6, 0.220f, 0, 0, 32, 32, true))
        std::cout << "Failed to load animation!" << std::endl;
        success = false;

    // Load the attack animation
    if (!m_animations[PlayerState_Attack].LoadFromFile("Data/Textures/Scavengers_SpriteSheet.png", 2, 0.120f, 0, 5, 32, 32, false))

    // Load the run animation (fast-paced idle)
    if (!m_animations[PlayerState_Run].LoadFromFile("Data/Textures/Scavengers_SpriteSheet.png", 6, 0.080f, 0, 0, 32, 32, true))

    return success;

All the parameters defining the animation are passed to the LoadFromFile method:

  1. File path of the sprite sheet
  2. Number of sprites for this animation
  3. Duration of each frame in seconds (fixed duration used for every frame)
  4. Sprite index on the row
  5. Sprite index on the column
  6. Width of the sprites
  7. Height of the sprites
  8. A boolean indicating it the animation loops

There’s still a bunch of things that should be improved here.

The animation’s parameters are no longer hard coded in the Animation class but in the Player. I’ll have to move those values in a configuration file.

Also in this version, the same sprite sheet is loaded 3 times, once per animation, which is obviously a problem. I’m thinking about writing a ResourceManager to solve this.

I’ll cover the frame rate limitation in a separate post.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s