Class: MG::Sprite

Inherits:
Node
  • Object
show all
Defined in:
doc/API_reference.rb

Properties collapse

Attributes inherited from Node

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

Spritesheets collapse

Constructors collapse

Actions collapse

Physics collapse

Methods inherited from Node

#add, #children, #clear, #delete, #delete_from_parent, #intersects?, #parent, #run_action, #stop_action, #stop_all_actions

Constructor Details

#initialize(sprite_name) ⇒ Sprite

Creates a new sprite object from sprite_name, which must be either the name of a standalone image file in the application’s resource directory or the name of a sprite frame which was loaded from a spritesheet using load.

Parameters:

  • sprite_name (String)

    the name of the sprite to create.



900
# File 'doc/API_reference.rb', line 900

def initialize(sprite_name); end

Instance Attribute Details

#category_maskInteger

Returns physics category mask.

Returns:

  • (Integer)

    physics category mask.



1018
1019
1020
# File 'doc/API_reference.rb', line 1018

def category_mask
  @category_mask
end

#collision_maskInteger

Returns physics collision mask.

Returns:

  • (Integer)

    physics collision mask.



1024
1025
1026
# File 'doc/API_reference.rb', line 1024

def collision_mask
  @collision_mask
end

#contact_maskInteger

Returns physics contact test mask.

Returns:

  • (Integer)

    physics contact test mask.



1021
1022
1023
# File 'doc/API_reference.rb', line 1021

def contact_mask
  @contact_mask
end

#dynamic?Boolean

Returns whether the sprite body should be dynamic or not in the physics world. The default is true, and a dynamic body will affect with gravity.

Returns:

  • (Boolean)

    whether the sprite body should be dynamic or not in the physics world. The default is true, and a dynamic body will affect with gravity.



1003
1004
1005
# File 'doc/API_reference.rb', line 1003

def dynamic?
  @dynamic?
end

#frictionFloat

Returns the linear damping / air friction force on the sprite body.

Returns:

  • (Float)

    the linear damping / air friction force on the sprite body.



1006
1007
1008
# File 'doc/API_reference.rb', line 1006

def friction
  @friction
end

#gravitates?Boolean

Returns whether the sprite should be affected by the scene’s gravitational force. The default is true.

Returns:

  • (Boolean)

    whether the sprite should be affected by the scene’s gravitational force. The default is true.



998
999
1000
# File 'doc/API_reference.rb', line 998

def gravitates?
  @gravitates?
end

#inertia_momentFloat

Returns the moment of inertia of the body.

Returns:

  • (Float)

    the moment of inertia of the body.



1015
1016
1017
# File 'doc/API_reference.rb', line 1015

def inertia_moment
  @inertia_moment
end

#massFloat

Returns the body mass of the sprite.

Returns:

  • (Float)

    the body mass of the sprite.



994
995
996
# File 'doc/API_reference.rb', line 994

def mass
  @mass
end

#resting?Boolean

Returns whether the body is at rest.

Returns:

  • (Boolean)

    whether the body is at rest.



1012
1013
1014
# File 'doc/API_reference.rb', line 1012

def resting?
  @resting?
end

#velocityPoint

Returns the velocity force on the sprite body.

Returns:

  • (Point)

    the velocity force on the sprite body.



1009
1010
1011
# File 'doc/API_reference.rb', line 1009

def velocity
  @velocity
end

Class Method Details

.load(file_name) ⇒ nil

Loads all sprites from the content of file_name, which should be the name of a property list spritesheet file in the application’s resource directory. Once a spritesheet file is loaded, individual sprites can be created using #initialize by providing the name of the frame. Sprite frames files can be created with a visual editor such as TexturePacker.

Parameters:

  • file_name (String)

    the name of the sprite frames property list file.

Returns:

  • (nil)


890
# File 'doc/API_reference.rb', line 890

def self.load(file_name); end

Instance Method Details

#animate(frame_names, delay, loops = 1) ⇒ Sprite

Starts an animation where the sprite display frame will be changed to the given frames in sprite_frames_names based on the given delay and repeated loops times.

