API Docs for: 0.1.0
Show:

CG.Sprite Class

Extends CG.Entity
Module: CG

CG.Sprite this is the basic object to get a image to the canvas. It must be added to a layer where update/draw of every object is called automatically. Otherwise it can be used stand alone in the Game object itself in the update and draw methods.


                        // new sprite with image from filepath
                        var s = new CG.Sprite({
                          image: '../images/demo.png',
                          position: new CG.Point(200,200)
                        })
                        
                        // new sprite with preloaded image from Game.asset
                        var s = new CG.Sprite({
                          image: Game.asset.getImageByName('player'),
                          position: new CG.Point(200,200)
                        })
                        

Methods

AABB

() Object

returns the bounds of rotated rectangle

Returns:

Object:

returns the calculated bounds

attachObject

()

attach a reference of the given object to this object

checkBound

()

Checks the bound if a boundMode (bounce or slide) is set

checkCollision

(
  • objects
  • callback
)

checks if there is a collision of the given objects to this object http://devmag.org.za/2009/04/13/basic-collision-detection-in-2d-part-1/

Parameters:

  • objects Array

    a array of objects to check for collision => Sprites, Animations, MapAreas

  • callback Callback

    what to do after collision?

follow

()

is there an attached element, this sprite will follow it depending on followspeed or followsteps it follows different

ifAttached

()

if there is a attached object get its position

ifClicked

() True/false

checks click inside of the rectangle, supports rotation

Returns:

True/false:

ifMouseOver

()

checks if the mouse/pointer is over the rectangle

init

(
  • options
)

Inherited from CG.Entity but overwritten in cangaja/sprite/sprite.js:30

Opions: image {string} imgpath, image object or atlasimage object to use position: {CG.Point}

Parameters:

Returns:

:

removeAttachedObject

()

removes the attached object reference

setAttachedOffsetX

()

set the x offset of the attached object to this object

setAttachedOffsetY

()

set the y offset of the attached object to this object

setBound

(
  • bound
)

set the bound of the sprite

Parameters:

setImage

(
  • image
)

initialize image for object. for now => sprite, particle, buffer, bitmap and button use it

Parameters:

  • image Image

    image path, image or atlasimage

updateDiff

()

calculate offset if bound is moving

Properties

alpha

Float

attachedobject

Boolean

boundingradius

Number

boundsMode

False/string

clicked

Boolean

diffpoint

CG.Point

dragable

Boolean

followobject

Boolean/object

followspeed

Boolean/integer

followsteps

Boolean/integer

height

Number

mapcollision

Boolean

offsetx

Number

offsety

Number

rotation

Number

rotationspeed

Integer/float

transform

Transform

Transform object for matrix transformation

visible

Boolean

visibility option

xhandle

Number

xscale

Number

yhandle

Number

yscale

Number