Back

CreateSprite

Hello World
Content:
- Methods

Creates a sprite object based on an image file containing a sprite or a spritesheet.

spr = gfx.CreateSprite( file, group, callback ) → game object: CreateSprite

To create a new Sprite just pass the image name as first parameter:

gfx.CreateSprite( "/Sys/Img/Bunny.png", "bunnies" );

Spritesheets can be loaded in two ways:

The simple one is a specific file pattern
“Img/Sheetname_WIDTHxHEIGHTxSPRITE_SXxSPRITE_SY or
“Img/Sheetname_stripTOTAL_WIDTHxHEIGHTxSPRITE_SXxSPRITE_SY
if you have a different amount of sprites than the rectangle of spritesx * spritesy sprites.

Example from the downloadable demo Grannies and Zombies:

granny = gfx.CreateSprite( "Img/Granny_1600x1000x8x5", "granny" );
zombie = gfx.CreateSprite( "Img/Zombie_strip35_1400x1000x7x5", "zombie" );

The second way is to create a SpriteSheet using the CreateSpriteSheet method which might come handy if a single sprite has multiple animations or if a sprite is reused but using a different sprite sheet.

Methods

The following methods are available on the Sprite object:

addedBoolean
alphaNumber: fraction (0..1)
angleNumber: fraction (0..1)
aspectNumber
Contains( x, y ) → Boolean
dataObject
GetFrame() → Number: integer
Goto( frame )
groupString
heightNumber: fraction (0..1)
pivotXNumber: fraction (0..1)
pivotYNumber: fraction (0..1)
scaleXNumber: factor
scaleYNumber: factor
SetSize( w, h )
Stop()
Update()
visibleBoolean
widthNumber
xNumber
yNumber: fraction (0..1)
game object: SpriteSheet
game object: Texture
Boolean
Number
String
Number: fraction (0..1)
Number: integer
Number: milliseconds
String: path to file ( “/absolute/...” or “relative/...” )
String: “Linear.None” or “Quadratic.In/Out” or “Cubic.In/Out” or “Quartic.In/Out” or “Quintic.In/Out” or “Sinusoidal.In/Out” or “Exponential.In/Out” or “Circular.In/Out” or “Elastic.In/Out” or “Back.In/Out” or “Bounce.In/Out”
Object: Matrix
Object: { x, y, w, w, sw, sh, rot }
function()
Indicates if the sprite has been added to the game
The objects alpha value
The rotation fraction of the object
The aspect ratio of the sprite
spr.Contains
Checks if a point is contained in the sprite
An object for saving individual extra properties.
spr.Flip
Flips the sprite on the horizontal and/or the vertical axis.
spr.GetFrame
Returns the current frame
spr.Goto
Displays a specific frame of an animation
The objects group identifier
The height of the object
spr.PauseTween
Pause tweening.
The x pivot for rotations
The y pivot for rotations
spr.Play
Start playing the sprite animation
spr.PlayRange
Start playing the sprite animation in a given frame range
spr.PlayTo
Play the animation until a specific frame is reached
spr.PlayTween
Resume tweening.
The horizontal scaling
The vertical scaling
spr.SetLoop
Define if the animation should loop or stop at the end
spr.SetMatrix
Set the individual 2d transformation
spr.SetPlaySpeed
Define at which speed the animation will play. 1 equals to 60 fps
spr.SetRange
Define the frame range the animation should show.
spr.SetSize
Set the sprite size on the screen
spr.SetSpriteSheet
Change the animation to another.
spr.SetTexture
Change the sprite texture to another.
spr.SetTween
Sets up tween methods and properties without playing it.
spr.StartTween
Start tweening automatically on every rendered frame.
spr.StepTween
Updates a tween to the current time (if not paused).
spr.Stop
Stop playin the animation.
spr.StopAt
Causes the animation to stop playing at a specific frame
spr.Tween
Performs an animation on the control.
The target object is for the position, size and rotation that the control has at the end of the animation.

The type specifies the behavior and the speed of the animation. Separated by a dot, you must also specify whether you want to apply this behavior to the beginning (In), end (Out), or to both (InOut) times of the animation.

With the amount of repeats you can control how many times you want to play the animation.

If you have jojo activated, the animation will alternate between forward and backward playback, so that if the repetition value is odd, the control will be at the start position again at the end of the animation.

Finally the callback function will be called after the animation has finished. Well, it's about time!
spr.Update
Updates internal properties
Indicates the objects visibility state
The obects width
X-position on the screen.
Y-position on the screen.