FLAG 3.0 GET

Sprite

Sprites are simply objects that display frames of animation. However, many of the same actions of Actors and Bodies can be applied to Sprites. The essential difference is that Sprites are not effected by Box2D physics simulations and currently have no collision detection.

Every Sprite has a decals list. Additional Sprites can be loaded into the decals list to augment the base Sprite, think of them as stickers. Decals inherit all the same behaviors as a full blown Sprites.

Sprites also have a gui setting which, when set to true, anchors it's position relative to the screen and not to the Scene's Map. This allows you to use Sprites as static GUI elements that are rendered inside the Canvas. Sprites are created in POLE. All other actions, including adding to the decals list, are done using FLAG and WIND.

Class

FLAGSPRITE

Called by FLAG.Sprite

FLAG.Sprite( instanceName:String ); Parameters instanceName:String --- The name of a Sprite instance in the Scene Example
FLAG.Sprite("mySprite");
Extend Class Example
FLAGSPRITE.prototype.myFunction = function(){
console.log("I added to the FLAGSPRITE Class");
};

Properties

alpha:Number --- Alpha of the Sprite animation:Number --- Index of Sprite animation decals:Array --- A list of additional Sprites draw:Boolean --- True if the Sprite is rendered frame:Number --- Frame number of the Sprite that is being rendered front:Boolean --- If the Sprite is in a decals list, true renders it in front of the main Sprite gui:Boolean --- True if the Sprite anchors it's position to the screen layer:Number --- Layer the Sprite is being rendered on loop:Boolean --- Should the Sprite's animation loop loopCount:Number --- How many animation loops before stopping, null if infinite loops:Number --- A counter for how many loops have occured name:String --- Name of the Sprite instance in the Scene pIndex:Number --- Index of the Sprite created in POLE playing:Boolean --- True if the Sprite's animation is playing showHitBox:Boolean --- True draws an outline of the Sprite's clickable area tileNext:Object --- Once a TilePath has been assigned, this is the next tile on the path
row:Number --- Row of tile col:Number --- Column of tile
tileOn:Object --- The tile the Sprite is on
row:Number --- Row of tile col:Number --- Column of tile
x:Number --- Horizontal pixel location y:Number --- Vertical pixel location update:Function --- Optional method to run each tick of the game loop

Methods

Add Decal

Adds a Sprite to the decals list of the Sprite.

FLAG.Sprite("mySprite").addDecal( parameters:Object ); Parameters parameters:Object --- An object with parameters
decal:String --- Name of Sprite created in POLE Optional Parameters decalName:String --- Instance name for decal Sprite x:Number --- Horizontal location relative to the main Sprite y:Number --- Vertical location relative to the main Sprite playing:Boolean --- Toggle cycling of decal Sprite frames alpha:Number --- Alpha of decal Sprite front:Boolean --- Toggle if decal Sprite is rendered in front of the main Sprite
Example
FLAG.Sprite("mySprite").addDecal({decal:"TheDecal",decalName:"myDecal"});

Camera Follow

Keeps the Sprite in the center of the screen.

FLAG.Sprite("mySprite").cameraFollow(); Example
FLAG.Sprite("mySprite").cameraFollow();

Clicked

Returns true if the Pointer is with in the bounds of the Sprite when clicked.

FLAG.Sprite("mySprite").clicked( ); Example
FLAG.Scene.mouseDown(e){
console.log(FLAG.Sprite("mySprite").clicked());
};

Clicked Decal

Returns true if the Pointer is with in the bounds of a Sprite, in the Sprite's decals list, when clicked.

FLAG.Sprite("mySprite").clicked( decal:String ); Parameters decal:String --- Instance name of Sprite in decals list Example
FLAG.Scene.mouseDown(e){
console.log(FLAG.Sprite("mySprite").clickedDecal("myDecal"));
};

Decal

Returns a Sprite from the Sprite's decals list.

FLAG.Sprite("mySprite").Decal( instanceName:String ); Parameters instanceName:String --- Instance name of Sprite in decals list Example
FLAG.Sprite("mySprite").Decal("myDecal");

Drag

Keeps the Sprite under the Pointer.

FLAG.Sprite("mySprite").drag( ); Example
FLAG.Scene.mouseMove(e){
FLAG.Sprite("mySprite").drag();
};

Get Animation

Returns an object containing animation information for the Sprite.

