Creating Player Movement in Games

Creating Player Movement in Games

Player movement is one of the most important parts of any game. A game may have beautiful graphics music effects and animations but if the player movement feels bad the game will not feel fun. Good movement makes the player feel connected to the game world. It gives control speed challenge and excitement.

In Flutter web games using Flame Engine movement can be created in many different ways. Some games move the character directly. Some games create the illusion of movement. Some games move objects using physics. Others use images animations touch input or keyboard controls.

In this chapter you will learn different ways to create movement systems in Flutter web games. You will understand how movement works in endless runner games maze games chess style games shooting games image based movement systems animation movement physics based movement and canvas rendering movement.

Still Player Movement in Traffic Rush

One of the easiest movement systems to understand is the endless runner movement style. In games like Traffic Rush the player often looks like they are moving forward but in reality the player is standing almost in the same place.

This creates something called movement illusion. Instead of moving the player across the world the world itself moves toward the player. Obstacles move from right to left or top to bottom. The background scrolls. Clouds move slowly. Ground tiles move continuously. This tricks the brain into feeling movement.

This system is very useful for web games because it is simple and fast. The game does not need huge maps or large camera systems. Everything moves in one direction. This also makes collision detection easier.

In a Traffic Rush game the player car usually stays around the left or bottom side of the screen. The only real movement is lane switching. Everything else moves around the player.

The road can move using repeated image scrolling. Obstacles can spawn outside the screen and move toward the player. Once they leave the screen they are removed.

The player feels like they are driving forward even though their position changes very little.

class PlayerCar {
  double x = 100
  double y = 300

  double laneY = 0

  void switchLane() {
    y = 400
  }

  void update() {
    // Car stays in position while world moves
  }
}

In this example the player car only switches lanes. The car does not drive across the screen. The illusion of movement is created by moving the environment.

class EnemyCar {
  double x = 800
  double y = 320

  void update() {
    x -= 6
  }
}

Here the enemy car moves left every frame. Since the player car stays mostly in one place the game feels like forward driving.

This type of movement is perfect for endless runner games because it keeps gameplay simple and smooth.

Actual Movement with Maze Square

Some games need real movement instead of illusion movement. Maze games are a perfect example. In a maze game the player must move through walls paths corners and obstacles. The player position truly changes inside the world.

Maze movement is usually grid based or free movement. Grid movement means the player moves one square at a time. Free movement means the player can move smoothly in any direction.

A simple maze square game often uses keyboard controls. The arrow keys move the player up down left or right.

This type of movement teaches important game programming ideas such as position updates collision checking speed control and world boundaries.

In Flame movement normally happens inside the update method. Every frame the player position changes based on speed and input.

class MazePlayer {
  double x = 100
  double y = 100

  double speed = 4

  bool moveLeft = false
  bool moveRight = false
  bool moveUp = false
  bool moveDown = false

  void update() {
    if (moveLeft) {
      x -= speed
    }

    if (moveRight) {
      x += speed
    }

    if (moveUp) {
      y -= speed
    }

    if (moveDown) {
      y += speed
    }
  }
}

This code creates simple maze movement. The player changes position depending on which key is pressed.

Maze movement becomes more interesting when walls are added. Before moving the player, the game checks if a wall blocks the path.

If the next position contains a wall movement is stopped. This creates the feeling of physical space inside the game world.

Maze games also teach camera movement. If the map becomes larger than the screen the camera follows the player.

Real movement systems are used in adventure games role playing games survival games and puzzle games.

Tap Movement in Chess Style Games

Not all games use keyboard movement. Some games use tap movement. Chess style games are a good example of this system.

In tap movement the player selects a location instead of controlling every step manually. The game then moves the piece automatically.

This movement style is very popular in strategy games mobile games board games and puzzle games.

In Flutter web games tap movement can be created using mouse clicks or touch input. When the player taps a tile the game updates the character position.

Chess movement is usually grid based. Every square has a fixed size. Pieces move from one square to another.

The game calculates the target position and then animates the movement.

class ChessPiece {
  double x = 0
  double y = 0

  void moveTo(double newX, double newY) {
    x = newX
    y = newY
  }
}

When the user taps a square, the game converts the tap location into grid coordinates.

void onTap(double tapX, double tapY) {
  double tileSize = 64

  double gridX = (tapX / tileSize).floor() * tileSize
  double gridY = (tapY / tileSize).floor() * tileSize

  piece.moveTo(gridX, gridY)
}

This creates clean tile based movement. The piece always stays perfectly aligned with the board.

Tap movement systems are easier for beginners because movement logic is controlled by game rules instead of continuous input.

This style also works very well on touch screens because players simply tap where they want to move.

Fire Bullet from Gun

Shooting movement is another important system in games. In shooting games bullets move independently after being created.

A bullet usually starts at the player position. Then it moves continuously in one direction until it leaves the screen or hits something.

This teaches object spawning and movement updates. Every bullet is its own object with its own speed and position.

Bullet systems are used in shooting games platform games survival games and space games.

In Flame bullets are often stored inside a list. Every frame the game updates all bullets.

