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.


  • Pete

    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

      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.

  • Pete

    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

      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

  • mikeek

    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

    • metin

      Yeah that’s a bug, I will fix it when I have some free time. If you have solved it can you share it? ๐Ÿ™‚

  • phrk

    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;

  • Pingback: Cocos s์ข‹์€ ์ž๋ฃŒ๋“ค ๋งํฌ | gongsick()

Recent Posts

Recent Comments

Categories