Class: MG::Sprite
Instance Attribute Summary collapse
-
#category_mask ⇒ Integer
Physics category mask.
-
#collision_mask ⇒ Integer
Physics collision mask.
-
#contact_mask ⇒ Integer
Physics contact test mask.
-
#friction ⇒ Float
The linear damping / air friction force on the sprite body.
-
#inertia_moment ⇒ Float
The moment of inertia of the body.
-
#mass ⇒ Float
The body mass of the sprite.
-
#velocity ⇒ Point
The velocity force on the sprite body.
Attributes inherited from Node
#alpha, #anchor_point, #color, #name, #position, #rotation, #scale, #size, #z_index
Spritesheets collapse
-
.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.
Constructors collapse
-
#initialize(sprite_name) ⇒ Sprite
constructor
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 Sprite.load.
Actions collapse
-
#animate(frame_names, delay, loops = 1) { ... } ⇒ self
Starts an animation where the sprite display frame will be changed to the given frames in
sprite_frames_names
based on the givendelay
and repeatedloops
times. -
#blink(number_of_blinks, interval) { ... } ⇒ self
Blinks the receiver.
-
#flipped_horizontally=(value) ⇒ Object
Sets whether the sprite should be flipped horizontally or not.
-
#flipped_vertically=(value) ⇒ Object
Sets whether the sprite should be flipped vertically or not.
-
#flipped_x=(value) ⇒ Object
This is alias method of #flipped_horizontally=.
-
#flipped_y=(value) ⇒ Object
This is alias method of #flipped_vertically=.
-
#move_by(delta_location, interval) { ... } ⇒ self
Moves the position of the receiver to a new location determined by the sum of the current location and the given
delta_location
object. -
#move_to(location, interval) { ... } ⇒ self
Moves the position of the receiver to a new given location.
-
#rotate_by(delta_angle, interval) { ... } ⇒ self
Rotates the position of the receiver to a new angle determined by the sum of the current rotation and the given
delta_angle
object. -
#rotate_to(angle, interval) { ... } ⇒ self
Rotates the angle of the receiver to a new angle certain angle by modifying it’s rotation attribute.
Physics collapse
-
#apply_force(force) ⇒ self
Applies an immediate force to the sprite body.
-
#apply_impulse(force) ⇒ self
Applies a continuous force to the sprite body.
-
#attach_physics_box(size = nil) ⇒ self
Attaches a physics body with a box shape to the sprite.
Instance Method Summary collapse
-
#dynamic=(value) ⇒ Object
Set dynamic to body.
-
#dynamic? ⇒ Boolean
Whether the sprite body should be dynamic or not in the physics world.
-
#gravitates=(value) ⇒ Object
Set the body is affected by the physics world’s gravitational force or not.
-
#gravitates? ⇒ Boolean
Whether the sprite should be affected by the scene’s gravitational force.
-
#resting=(value) ⇒ Object
Set body to rest.
-
#resting? ⇒ Boolean
Whether the body is at rest.
Methods inherited from Node
#add, #children, #clear, #delete, #delete_from_parent, #intersects?, #number_of_running_actions, #parent, #run_action, #schedule, #schedule_once, #stop_action, #stop_all_actions, #unschedule, #visible=, #visible?
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.
951 |
# File 'doc/API_reference.rb', line 951 def initialize(sprite_name); end |
Instance Attribute Details
#category_mask ⇒ Integer
Returns physics category mask.
1087 1088 1089 |
# File 'doc/API_reference.rb', line 1087 def category_mask @category_mask end |
#collision_mask ⇒ Integer
Returns physics collision mask.
1093 1094 1095 |
# File 'doc/API_reference.rb', line 1093 def collision_mask @collision_mask end |
#contact_mask ⇒ Integer
Returns physics contact test mask.
1090 1091 1092 |
# File 'doc/API_reference.rb', line 1090 def contact_mask @contact_mask end |
#friction ⇒ Float
Returns the linear damping / air friction force on the sprite body.
1071 1072 1073 |
# File 'doc/API_reference.rb', line 1071 def friction @friction end |
#inertia_moment ⇒ Float
Returns the moment of inertia of the body.
1084 1085 1086 |
# File 'doc/API_reference.rb', line 1084 def inertia_moment @inertia_moment end |
#mass ⇒ Float
Returns the body mass of the sprite.
1051 1052 1053 |
# File 'doc/API_reference.rb', line 1051 def mass @mass end |
#velocity ⇒ Point
Returns the velocity force on the sprite body.
1074 1075 1076 |
# File 'doc/API_reference.rb', line 1074 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.
941 |
# File 'doc/API_reference.rb', line 941 def self.load(file_name); end |
Instance Method Details
#animate(frame_names, delay, loops = 1) { ... } ⇒ self
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.
1008 |
# File 'doc/API_reference.rb', line 1008 def animate(frame_names, delay, loops=1); end |
#apply_force(force) ⇒ self
Applies an immediate force to the sprite body.
1045 |
# File 'doc/API_reference.rb', line 1045 def apply_force(force); end |
#apply_impulse(force) ⇒ self
Applies a continuous force to the sprite body.
1040 |
# File 'doc/API_reference.rb', line 1040 def apply_impulse(force); end |
#attach_physics_box(size = nil) ⇒ self
Attaches a physics body with a box shape to the sprite.
1035 |
# File 'doc/API_reference.rb', line 1035 def attach_physics_box(size=nil); end |
#blink(number_of_blinks, interval) { ... } ⇒ self
Blinks the receiver.
994 |
# File 'doc/API_reference.rb', line 994 def blink(number_of_blinks, interval); end |
#dynamic=(value) ⇒ Object
Set dynamic to body.
1068 |
# File 'doc/API_reference.rb', line 1068 def dynamic=(value); 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.
1064 |
# File 'doc/API_reference.rb', line 1064 def dynamic?; 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.
1014 |
# File 'doc/API_reference.rb', line 1014 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.
1023 |
# File 'doc/API_reference.rb', line 1023 def flipped_vertically=(value); end |
#flipped_x=(value) ⇒ Object
This is alias method of #flipped_horizontally=.
1017 |
# File 'doc/API_reference.rb', line 1017 def flipped_x=(value); end |
#flipped_y=(value) ⇒ Object
This is alias method of #flipped_vertically=.
1026 |
# File 'doc/API_reference.rb', line 1026 def flipped_y=(value); end |
#gravitates=(value) ⇒ Object
Set the body is affected by the physics world’s gravitational force or not.
1059 |
# File 'doc/API_reference.rb', line 1059 def gravitates=(value); end |
#gravitates? ⇒ Boolean
Returns whether the sprite should be affected by the scene’s gravitational force. The default is true
.
1055 |
# File 'doc/API_reference.rb', line 1055 def gravitates?; end |
#move_by(delta_location, interval) { ... } ⇒ self
Moves the position of the receiver to a new location determined by the sum of the current location and the given delta_location
object.
963 |
# File 'doc/API_reference.rb', line 963 def move_by(delta_location, interval); end |
#move_to(location, interval) { ... } ⇒ self
Moves the position of the receiver to a new given location.
970 |
# File 'doc/API_reference.rb', line 970 def move_to(location, interval); end |
#resting=(value) ⇒ Object
Set body to rest
1081 |
# File 'doc/API_reference.rb', line 1081 def resting=(value); end |
#resting? ⇒ Boolean
Returns whether the body is at rest.
1077 |
# File 'doc/API_reference.rb', line 1077 def resting?; end |
#rotate_by(delta_angle, interval) { ... } ⇒ self
Rotates the position of the receiver to a new angle determined by the sum of the current rotation and the given delta_angle
object.
978 |
# File 'doc/API_reference.rb', line 978 def rotate_by(delta_angle, interval); end |
#rotate_to(angle, interval) { ... } ⇒ self
Rotates the angle of the receiver to a new angle certain angle by modifying it’s rotation attribute.
986 |
# File 'doc/API_reference.rb', line 986 def rotate_to(angle, interval); end |