Back

CreateSprite

JS Py
Hello World
Content:
- Properties
- 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.

Properties

The following properties are available on the Sprite object:

addedBoolean
alphaNumber: fraction (0..1)
angleNumber: fraction (0..1)
aspectNumber
dataObject: { key, value }
groupString
heightNumber: fraction (0..1)
pivotXNumber: fraction (0..1)
pivotYNumber: fraction (0..1)
scaleXNumber: factor
scaleYNumber: factor
visibleBoolean
widthNumber
xNumber: fraction (0..1)
yNumber: fraction (0..1)

Methods

The following methods are available on the Sprite object:

Contains( x, y ) → Boolean
GetFrame() → Number: integer
Goto( frame )
SetSize( w, h )
Stop()
Update()
game object: SpriteSheet
game object: Texture
all types
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, h, sw, sh, rot }
function()
spr.added
Indicates if the sprite has been added to the game
spr.alpha
The objects alpha value
spr.angle
The rotation fraction of the object
spr.aspect
The aspect ratio of the sprite
spr.Contains
Checks if a point is contained in the sprite
spr.data
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
spr.group
The objects group identifier
spr.height
The height of the object
spr.PauseTween
Pause tweening.
spr.pivotX
The x pivot for rotations
spr.pivotY
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.
spr.scaleX
The horizontal scaling
spr.scaleY
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
spr.visible
Indicates the objects visibility state
spr.width
The obects width
spr.x
X-position on the screen.
spr.y
Y-position on the screen.