Player Node

Player Migration

As an in-world entity, the Player must become a Node to inherit its Update and Draw methods. Instead of directly manipulating the sprite's position, the player's transform will now handle world translation, and the sprite will be drawn at the player's transform. Since the player resides at the scene tree's root, its local transform directly mirrors its global transform.

game/player.h
// -----
#include "engine/node.h" // Add: Include.

namespace game {

class Player : public ng::Node { // Add: Inherit from Node.
 public:
  Player(ng::App* app, const ng::Tilemap* tilemap);

 // --- Change: Instead of having a public Update and Draw, override the node's methods. ---
 protected:
  void Update() override;
  void Draw(sf::RenderTarget& target) override;
 // --- End ---
  
 // -----
 private:
   ng::App* app_ = nullptr; // Remove.
};

}  // namespace game

Last updated