class Bullet {
  double x
  double y

  double speed = 10

  Bullet(this.x, this.y)

  void update() {
    x += speed
  }
}

When the player presses a button, a new bullet is created.

List<Bullet> bullets = []

void fireGun(double playerX, double playerY) {
  bullets.add(Bullet(playerX, playerY))
}

During every frame update, all bullets move forward.

void updateBullets() {
  for (var bullet in bullets) {
    bullet.update()
  }
}

Shooting systems can later become more advanced with collision detection enemy damage explosion effects and different bullet patterns.

Some games use straight bullets. Others use curved movement homing bullets or physics based projectiles.

Understanding bullet movement is important because many game mechanics depend on moving objects.

Movement with Canvas

Canvas movement is one of the most important ideas in game development. In Flutter games the canvas is the drawing area where everything appears on the screen.

Every frame the game clears the screen and redraws objects in new positions. This repeated drawing creates animation and movement.

The canvas itself does not move. Instead the objects drawn on the canvas change positions many times every second.

Canvas based movement is used in almost every game engine.

In Flutter movement with canvas often happens inside the render method or paint method.

double playerX = 100

void update() {
  playerX += 5
}

void render(Canvas canvas) {
  Paint paint = Paint()

  canvas.drawRect(
    Rect.fromLTWH(playerX, 200, 50, 50),
    paint,
  )
}

In this example the square moves right because the x position increases every frame.

Canvas movement gives complete control over graphics. Developers can draw shapes images particles text and effects.

It is also very fast because the game only redraws the current frame.

Understanding canvas movement helps developers create custom game systems instead of depending only on premade widgets.

Most advanced Flutter games combine canvas rendering with Flame components for better organization.

Movement with Image

Image based movement is the most common movement style in modern games. Instead of moving simple shapes the game moves sprite images.

A sprite is a game image used for characters enemies objects or effects.

In Flutter Flame sprite movement works by changing the image position every frame.

The image itself does not contain movement. The game changes where the image is drawn.

This creates smooth animation and realistic gameplay.

class PlayerSprite {
  double x = 100
  double y = 200

  double speed = 3

  void moveRight() {
    x += speed
  }
}

The sprite image is drawn using its current position.

SpriteComponent(
  sprite: playerSprite,
  position: Vector2(x, y),
  size: Vector2(64, 64),
)

Image movement becomes more realistic when animations are added. Walking frames running frames and jumping frames can all play while moving.

Sprite movement is used in platform games action games fighting games and adventure games.

Most professional games depend heavily on image based movement systems.

GIF Movement

GIF movement is another way to create animation in games. A GIF is a sequence of images played repeatedly.

Instead of manually changing frames, the GIF already contains animated frames.

GIF movement is simple for beginners because it quickly creates animated characters.

However, GIF files are usually less efficient than sprite sheets. Many professional games avoid GIFs because they use more memory and offer less control.

Still GIF movement can be useful for simple web games loading screens effects or prototypes.

Flutter supports GIF images using Image widgets or asset loading.

Image.asset(
  'assets/player_run.gif',
  width: 100,
  height: 100,
)

The GIF automatically animates when displayed.

Some developers combine GIF movement with manual movement systems. The GIF handles animation while the game updates position.

double playerX = 100

void update() {
  playerX += 4
}

This makes the animated GIF move across the screen.

While GIFs are easy to use, sprite sheets are normally better for performance in large games.

Physics Based Movement

Physics movement makes games feel realistic. Instead of directly controlling position physics systems use forces gravity velocity acceleration and collision reactions.

Physics creates natural movement. Objects fall bounce slide and collide in believable ways.

In platform games jumping usually depends on gravity physics. In racing games movement depends on acceleration and friction.

Physics systems are powerful because they simulate real world motion.

One of the simplest physics systems is gravity.

class PhysicsPlayer {
  double y = 200

  double velocityY = 0
  double gravity = 0.8

  void update() {
    velocityY += gravity
    y += velocityY
  }

  void jump() {
    velocityY = -15
  }
}

The player moves upward when jumping then gravity slowly pulls the player back down.

Physics movement creates smoother and more natural gameplay than direct position movement.

Advanced physics systems can include momentum bouncing friction slopes and object weight.

Flame also supports external physics engines like Forge2D for advanced simulation.

Physics movement is important for platform games puzzle games racing games and simulation games.

Understanding physics helps developers create movement that feels alive and responsive.

Conclusion

Player movement is the foundation of every game. Different games use different movement systems depending on gameplay style and player interaction.

Endless runners create movement illusion by moving the world around the player. Maze games use true position movement. Chess games use tap based movement. Shooting games create moving bullets. Canvas systems redraw objects every frame. Image movement uses sprites. GIF movement uses animated images. Physics systems simulate realistic motion.

Learning these movement systems gives you the ability to build many different types of Flutter web games. Once movement feels smooth and responsive the game immediately becomes more fun and professional.

In the next chapters you will learn about enemies collision systems hitboxes and physics interactions that work together with movement systems.

← Previous Chapter Next Chapter 12 →