Parameters:

  • frame_names (Array<String>)

    an array of sprite frames to load and use for the animation, which can be either the names of standalone image files in the application’s resource directory or the names of sprite frames loaded from a spritesheet using load.

  • delay (Float)

    the delay in seconds between each frame animation.

  • loops (Integer, Symbol) (defaults to: 1)

    the number of times the animation should loop. If given the :forever symbol, the animation will loop forever.

Returns:



951
# File 'doc/API_reference.rb', line 951

def animate(frame_names, delay, loops=1); end

#apply_force(force) ⇒ Sprite

Applies an immediate force to the sprite body.

Parameters:

  • force (Point)

    the force to apply.

Returns:



988
# File 'doc/API_reference.rb', line 988

def apply_force(force); end

#apply_impulse(force) ⇒ Sprite

Applies a continuous force to the sprite body.

Parameters:

  • force (Point)

    the force to apply.

Returns:



983
# File 'doc/API_reference.rb', line 983

def apply_impulse(force); end

#attach_physics_box(size = nil) ⇒ Sprite

Attaches a physics body with a box shape to the sprite.

Parameters:

  • size (Size) (defaults to: nil)

    the size of the box. If nil is given, the size of the sprite, retrieved with Node#size, will be used instead.

Returns:



978
# File 'doc/API_reference.rb', line 978

def attach_physics_box(size=nil); end

Blinks the receiver.

Parameters:

  • number_of_blinks (Integer)

    the number of times the receiver should blink.

  • interval (Float)

    the animation interval.

Returns:



938
# File 'doc/API_reference.rb', line 938

def blink(number_of_blinks, interval); end

#flipped_horizontally=(value) ⇒ Object

Sets whether the sprite should be flipped horizontally or not. It only flips the texture of the sprite, and not the texture of the sprite’s children. Also, flipping the texture doesn’t alter the anchorPoint.

Parameters:

  • value (Boolean)

    true if the sprite should be flipped horizontally, false otherwise.



957
# File 'doc/API_reference.rb', line 957

def flipped_horizontally=(value); end

#flipped_vertically=(value) ⇒ Object

Sets whether the sprite should be flipped vertically or not. It only flips the texture of the sprite, and not the texture of the sprite’s children. Also, flipping the texture doesn’t alter the anchorPoint.

Parameters:

  • value (Boolean)

    true if the sprite should be flipped vertically, false otherwise.



966
# File 'doc/API_reference.rb', line 966

def flipped_vertically=(value); end

#flipped_x=(value) ⇒ Object

This is alias method of “#flipped_horizontally=”.



960
# File 'doc/API_reference.rb', line 960

def flipped_x=(value); end

#flipped_y=(value) ⇒ Object

This is alias method of “#flipped_vertically=”.



969
# File 'doc/API_reference.rb', line 969

def flipped_y=(value); end

#move_by(delta_location, interval) ⇒ Sprite

Moves the position of the receiver to a new location determined by the sum of the current location and the given delta_location object.

Parameters:

  • delta_location (Point)

    a point that will be added to the receiver’s current location.

  • interval (Float)

    the animation interval.

Returns:



911
# File 'doc/API_reference.rb', line 911

def move_by(delta_location, interval); end

#move_to(location, interval) ⇒ Sprite

Moves the position of the receiver to a new given location.

Parameters:

  • location (Point)

    where the receiver should be moved to.

  • interval (Float)

    the animation interval.

Returns:



917
# File 'doc/API_reference.rb', line 917

def move_to(location, interval); end

#rotate_by(delta_angle, interval) ⇒ Sprite

Rotates the position of the receiver to a new angle determined by the sum of the current rotation and the given delta_angle object.

Parameters:

  • delta_angle (Float)

    the angle to add to the current rotation

  • interval (Float)

    the animation interval.

Returns:



924
# File 'doc/API_reference.rb', line 924

def rotate_by(delta_angle, interval); end

#rotate_to(angle, interval) ⇒ Sprite

Rotates the angle of the receiver to a new angle certain angle by modifying it’s rotation attribute.

Parameters:

  • angle (Float)

    the receiver should be rotated to.

  • interval (Float)

    the animation interval.

Returns:



931
# File 'doc/API_reference.rb', line 931

def rotate_to(angle, interval); end