Class: Zif::Layers::ActiveLayer
- Inherits:
-
CompoundSprite
- Object
- Sprite
- CompoundSprite
- Zif::Layers::ActiveLayer
- Includes:
- Layerable
- Defined in:
- lib/zif/layers/active_layer.rb
Overview
Designed to be used with LayerGroup.
This layer is based on CompoundSprite and therefore each component sprite is rendered every tick. Use this for layers that need to be updated frequently, but have a small sprite count.
In contrast, SimpleLayer is built on RenderTarget and therefore incurs a little performance hit every time it is redrawn, but balances that by being able to cheaply display those sprites once rendered.
Deciding between SimpleLayer and ActiveLayer depends on your application. Try organizing your layers into those that don’t change at all, or only change when action (like camera movement) isn’t happening, and put those sprites into a SimpleLayer. Then take all of the sprites which do need to change often, or are necessary for action, and put those in ActiveLayers.
You can use this or SimpleLayer directly when the sprites contained don’t need to snap to the tile grid set up in the LayerGroup. Otherwise, you should use TiledLayer or ActiveTiledLayer
Direct Known Subclasses
Constant Summary
Constants inherited from Sprite
Instance Attribute Summary
Attributes included from Layerable
#layer_name, #map, #should_render, #z_index
Attributes inherited from CompoundSprite
Attributes inherited from Sprite
#a, #angle, #b, #g, #h, #logical_x, #logical_y, #name, #path, #r, #render_target, #source_h, #source_w, #source_x, #source_y, #w, #x, #y, #z_index
Attributes included from Clickable
#on_mouse_changed, #on_mouse_down, #on_mouse_up
Attributes included from Actions::Animatable
#animation_sequences, #cur_animation
Attributes included from Actions::Actionable
Instance Method Summary collapse
- #add_positioned_sprite(sprite:, logical_x:, logical_y:) ⇒ Object
-
#containing_sprite ⇒ Zif::Layers::ActiveLayer
This is not based on RenderTarget so we don’t have a “containing sprite” here.
-
#initialize(map, name, z_index: 0) ⇒ ActiveLayer
constructor
A new instance of ActiveLayer.
-
#reinitialize_sprites ⇒ Object
This will clear the sprites array.
- #remove_sprite(sprite) ⇒ Object
-
#rerender ⇒ Boolean
No-op - ActiveLayer is always rendering!.
-
#source_sprites ⇒ Array<Zif::Sprite>
This is for compatibility with SimpleLayer#source_sprites.
Methods included from Layerable
#clicked?, #exclude_from_serialize, #intersecting_sprites, #position_sprite, #remove_positioned_sprite, #target_layer_name, #visible_sprites
Methods inherited from CompoundSprite
Methods inherited from Sprite
#blend, #blend=, #center, #center_x, #center_y, #clicked?, #color, #color=, #dup_and_assign, #exclude_from_serialize, #hide, #rect, rect_array_to_hash, rect_array_to_source_hash, #rect_hash, rect_hash_to_source_hash, #show, #source_as_rect_hash, #source_center, #source_is_set?, #source_rect, #source_rect_hash, #source_wh, #source_xy, #to_h, #view_actual_size!, #wh, #xy, #zoom_factor
Methods included from Clickable
Methods included from Actions::Animatable
#new_basic_animation, #new_tiled_animation, #register_animation_sequence, #run_animation_sequence, #stop_animating
Methods included from Actions::Actionable
#bounce_forever_around, #delayed_action, #fade_in, #fade_out, #fade_out_and_in_forever, #new_action, #perform_actions, #run_action, #running_actions?, #stop_action
Methods included from Serializable
#exclude_from_serialize, #inspect, #serialize, #to_s
Methods included from Assignable
Constructor Details
#initialize(map, name, z_index: 0) ⇒ ActiveLayer
Returns a new instance of ActiveLayer.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/zif/layers/active_layer.rb', line 26 def initialize(map, name, z_index: 0) super(name) @map = map @layer_name = name @z_index = z_index @should_render = true # This does not control anything in this context since we are always rendering. reinitialize_sprites @x = 0 @y = 0 @w = @map.max_width @h = @map.max_height @source_x = 0 @source_y = 0 @source_w = @w @source_h = @h end |
Instance Method Details
#add_positioned_sprite(sprite:, logical_x:, logical_y:) ⇒ Object
54 55 56 57 |
# File 'lib/zif/layers/active_layer.rb', line 54 def add_positioned_sprite(sprite:, logical_x:, logical_y:) # puts "ActiveLayer#add_positioned_sprite: #{logical_x} #{logical_y}" @sprites << position_sprite(sprite: sprite, logical_x: logical_x, logical_y: logical_y) end |
#containing_sprite ⇒ Zif::Layers::ActiveLayer
This is not based on RenderTarget so we don’t have a “containing sprite” here. This is for compatibility with SimpleLayer#containing_sprite
47 48 49 |
# File 'lib/zif/layers/active_layer.rb', line 47 def containing_sprite self end |
#reinitialize_sprites ⇒ Object
This will clear the sprites array.
71 72 73 |
# File 'lib/zif/layers/active_layer.rb', line 71 def reinitialize_sprites @sprites = [] end |
#remove_sprite(sprite) ⇒ Object
60 61 62 |
# File 'lib/zif/layers/active_layer.rb', line 60 def remove_sprite(sprite) @sprites.delete(sprite) end |
#rerender ⇒ Boolean
No-op - ActiveLayer is always rendering!
77 78 79 |
# File 'lib/zif/layers/active_layer.rb', line 77 def rerender true end |
#source_sprites ⇒ Array<Zif::Sprite>
This is for compatibility with SimpleLayer#source_sprites
66 67 68 |
# File 'lib/zif/layers/active_layer.rb', line 66 def source_sprites @sprites end |