Method: MiniGL::GameObject#initialize
- Defined in:
- lib/minigl/game_object.rb
#initialize(x, y, w, h, img, img_gap = nil, sprite_cols = nil, sprite_rows = nil, mass = 1.0, retro = nil) ⇒ GameObject
Creates a new game object.
Parameters:
- x
-
The x-coordinate of the object’s bounding box. This can be modified later via the
xattribute. - y
-
The y-coordinate of the object’s bounding box. This can be modified later via the
yattribute. - w
-
The width of the object’s bounding box.
- h
-
The height of the object’s bounding box.
- img
-
The image or spritesheet for the object.
- img_gap
-
A Vector object representing the difference between the top left corner of the bounding box and the coordinates of the image. For example, an object with
x = 100,y = 50andimg_gap = Vector.new(-5, -5)will be drawn at position (95, 45) of the screen. - sprite_cols
-
The number of columns in the spritesheet. Use
nilif the image is not a spritesheet. - sprite_rows
-
The number of rows in the spritesheet. Use
nilif the image is not a spritesheet. - mass
-
The mass of the object. Details on how it is used can be found in the Movement module.
216 217 218 219 220 221 222 223 224 225 226 227 228 229 |
# File 'lib/minigl/game_object.rb', line 216 def initialize(x, y, w, h, img, img_gap = nil, sprite_cols = nil, sprite_rows = nil, mass = 1.0, retro = nil) super x, y, img, sprite_cols, sprite_rows, retro @w = w; @h = h @img_gap = if img_gap.nil? Vector.new 0, 0 else img_gap end @mass = mass @speed = Vector.new 0, 0 @max_speed = Vector.new 15, 15 @stored_forces = Vector.new 0, 0 end |