Mets Blog

Libgdx tutorial beginner Part 3 – Map

Libgdx tutorial part 3, time to add some movement to the player and our main focus will be on how the map is rendered.

  • Here is the stripped down versions of Map and MapRenderer
  • Map contains data and MapRenderer will draw our map usin that data
  • Bob is also created here and will be updated by the Map class
  • Tiles are added according to the levels.png, each pixel represents a tile, ex. white ones are walls, blues are lasers etc.
  • We also edit the GameScreen to start rendering our Map
  • Dispensers are checkpoints, once you collide with it, it will get updated


  • Roman

    Can you please explain that part of code ?

    player.getVelocity().scl(delta);
    // unscale the velocity by the inverse delta time and set
    // the latest position
    player.getPosition().add(player.getVelocity());
    player.getVelocity().scl(1 / delta);

    • sotrh

      The scl function multiplies the x and y values of players velocity vector by the value passed in (delta in this case). The delta value scales the vector to account for the time since the last frame. The velocity vector needs to be unscaled (by using the final line of code you included) to maintain accuracy.