Game Development Reference
In-Depth Information
Screen Coordinates And Depth
Just like most conventional computer graphics libraries, Gosu treats x as horizontal axis
(left to right), y as vertical axis (top to bottom), and z as order.
Screen coordinates and depth
x and y are measured in pixels, and value of z is a relative number that doesn't mean
anything on it's own. The pixel in top-left corner of the screen has coordinates of 0:0 .
z order in Gosu is just like z-index in CSS. It does not define zoom level, but in case
two shapes overlap, one with higher z value will be drawn on top.
Main Loop
The heart of Gosu library is the main loop that happens in Gosu::Window . It is explained
fairly well in Gosu wiki, so we will not be discussing it here.
Moving Things With Keyboard
We will modify our “Hello, World!” example to learn how to move things on screen. The
following code will print coordinates of the message along with number of times screen
was redrawn. It also allows exiting the program by hitting Esc button.
01-hello/hello_movement.rb
1 require 'gosu'
2
3 class GameWindow < Gosu :: Window
4 def initialize (width =320 , height =240 , fullscreen = false )
5 super
6
self . caption = 'Hello Movement'
@x = @y = 10
7
Search WWH ::




Custom Search