class
Crame::Game
- Crame::Game
- Reference
- Object
Overview
Game is the class used to represent the main entry point of your game. This is what
your game code will inherit from.
In the class inheriting Game, there are some useful methods and callbacks that you
can (and should) define to make your game run:
Game.initialize: The constructor of your game, where you declare the needed variables before your game starts. This is also where you call the parent constructor viasuper(this is essential, otherwise the game won't be able to run). In particular, thesupercall is used to create the main window.Game.update(dt : Time::Span): The callback that handles the game's logic. Everything you put in here should be used to update the state of your game (for example moving your character when you hold down a key of your keyboard). Thedtparameter in the callback refers to the elapsed time since the previous frame. Useful if you want a smooth animation, independently from your monitor's refresh rate.Game.physics_update(dt : Time::Span): Same asGame.update(dt : Time::Span), but is more meant to interact with the physics engine. The only difference is that thedtparameter is guaranteed to be a fixed value. Useful if you want determinism in your simulation.Game.draw: The callback that tells the game what to render in your window. This is where you want to draw anything that can be drawable.
WARNING Mixing methods to the callbacks they shouldn't belong to (for example, putting
in Game.draw what should be in Game.update(dt : Time::Span)) may result in unexpected
behaviours.
Defined in:
crame/game.crConstructors
-
.new(title : String, size : Vector2)
Creates a new instance of the game.
Instance Method Summary
-
#run
Makes the game run its main loop.
-
#window : Window
Returns the main window of the game.
Constructor Detail
Creates a new instance of the game.
This constructor is used to create the main window, where everything related to the game will be handled and rendered.
NOTE When redefined by the class inheriting this one in the form of Game.initialize,
this constructor must be called as a super method.