FLAG.Sprite("mySprite").getAnimation( ); Example
console.log(FLAG.Sprite("mySprite").getAnimation().name);

Isometric Move

Moves the Sprite, using the arrow keys, along the isometric axis.

FLAG.Sprite("mySprite").isometricMove( speed:Number ); Parameters speed:Number --- The speed of travel Example
FLAG.Scene.update(){
FLAG.Sprite("mySprite").isometricMove(5);
};

Linear Move

Moves the Sprite, using the arrow keys, along the linear axis.

FLAG.Sprite("mySprite").linearMove( speed:Number ); Parameters speed:Number --- The speed of travel Example
FLAG.Scene.update(){
FLAG.Sprite("mySprite").linearMove(5);
};

Play

Sets the Sprite's animation to play.

FLAG.Sprite("mySprite").play( );

Remove Decal

Removes a Sprite from the decals list of the Sprite.

FLAG.Sprite("mySprite").removeDecal( decal:String ); Parameters decal:String --- Instance name of a Sprite in a decals list Example
FLAG.Scene.mouseDown(e){
FLAG.Sprite("mySprite").removeDecal("myDecal");
};

Set Animation

Sets the animation of the Sprite.

FLAG.Sprite("mySprite").setAnimation( animation:String || Number ); Parameters animation:String || Number --- Name or index of animation for Sprite Example
FLAG.Sprite("mySprite").setAnimation("Walk");

Set Frame

Sets the frame of the Sprite.

FLAG.Sprite("mySprite").setFrame( frame:String || Number ); Parameters frame:String || Number --- "startFrame" or "endFrame" or number of frame for Sprite Example
FLAG.Sprite("mySprite").setFrame(0);

Stop

Sets the Sprite's animation to stop.

FLAG.Sprite("mySprite").stop( );

Tile Path

Calculates a tile path using walkable tiles and an A-Star algorithm to move the Sprite to a target tile.

FLAG.Sprite("mySprite").tilePath( parameters:Object ); Parameters parameters:Object --- Tile Path parameters
row:Number --- Row of target tile col:Number --- Column of target tile timeStep:Number --- Speed of the move diagonals:Boolean --- True if using diagonals, default is false
Example
FLAG.Scene.mouseDown(e){
FLAG.Sprite("mySprite").tilePath({row:0,col:0,timeStep:3});
};

To Tile

Sets the pixel position of the Sprite to a tile.

FLAG.Sprite("mySprite").toTile( parameters:Object ); Parameters parameters:Object --- Tile parameters
row:Number --- Row of target tile col:Number --- Column of target tile
Example
FLAG.Sprite("mySprite").toTile({row:0,col:0});

Travel Tile Path

Called by FLAG.update. Uses the Tile Path to move the Sprite along the path.

FLAG.Sprite("mySprite").travelTilePath( );

Tween Alpha

Uses FLAG.Tween to change the alpha, over time, of the Sprite.

FLAG.Sprite("mySprite").tweenAlpha( parameters:Object ); Parameters parameters:Object --- Tween Alpha parameters
alpha:Number --- Target alpha duration:Number --- Number of seconds for change ease:Function --- Which easing method onComplete:Function --- Function to run when Tween is complete
Example
FLAG.Sprite("mySprite").tweenAlpha({alpha:.25,duration:3});

Tween Position

Uses FLAG.Tween to change the position, over time, of the Sprite.

FLAG.Sprite("mySprite").tweenPosition( parameters:Object ); Parameters parameters:Object --- Tween Alpha parameters
x:Number --- Target x location y:Number --- Target y location duration:Number --- Number of seconds for change ease:Function --- Which easing method onComplete:Function --- Function to run when Tween is complete
Example
FLAG.Sprite("mySprite").tweenPosition({x:100,duration:3,ease:FLAG.easeInBack});

Tween to Tile

Uses FLAG.Tween to change the position, over time, of the Sprite to a tile.

FLAG.Sprite("mySprite").tweenToTile( parameters:Object ); Parameters parameters:Object --- Tween Alpha parameters
row:Number --- Row of target tile col:Number --- Column of target tile duration:Number --- Number of seconds for change ease:Function --- Which easing method onComplete:Function --- Function to run when Tween is complete
Example
FLAG.Sprite("mySprite").tweenToTile({row:2,col:2,duration:3,ease:FLAG.easeInBack});
POLE WIND