You can create custom Ruby classes to represent sprites. To be rendered as a primitive by args.outputs.sprites, the class must:
- Implement all sprite properties (x, y, w, h, path, etc.).
- Define a method
primitive_marker that returns the symbol :sprite.
class Sprite
attr_accessor :x, :y, :w, :h, :path, :angle, :a, :r, :g, :b, :source_x,
:source_y, :source_w, :source_h, :flip_horizontally,
:flip_vertically, :angle_anchor_x, :angle_anchor_y
def primitive_marker
:sprite
end
end
class PlayerSprite < Sprite
def initialize x, y, w, h
self.x = x
self.y = y
self.w = w
self.h = h
self.path = 'sprites/player.png'
end
end
# Render the custom object
args.outputs.sprites << PlayerSprite.new(10, 10, 32, 64)