Class: RedBird::Entity

Inherits:
Object
  • Object
show all
Defined in:
lib/red_bird/entity.rb

Overview

An entity is an object that is managed by the Engine; it has a size, a position, ticks, and is renderable. RedBird::Engine.run expects every single entity that it receives from Stage to have these methods and attributes.

Direct Known Subclasses

RelativeEntity, TileMap, UIBox, VerticalMenu

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#heightInteger (readonly)

Size

Returns:

  • (Integer)


17
18
19
# File 'lib/red_bird/entity.rb', line 17

def height
  @height
end

#pos_xInteger (readonly)

Position

Returns:

  • (Integer)


13
14
15
# File 'lib/red_bird/entity.rb', line 13

def pos_x
  @pos_x
end

#pos_yInteger (readonly)

Position

Returns:

  • (Integer)


13
14
15
# File 'lib/red_bird/entity.rb', line 13

def pos_y
  @pos_y
end

#priorityInteger (readonly)

Entities with higher priorit are called first when the RedBird::Engine.run calls #tick and #render.

Returns:

  • (Integer)


22
23
24
# File 'lib/red_bird/entity.rb', line 22

def priority
  @priority
end

#widthInteger (readonly)

Size

Returns:

  • (Integer)


17
18
19
# File 'lib/red_bird/entity.rb', line 17

def width
  @width
end

Instance Method Details

#cursor_down(x, y) ⇒ Object

The RedBird::Engine.run calls this method whenever there is a click over this entity. Overwrite this function if you want your entity to react to a click.

Parameters:

  • x (Integer)

    cursor position.

  • y (Integer)

    cursor position.



50
51
52
# File 'lib/red_bird/entity.rb', line 50

def cursor_down(x, y)
  # By default do nothing
end

#cursor_hover(x, y) ⇒ Object

The RedBird::Engine.run calls this method whenever the cursor is over this entity. Overwrite this function if you want your entity to react to a cursor hover.

Parameters:

  • x (Integer)

    cursor position.

  • y (Integer)

    cursor position.



39
40
41
# File 'lib/red_bird/entity.rb', line 39

def cursor_hover(x, y)
  # By default do nothing
end

#cursor_up(x, y) ⇒ Object

The RedBird::Engine.run calls this method whenever there is a cursor release over this entity. Overwrite this function if you want your entity to react to a cursor release.

Parameters:

  • x (Integer)

    cursor position.

  • y (Integer)

    cursor position.



61
62
63
# File 'lib/red_bird/entity.rb', line 61

def cursor_up(x, y)
  # By default do nothing
end

#renderObject

The RedBird::Engine.run calls this method to render this entity into the scree. Overwrite this method if you want to change how the entity renders into the screen.



70
71
72
# File 'lib/red_bird/entity.rb', line 70

def render
  self.current_sprite.render_to_screen(self.pos_x, self.pos_y)
end

#tickObject

The RedBird::Engine.run calls this method every single frame. Overwrite it if you want your entity to do something every frame.



28
29
30
# File 'lib/red_bird/entity.rb', line 28

def tick
  # By default do nothing
end