Class: GamePlay::BaseCleanUpdate

Inherits:
Base show all
Defined in:
scripts/01450 Systems/00000 General/00003 GamePlay__Base/00000 GamePlay__Base.rb

Overview

Base Scene where you should not define update but dedicated update methods : “`ruby

class MyScene < BaseCleanUpdate
  # Called when input can be updated (put your input related code inside)
  # @return [Boolean] if the update can continue
  def update_inputs
    # ...
    return true
  end

  # Called when mouse can be updated (put your mouse related code inside)
  # @param moved [Boolean] boolean telling if the mouse moved
  # @return [Boolean] if the update can continue
  def update_mouse(moved)
    return unless moved
    # ...
    return true
  end

  # Called each frame after message update and eventual mouse/input update
  # @return [Boolean] if the update can continue
  def update_graphics
    # ...
    return true
  end
end

“` All the update methods are optionnal but you should define at least one otherwise your Scene will be useless and softlock the game

Defined Under Namespace

Classes: FrameBalanced

Constant Summary collapse

AIU_KEY2METHOD =
{
  A: :action_a, B: :action_b, X: :action_x, Y: :action_y, L: :action_l, R: :action_r,
  L2: :action_l2, R2: :action_r2, L3: :action_l3, R3: :action_r3,
  START: :action_start, SELECT: :action_select, HOME: :action_home
}

Constants inherited from Base

GamePlay::Base::DEFAULT_TRANSITION, GamePlay::Base::DEFAULT_TRANSITION_PARAMETER

Constants included from Input

Input::ALIAS_KEYS, Input::AXIS_MAPPING, Input::AXIS_SENSITIVITY, Input::DEAD_ZONE, Input::Keyboard, Input::Keys, Input::NON_TRIGGER_ZONE, Input::REPEAT_COOLDOWN, Input::REPEAT_SPACE

Constants included from DisplayMessage

DisplayMessage::MESSAGE_ERROR, DisplayMessage::MESSAGE_PROCESS_ERROR

Instance Attribute Summary

Attributes inherited from Base

#__last_scene, #__result_process, #running, #viewport

Attributes included from DisplayMessage

#message_window

Instance Method Summary collapse

Methods inherited from Base

#add_disposable, #call_scene, #dispose, #find_parent, #initialize, #main, #return_to_scene, #snap_to_bitmap, #visible, #visible=

Methods included from Input

dir4, dir8, get_text, joy_axis_position, press?, register_events, released?, repeat?, swap_states, trigger?

Methods included from DisplayMessage

#can_display_message_be_called?, #close_message_window, #display_message, #display_message_and_wait, #message_class, #message_processing?, #message_visible, #message_visible=

Constructor Details

This class inherits a constructor from GamePlay::Base

Instance Method Details

#automatic_input_update(key2method = AIU_KEY2METHOD) ⇒ Boolean

Automatically detect input update and call the corresponding action method

Examples:

Use the generic aiu

def update_inputs
  return false unless automatic_input_update
  # Do something else
  return true
end

Use aiu with specific functions

return false unless automatic_input_update(A: :action_a2, B: :action_b2)

Parameters:

  • key2method (Hash) (defaults to: AIU_KEY2METHOD)

    Hash associating Input Keys to action method name

Returns:

  • (Boolean)

    if the update_inputs should continue



488
489
490
491
492
493
494
495
496
# File 'scripts/01450 Systems/00000 General/00003 GamePlay__Base/00000 GamePlay__Base.rb', line 488

def automatic_input_update(key2method = AIU_KEY2METHOD)
  key2method.each do |key, method_name|
    if respond_to?(method_name, true) && Input.trigger?(key)
      send(method_name)
      return false
    end
  end
  return true
end

#updateBoolean

Scene update process

Returns:

  • (Boolean)

    if the scene should continue the update process or abort it (message/animation etc…)



463
464
465
466
467
468
469
470
471
472
473
474
475
# File 'scripts/01450 Systems/00000 General/00003 GamePlay__Base/00000 GamePlay__Base.rb', line 463

def update
  can_continue = true
  # Process message
  can_continue = false unless super
  # Update inputs
  can_continue = false if can_continue && respond_to?(:update_inputs, true) && update_inputs == false
  # Update mouse
  can_continue = false if can_continue && respond_to?(:update_mouse, true) && update_mouse(Mouse.moved) == false
  # Update the graphics at the end with the correct state
  return update_graphics && can_continue if respond_to?(:update_graphics, true)

  return can_continue
end