METS BLOG

METS BLOG

Cocos2D-X Platformer tutorial Part 8 – Cleaning

Collision detection and gravity have been cleaned up, everything is smooth now, there will be 2 more parts for enemies and bullets. Some stuff has changed but there is no new logic, if you have questions just ask.


8 responses to “Cocos2D-X Platformer tutorial Part 8 – Cleaning”

  1. Pete says:

    Love the tutorials, thanks for taking the time to write there =)!
    Works flawlessy except for one minor thing:
    Every second time I jump my character goes down one tile. If I jump from a higher distance I go further down so I guess it might be something to do with the line :
    player->position.y = player->position.y + player->velocity.y;

    in GameScene.cpp
    I’m using vs2013 and cocos2d-x 3.3, any thoughts? Thank youy very much, keep up the good work!

    • metin says:

      I’ll check later today but should be okay, you however should check your Level class and collision detection. It sounds like there is a positioning issue after collision with bottom tile.

  2. Pete says:

    The fix, atleast for me, was to add the “+ 2.0f,” to “player_rect.setRect(” after the second tiles.clear()

    First time initialize:
    player_rect.setRect(
    player_sprite->getBoundingBox().getMinX() + player->velocity.x,
    player_sprite->getBoundingBox().getMinY() + 2.0f, // dont let the rectangle touch the ground otherwise, will count as collision
    player->player_size.width,
    player->player_size.height
    );

    and then second time:
    player_rect.setRect(
    player_sprite->getBoundingBox().getMinX(),
    player_sprite->getBoundingBox().getMinY(),
    player->player_size.width,
    player->player_size.height
    );

    changed to
    player_sprite->getBoundingBox().getMinY()-2.0f,

    Might be something I changed when playing around that made this, but might help someone else if they mess up the code ;). Keep up the good work Metin, love this tutorial =)

    • metin says:

      glad to see you playing around with code, you should check your code when you have the time and figure it out, check the collision methods if the correct one are called and what is changed when bottom sprite collides

  3. mikeek says:

    Hi,

    I have a problem with player “shaking” on the ground (when standing/walking). y position loops between 3 values (+-gravity), standing on platform (that part where stutteringFix = 0; is set) is detected in only 1 of 3 cases and I can’t figure why is this happening. The only thing I’ve done differently is that I have player-specific parts in it’s class and from GameScene I only call player->update(delta).

    Do you have an idea what can be causing this problem?

    Thanks, M

  4. phrk says:

    I found the bug. You need to set the Playerposition slightly different when a collision with the ground happens:

    player->position.y = tile.getMaxY()-1;

Leave a Reply

Your email address will not be published. Required fields are marked *