Class: MG::Sprite
Properties (collapse)
-
- (Integer) category_mask
Physics category mask.
-
- (Integer) collision_mask
Physics collision mask.
-
- (Integer) contact_mask
Physics contact test mask.
-
- (Boolean) dynamic?
Whether the sprite body should be dynamic or not in the physics world.
-
- (Float) friction
The linear damping / air friction force on the sprite body.
-
- (Boolean) gravitates?
Whether the sprite should be affected by the scene's gravitational force.
-
- (Float) inertia_moment
The moment of inertia of the body.
-
- (Float) mass
The body mass of the sprite.
-
- (Boolean) resting?
Whether the body is at rest.
-
- (Point) velocity
The velocity force on the sprite body.
Attributes inherited from Node
#alpha, #anchor_point, #color, #name, #position, #rotation, #scale, #size, #visible?, #z_index
Spritesheets (collapse)
-
+ (nil) load(file_name)
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)
-
- (Sprite) initialize(sprite_name)
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)
-
- (Sprite) animate(frame_names, delay, loops = 1)
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. -
- (Sprite) blink(number_of_blinks, interval)
Blinks the receiver.
-
- (Sprite) move_by(delta_location, interval)
Moves the position of the receiver to a new location determined by the sum of the current location and the given
delta_location
object. -
- (Sprite) move_to(location, interval)
Moves the position of the receiver to a new given location.
Physics (collapse)
-
- (Sprite) apply_force(force)
Applies an immediate force to the sprite body.
-
- (Sprite) apply_impulse(force)
Applies a continuous force to the sprite body.
-
- (Sprite) attach_physics_box(size = nil)
Attaches a physics body with a box shape to the sprite.
Methods inherited from Node
#add, #children, #clear, #delete, #delete_from_parent, #intersects?, #parent
Constructor Details
- (Sprite) initialize(sprite_name)
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.
454 |
# File 'motion-game', line 454 def initialize(sprite_name); end |
Instance Attribute Details
- (Integer) category_mask
Returns physics category mask.
540 541 542 |
# File 'motion-game', line 540 def category_mask @category_mask end |
- (Integer) collision_mask
Returns physics collision mask.
546 547 548 |
# File 'motion-game', line 546 def collision_mask @collision_mask end |
- (Integer) contact_mask
Returns physics contact test mask.
543 544 545 |
# File 'motion-game', line 543 def contact_mask @contact_mask end |
- (Boolean) dynamic?
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.
525 526 527 |
# File 'motion-game', line 525
def dynamic?
@dynamic?
end
|
- (Float) friction
Returns the linear damping / air friction force on the sprite body.
528 529 530 |
# File 'motion-game', line 528 def friction @friction end |
- (Boolean) gravitates?
Returns whether the sprite should be affected by the scene's
gravitational force. The default is true
.
520 521 522 |
# File 'motion-game', line 520
def gravitates?
@gravitates?
end
|
- (Float) inertia_moment
Returns the moment of inertia of the body.
537 538 539 |
# File 'motion-game', line 537 def inertia_moment @inertia_moment end |
- (Float) mass
Returns the body mass of the sprite.
516 517 518 |
# File 'motion-game', line 516 def mass @mass end |
- (Boolean) resting?
Returns whether the body is at rest.
534 535 536 |
# File 'motion-game', line 534
def resting?
@resting?
end
|
- (Point) velocity
Returns the velocity force on the sprite body.
531 532 533 |
# File 'motion-game', line 531 def velocity @velocity end |
Class Method Details
+ (nil) load(file_name)
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.
444 |
# File 'motion-game', line 444 def self.load(file_name); end |
Instance Method Details
- (Sprite) animate(frame_names, delay, loops = 1)
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.
491 |
# File 'motion-game', line 491 def animate(frame_names, delay, loops=1); end |
- (Sprite) apply_force(force)
Applies an immediate force to the sprite body.
510 |
# File 'motion-game', line 510 def apply_force(force); end |
- (Sprite) apply_impulse(force)
Applies a continuous force to the sprite body.
505 |
# File 'motion-game', line 505 def apply_impulse(force); end |
- (Sprite) attach_physics_box(size = nil)
Attaches a physics body with a box shape to the sprite.
500 |
# File 'motion-game', line 500 def attach_physics_box(size=nil); end |
- (Sprite) blink(number_of_blinks, interval)
Blinks the receiver.
478 |
# File 'motion-game', line 478 def blink(number_of_blinks, interval); end |
- (Sprite) move_by(delta_location, interval)
Moves the position of the receiver to a new location determined by the sum
of the current location and the given delta_location
object.
465 |
# File 'motion-game', line 465 def move_by(delta_location, interval); end |
- (Sprite) move_to(location, interval)
Moves the position of the receiver to a new given location.
471 |
# File 'motion-game', line 471 def move_to(location, interval); end |