Class: MG::Scene

Inherits:
Node
  • Object
show all
Defined in:
motion-game

Overview

This class represents a scene, an independent screen or stage of the application workflow. A scene is responsible for handling events from the device, providing a physics world for the sprites, and also starting the game loop. An application must have at least one scene, and the Scene class is designed to be subclassed.

Properties (collapse)

Attributes inherited from Node

#alpha, #anchor_point, #color, #name, #position, #rotation, #scale, #size, #visible?, #z_index

Constructors (collapse)

Update Loop (collapse)

Events (collapse)

Methods inherited from Node

#add, #children, #clear, #delete, #delete_from_parent, #intersects?, #parent

Constructor Details

- (Scene) initialize

The default initializer. Subclasses can construct the scene interface in this method, as well as providing an implementation for #update, then run the update loop by calling #start_update.



184
# File 'motion-game', line 184

def initialize; end

Instance Attribute Details

- (Boolean) debug_physics?

Returns whether the physics engine should draw debug lines.

Returns:

  • (Boolean)

    whether the physics engine should draw debug lines.



250
251
252
# File 'motion-game', line 250

def debug_physics?
  @debug_physics?
end

- (Point) gravity

Returns the gravity of the scene's physics world.

Returns:

  • (Point)

    the gravity of the scene's physics world.



247
248
249
# File 'motion-game', line 247

def gravity
  @gravity
end

Instance Method Details

- (Scene) on_accelerate {|Events::Acceleration| ... }

Starts listening for accelerometer events on the receiver.

Yields:

  • (Events::Acceleration)

    the given block will be yield when an accelerometer event is received from the device.

Returns:

  • (Scene)

    the receiver.



235
# File 'motion-game', line 235

def on_accelerate; end

- (Scene) on_contact_begin {|Events::PhysicsContact| ... }

Starts listening for contact begin events from the physics engine.

Yields:

  • (Events::PhysicsContact)

    the given block will be yield when a contact event is received from the physics engine.

Returns:

  • (Scene)

    the receiver.



241
# File 'motion-game', line 241

def on_contact_begin; end

- (Scene) on_touch_begin {|Events::Touch| ... }

Starts listening for touch begin events on the receiver.

Yields:

  • (Events::Touch)

    the given block will be yield when a touch begin event is received.

Returns:

  • (Scene)

    the receiver.



229
# File 'motion-game', line 229

def on_touch_begin; end

- (String) schedule(delay, repeat = 0, interval = 0) {|Float| ... }

Schedules a given block for execution.

Parameters:

  • delay (Float)

    the duration of the block, in seconds.

  • repeat (Integer) (defaults to: 0)

    the number of times the block should be repeated.

  • interval (Float) (defaults to: 0)

    the interval between repetitions, in seconds.

Yields:

  • (Float)

    the given block will be yield with the delta value, in seconds.

Returns:

  • (String)

    a token representing the task that can be passed to #unschedule when needed.



214
# File 'motion-game', line 214

def schedule(delay, repeat=0, interval=0); end

- (Scene) start_update

Starts the update loop. The #update method will be called on this object for every frame.

Returns:

  • (Scene)

    the receiver.



192
# File 'motion-game', line 192

def start_update; end

- (Scene) stop_update

Stops the update loop. The #update method will no longer be called on this object.

Returns:

  • (Scene)

    the receiver.



197
# File 'motion-game', line 197

def stop_update; end

- (Scene) unschedule(key)

Unschedules a task that's currently running.

Parameters:

  • key (String)

    a token representing the task to unschedule, returned by #schedule.

Returns:

  • (Scene)

    the receiver.



220
# File 'motion-game', line 220

def unschedule(key); end

- (Scene) update(delta)

The update loop method. Subclasses can provide a custom implementation of this method. The default implementation is empty.

Parameters:

  • delta (Float)

    a value representing the amount of time, in seconds, since the last time this method was called.

Returns:

  • (Scene)

    the receiver.



204
# File 'motion-game', line 204

def update(delta); end