efficiently handles large tile datasets, useful for backgrounds, terrains, etc... More...
Public Member Functions | |
number | checkCollision (Sprite movingSprite, uint alphaThreshold=128, boolean shortCircuit=true) |
see if a sprite has collided with tiles in a layer More... | |
defineTileSet (int tileWidth, int tileHeight, Image tiles, boolean hasTransparency=true, boolean flipTiles=false) | |
define image and dimensions for the tiles used by this layer More... | |
MemBlock | getMapData (int mapWidth=0, int mapHeight=0, int srcX, int srcY) |
Image | getTileSetImage () |
get the Image currently being used as a tile set More... | |
Point | getTileSize () |
get size of a tile in the image More... | |
object | getTileTypeAndFacingAt (int x, int y) |
get the tile type and the facing/flipped state of the tile More... | |
number | getTileTypeAt (int x, int y) |
get the tile type at a particular spot on the map More... | |
Rect | getWorldBounds () |
get the size in layer coordinates of the world map More... | |
Rect | getWorldSize () |
get the number of tiles in the map More... | |
loadMapData (BinaryString data, int mapWidth=0, int mapHeight=0, int dstX, int dstY) | |
loadMapData (MemBlock data, int mapWidth=0, int mapHeight=0, int dstX, int dstY) | |
setTileTypeAt (int x, int y, uint t, uint facing=facing_Ignore) | |
sets the type of tile at a given location on the map More... | |
setWorldSize (int width, int height, boolean repeatingX=false, boolean repeatingY=false) | |
sets the number of tiles in the world map More... | |
Public Member Functions inherited from SpriteLayer | |
addSprite (Sprite newSprite) | |
add an existing sprite to the layer More... | |
Sprite | createSprite () |
create a sprite that belongs to this layer More... | |
Sprite | createSpriteFromSCML (string inSCML, string inEntityName=null) |
create a single sprite from SCML data More... | |
Sprite | createSpriteFromSCMLEntity (string inEntityName) |
create a sprite from SCML data that was previously loaded More... | |
Sprite | createSpriteFromSCMLFile (string inFileName, string inEntityName=null) |
create a sprite from an SCML data file More... | |
deserialize (Deserializer deserializer) | |
deserialize a sprite layer More... | |
disableCollisions () | |
stop checking for collisions between objects in this layer More... | |
disableCollisionsWithLayer (SpriteLayer otherLayer) | |
remove layer from list of layers that do collisions between layers More... | |
enableCollisions () | |
allow collision checking for sprites in this layer More... | |
enableCollisionsWithLayer (SpriteLayer otherLayer) | |
start collision checking with sprites in another layer More... | |
fadeIn (int msDuration, int easing=linearTween) | |
fade entire layer to full opacity over time More... | |
fadeOut (int msDuration, int easing=linearTween) | |
fade out the entire layer to full transparency over time More... | |
Sprite | findSprite (int id) |
find a sprite in this layer by user assigned id More... | |
number | getMyClassTag () |
returns class tag for SpriteLayer, used for serialization More... | |
Sprite | getNthSprite (int index) |
get a sprite by z-order More... | |
Point | getOrigin () |
get the point in the layer that is drawn at 0,0 in the port More... | |
uint | getSerializedSize (Serializer serializer) |
get the bytes needed to serialize the layer More... | |
CpSpace | getSpace () |
get the Chipmunk Physics CpSpace for the layer More... | |
Port | getSpritePort () |
get the Port the layer renders into More... | |
int | getSpriteZOrder (Sprite sprite) |
get the z-order of a sprite in this layer More... | |
number | getZoom () |
get the current zoom factor More... | |
int | getZOrder () |
get the z-order of this layer compared to all others More... | |
boolean | hasSprite (Sprite sprite) |
see if a particular sprite belongs to this layer More... | |
hide () | |
stop rendering this layer. More... | |
boolean | isHidden () |
true if layer is hidden, false if it is visible More... | |
boolean | isSpriteBehind (Sprite sprite, Sprite otherSprite) |
returns true if sprite will be drawn before otherSprite More... | |
Offset | layerToPortOffset (Offset o) |
adjust the offset to account for layer transformations More... | |
Point | layerToPortPoint (Point p) |
translate the point to account for layer transformations More... | |
Quad | layerToPortQuad (Quad q) |
translate the Quad to account for layer transformations More... | |
RotatedRect | layerToPortRect (Rect r) |
translate the rectangle (or RotatedRect) to account for layer transformations More... | |
Vector | layerToPortVector (Vector v) |
translate the point to account for layer transformations More... | |
moveBehind (SpriteLayer layer) | |
change the z-order of this layer to draw it before the given layer More... | |
moveInFrontOf (SpriteLayer layer) | |
change the z-order of this layer to draw it after the given layer More... | |
moveToBack () | |
move this layer behind all other layers More... | |
moveToFront () | |
move this layer in front of all other layers More... | |
moveWith (SpriteLayer layer, number moveRatio=1.0, number zoomRatio=1.0) | |
link this layer to follow another layer's movements More... | |
IEventHandler | on (int eventCode, function func) |
set event handler for all different sprite and spritelayer events More... | |
IEventHandler | onAnimationComplete (function func) |
set event handler for layer animation complete events More... | |
IEventHandler | onAnimationEnd (function func) |
set event handler for sprite animation end events More... | |
IEventHandler | onAnimationLoop (function func) |
set event handler for sprite animation loop events More... | |
IEventHandler | onAnimationStart (function func) |
set event handler for layer animation complete events More... | |
IEventHandler | onCollideSprite (function func) |
set event handler for sprite-to-sprite collision events More... | |
IEventHandler | onCollideWall (function func) |
set event handler for sprite-wall collision events More... | |
IEventHandler | onDrawPortComplete (function func) |
set event handler for rendering complete events More... | |
IEventHandler | onErasePort (function func) |
set event handler for rendering starting events More... | |
IEventHandler | onExitLayer (function func) |
set event handler for sprite out of bounds event More... | |
IEventHandler | onFadeComplete (function func) |
set event handler for sprite fade event More... | |
IEventHandler | onFadeInComplete (function func) |
set event handler for sprite fade in event More... | |
IEventHandler | onFadeOutComplete (function func) |
set event handler for sprite fade out event More... | |
IEventHandler | onLayerFadeInComplete (function func) |
set event handler for layer fade in event More... | |
IEventHandler | onLayerFadeOutComplete (function func) |
set event handler for layer fade out event More... | |
IEventHandler | onMouseClick (function func) |
set event handler for tap or mouse click in a sprite More... | |
IEventHandler | onMouseDown (function func) |
set event handler for finger down or mouse down in a sprite More... | |
IEventHandler | onMouseEnter (function func) |
set event handler for mouse pointer over a sprite More... | |
IEventHandler | onMouseLeave (function func) |
set event handler for mouse pointer leaving a sprite it was over More... | |
IEventHandler | onMouseUp (function func) |
set event handler for finger up or mouse up in a sprite More... | |
IEventHandler | onOffscreen (function func) |
set event handler for sprite offscreen event More... | |
IEventHandler | onOnscreen (function func) |
set event handler for sprite onscreen event More... | |
IEventHandler | onPostAnimateLayer (function func) |
set event handler for layer animation finished events More... | |
IEventHandler | onPostDrawLayer (function func) |
set event handler for layer rendering complete events More... | |
IEventHandler | onPreAnimateLayer (function func) |
set event handler for layer animation start events More... | |
IEventHandler | onPreDrawLayer (function func) |
set event handler for layer rendering start events More... | |
IEventHandler | onZoomComplete (function func) |
set event handler for this layer finishing zoom animation More... | |
Offset | portToLayerOffset (Offset o) |
adjust the offset to account for layer transformations More... | |
Point | portToLayerPoint (Point p) |
adjust the point to account for layer transformations More... | |
Quad | portToLayerQuad (Quad q) |
adjust the quad to account for layer transformations More... | |
RotatedRect | portToLayerRect (Rect r) |
adjust the rectangle to account for layer transformations More... | |
Vector | portToLayerVector (Vector v) |
adjust the vector to account for layer transformations More... | |
removeAllSprites () | |
remove all sprites in the layer More... | |
removeSprite (Sprite oldSprite) | |
remove a particular sprite from the layer More... | |
serialize (Serializer serializer) | |
serialize the sprite layer and all the sprites in it More... | |
setAutoCenter (boolean autoCenter=true) | |
keep the center of the layer at the center of the port More... | |
setDamping (number damping) | |
set the overall resistance to motion over time (Chipmunk Physics Only) More... | |
setFixedMoveAxis (boolean fixedAxis=true) | |
make movement of the layer relative to the port axis More... | |
setGravity (number gravity, boolean keepItDownward=true) | |
set the force of gravity pulling everything downward (Chipmunk Physics Only) More... | |
setKeepGravityDownward (boolean keepItDownward=true) | |
keep gravity relative to the port when the layer is rotated (Chipmunk Physics Only) More... | |
setOrigin (Point origin) | |
set the point in the layer that is drawn at 0,0 in the port More... | |
SpriteLayer | setSerializationFlags (uint flags) |
set the mode for sprite layer serialization More... | |
setSpritePort (Port port) | |
set the port this layer is rendered into More... | |
setStaticLayer (boolean isStatic=true) | |
make objects in this layer not subject to physics forces (Chipmunk Physics Only) More... | |
setUseChipmunkPhysics (boolean useIt=true) | |
enable or disable use of Chipmunk Physics for a particular layer More... | |
setZoom (number zoomLevel) | |
immediately set the zoom level for this layer More... | |
show () | |
start rendering this layer if it was previously hidden More... | |
startAnimations () | |
restart doing animation calculations for this layer if they were stopped More... | |
stopAnimations () | |
stop doing animation calculations for this layer More... | |
zoom (number deltaZoomLevel, int msDuration, int easing=easeInOutQuad, Rect keepInRect=Rect(0, 0), Point centerOn=Point(0, 0)) | |
animated zoom by a particular factor over time More... | |
zoomTo (number zoomLevel, int msDuration, int easing=easeInOutQuad, Rect keepInRect=Rect(0, 0), Point centerOn=Point(0, 0)) | |
animated zoom to a particular zoom level over time More... | |
Public Member Functions inherited from Animated | |
accelerate (number deltaSpeed, int msDuration=duration_Instantaneous, int easing=linearTween) | |
change the object's speed over time More... | |
accelerateTo (number speed, int msDuration=duration_Instantaneous, int easing=linearTween) | |
change the object's speed to a particular value over time More... | |
addAnimationHelper (IAnimationHelper helper) | |
setup a helper to handle custom animation More... | |
boolean | animate (int msElapsed) |
animate based on the passage of time More... | |
applyForce (Vector force, int msDuration=duration_Instantaneous) | |
apply a force to the object over time More... | |
applyTorque (number forceSpin, int msDuration=duration_Instantaneous) | |
apply torque to the object over time More... | |
changeCenter (Offset offset, int msDuration=duration_Instantaneous, int easing=easeInOutQuad) | |
shift the center point of the object over time More... | |
changeCenterTo (Offset offset, int msDuration=duration_Instantaneous, int easing=easeInOutQuad) | |
shift the center point of the object to a particular offset from true center over time More... | |
clearAnimationHelpers () | |
remove all previously added animation helpers More... | |
Rect | getBoundingBox () |
get the rectangle that completely encloses the object More... | |
Offset | getCenterOffset () |
get the current offset of the center relative to the true center point More... | |
number | getHeight () |
get height of the object More... | |
Point | getLocation () |
get the position of the object More... | |
number | getMass () |
get the mass of the object More... | |
number | getMoveFriction () |
get the amount of friction for movement More... | |
number | getMovementDirectionInRadians () |
get the direction the object is moving More... | |
RotatedRect | getRotatedBounds () |
get the bounds with rotation More... | |
number | getRotation () |
get how much the object is rotated More... | |
number | getSizeFriction () |
get the friction applied to size changes (growing or shrinking) More... | |
number | getSpeed () |
get how fast the object is moving in pixels/sec More... | |
number | getSpin () |
get how fast the object is spinning in radians per second More... | |
number | getSpinFriction () |
get the friction applied toward spinning More... | |
Vector | getVelocity () |
get the vector that expresses magnitude and direction of the object's movement in pixels/sec More... | |
number | getWidth () |
get the width of the object More... | |
grow (number factor, int msDuration=duration_Instantaneous, int easing=easeInOutQuad) | |
change size of the object by a factor over time More... | |
move (Offset delta, int msDuration=duration_Instantaneous, int easing=easeInOutQuad) | |
move the object by a certain amount over time More... | |
moveTo (Point where, int msDuration=duration_Instantaneous, int easing=easeInOutQuad) | |
move the object to a particular location over time More... | |
removeAnimationHelper (IAnimationHelper helper) | |
remove a specific animation helper More... | |
resize (number deltaWidth, number deltaHeight, int msDuration=duration_Instantaneous, int easing=easeInOutQuad) | |
change the size of an object by a given amount over time More... | |
resizeTo (number width, number height, int msDuration=duration_Instantaneous, int easing=easeInOutQuad) | |
resize the object to a specific size over time More... | |
rotate (number radians, int msDuration=duration_Instantaneous, int easing=easeInOutQuad) | |
rotate the object by a specific amount over time More... | |
rotateTo (number radiansRotation, int msDuration=duration_Instantaneous, int easing=easeInOutQuad) | |
rotate the object to face a particular direction over time More... | |
Animated | setCenterOffset (Offset inCenterOffset) |
set the offset of the center point relative to the true center More... | |
Animated | setFriction (number frictionCoefficient) |
set friction for movement, rotation and resizing all at once More... | |
Animated | setHeight (number inHeight) |
set the object's height More... | |
Animated | setLocation (Point inLocation) |
place the object at a particular location More... | |
Animated | setMass (number inMass) |
set the object's mass, used when forces are applied More... | |
Animated | setMoveFriction (number inMoveFriction) |
set the object's friction for movement More... | |
Animated | setRotation (number inRotation) |
set the direction the object is facing in radians More... | |
Animated | setSize (number width, number height) |
set the size of the object More... | |
Animated | setSizeFriction (number inSizeFriction) |
set the friction applied for object resizing More... | |
Animated | setSpeed (number inSpeed) |
set the speed the object is moving in its current direction of motion More... | |
Animated | setSpin (number inSpin) |
set the rate at which the object is spinning, in radians/sec More... | |
Animated | setSpinFriction (number inSpinFriction) |
set the friction the object faces for spinning More... | |
Animated | setVelocity (Vector deltaPerSec) |
set the speed and direction the object is moving More... | |
Animated | setVelocity (number deltaXPerSec, number deltaYPerSec) |
set the speed and direction the object is moving More... | |
Animated | setVelocityInRadians (number speed, number direction) |
set the speed and direction the object is moving More... | |
Animated | setWidth (number inWidth) |
set the width of the object More... | |
startGrowing (number amountPerSecond) | |
set the growth rate of the object in pixels/sec More... | |
startStretching (number widthPerSecond, number heightPerSecond) | |
set the growth rate of the object in pixels/sec, with varied rates for width and height More... | |
stopAllForces () | |
remove all forces that were acting on the object (except friction) More... | |
stopGrowing () | |
stop any size change More... | |
stopMoving () | |
stop any movement the object was doing (except spinning) More... | |
stopSpinning () | |
stop any spinning the object was doing More... | |
stopStretching () | |
stop any stretching the object was doing More... | |
stretch (number widthFactor, number heightFactor, int msDuration=duration_Instantaneous, int easing=easeInOutQuad) | |
change the dimensions of the object over time More... | |
Animated | wait (int msDuration) |
wait before beginning the next animation call that operates over time More... | |
Public Member Functions inherited from EventEmitter | |
addHandler (IEventHandler inHandler, int inEventType=all_events) | |
add a new handler for some event type, or for all events if no type specified. More... | |
blockEvent (int inEventType) | |
temporarily ignore all events of a particular type. More... | |
clear () | |
remove all handlers More... | |
removeHandler (IEventHandler inHandler, int inEventType=all_events) | |
remove a handler for some event type, or for all events (see note) if no type specified. More... | |
unblockEvent (int inEventType) | |
stop ignoring events of a particular type More... | |
Additional Inherited Members | |
Related Functions inherited from SpriteLayer | |
cleanupSpriteLayer | |
free all the memory used by a SpriteLayer More... | |
createSpriteLayer | |
create a new SpriteLayer attached to a particular port More... | |
createSpriteLayerFromSCMLFile | |
create a new SpriteLayer from an Spriter SCML file More... | |
Related Functions inherited from ISerializable | |
registerSerializableClass | |
register a particular class as implementing ISerializable interface More... | |
efficiently handles large tile datasets, useful for backgrounds, terrains, etc...
Each TileLayer has a tile set, a set of equal size tiles taken from a single image. There can be at most 256 tiles in an image.
Tile sets can contain transparency, either through a transparent color or via an alpha channel. If a tile set does not contain transparency, then the entire tile world will be filled in solid, there is no way to leave out a tile. In tile sets with transparency, tile type 0 is considered empty, even if the there is no transparency in the actual image.
Tile sets can support tile rotation (facing) or tile flipping (vertical, horizontal, or both). You cannot use both rotation and flipping in the same layer.
For truly impressive maps, you will rarely use just a single TileLayer. Because TileLayers are highly optimized for large areas of transparent/empty tiles, you can use a number of linked TileLayers that each focus on different details: water, terrain, ground cover, flowers and shrubs, trees, etc...
You can intersperse regular SpriteLayers in between TileLayers to provided animated effects to make your characters move at the right layer (underneath the tree-tops, for example).
Be sure to link together all your layers using SpriteLayer.moveWith().
checkCollision | ( | Sprite | movingSprite, |
uint | alphaThreshold = 128 , |
||
boolean | shortCircuit = true |
||
) |
see if a sprite has collided with tiles in a layer
defineTileSet | ( | int | tileWidth, |
int | tileHeight, | ||
Image | tiles, | ||
boolean | hasTransparency = true , |
||
boolean | flipTiles = false |
||
) |
define image and dimensions for the tiles used by this layer
Each TileLayer has a set of equal size tiles taken from a single image. The tileWidth and tileHeight specify the size of each individual tile in the image, and the image should divide evenly into tiles with no left-over space. There can be at most 256 tiles in an image.
Tile sets can contain transparency, either through a transparent color or via an alpha channel (See Image for more details on transparency).
Tile sets can support tile rotation (facing) or tile flipping (vertical, horizontal, or both). You cannot use both rotation and flipping in the same layer.
To support rotation, you must have a maximum of 64 tiles in your tile set. Typically the tiles would be arranged in an 8x8 grid, with the top left corner tile being considered tile 0 and then counting left to right, top to bottom.
To support flipping in both directions, your tile set should be laid out just like for rotation, 64 tiles in an 8x8 grid. For horizontal flipping only, you should have 128 tiles in an 8x16 grid, and for vertical flipping only you should have 128 tile in a 16x8 grid. For all kinds of flipping you must pass true for the flipTiles parameter when you call defineTileSet().
MemBlock getMapData | ( | int | mapWidth = 0 , |
int | mapHeight = 0 , |
||
int | srcX, | ||
int | srcY | ||
) |
getTileSetImage | ( | ) |
get the Image currently being used as a tile set
getTileSize | ( | ) |
get size of a tile in the image
getTileTypeAndFacingAt | ( | int | x, |
int | y | ||
) |
get the tile type and the facing/flipped state of the tile
x | component of x,y coordinates on the map |
y | component of x,y coordinates on the map |
> console.log(myTileLayer.getTileTypeAndFacingAt(0,0); { tileType: 61, facing: 128 }
getTileTypeAt | ( | int | x, |
int | y | ||
) |
get the tile type at a particular spot on the map
x | component of x,y coordinates on the map |
y | component of x,y coordinates on the map |
getWorldBounds | ( | ) |
get the size in layer coordinates of the world map
getWorldSize | ( | ) |
get the number of tiles in the map
loadMapData | ( | BinaryString | data, |
int | mapWidth = 0 , |
||
int | mapHeight = 0 , |
||
int | dstX, | ||
int | dstY | ||
) |
loadMapData | ( | MemBlock | data, |
int | mapWidth = 0 , |
||
int | mapHeight = 0 , |
||
int | dstX, | ||
int | dstY | ||
) |
setTileTypeAt | ( | int | x, |
int | y, | ||
uint | t, | ||
uint | facing = facing_Ignore |
||
) |
sets the type of tile at a given location on the map
x | the horizontal tile position on the map (not pixels) |
y | the vertical tile position on the map (not pixels) |
t | the type of tile (the tile index in the tile set image) |
facing | the rotation (or flipping) to use for this tile, defaults to none, ignored on layers that aren't using facing or flipping |
setWorldSize | ( | int | width, |
int | height, | ||
boolean | repeatingX = false , |
||
boolean | repeatingY = false |
||
) |
sets the number of tiles in the world map
width | how many tiles wide the world should be |
height | how many tiles high the world should be |
repeatingX | true if the map should wrap around horizontally to appear infinite, defaults to false |
repeatingY | true if the map should wrap around vertically to appear infinite, defaults to false |