API Docs for: 0.1.0
Show:

CG.B2DPolygon Class

Extends CG.B2DEntity
Module: CG

B2DPolygon is a simple b2PolygonShape wrapper element with basic physics properties. It uses PhysicsEditor json files, use export Lime + Corona (json). Supported options for now are friction, density and bounce and would be set to B2DPolygon.


                        var e = new CG.B2DPolygon({
                           name: 'player',
                           image: this.asset.getImageByName('glowball'),
                           texturepacker: this.asset.getJsonByName('powerstar75'),
                           x: 100,
                           y: 100,
                           world: b2world,
                           scale: 40,
                           bodyType: box2d.b2BodyType.b2_staticBody,
                           bullet: false
                        })
                        

Methods

AABB

() Object

returns the bounds of rotated rectangle

Returns:

Object:

returns the calculated bounds

addVelocity

(
  • b2Vec2
)

Parameters:

applyImpulse

(
  • degrees
  • power
)

Parameters:

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?

getPolysFromBitmapTrace

(
  • image
)
Array

use the CG.Bitmap traceContour method to get the shape of an bitmap. The result are 'only' triangulated polygons. Better results with concave polygons are calculated with Physicseditor, see getPolysFromJson.

Parameters:

Returns:

Example:

// example code from demo-bitmap-contour.js
                                            bitmap = new CG.Bitmap(Game.width, Game.height)
                                            bitmap.loadImage(Game.asset.getImageByName('star-contour-test'))
                                            var contour = bitmap.traceContour()
                                            var lightedContour = bitmap.lightenCountur(contour)
                                            var triangulatedContour = bitmap.triangulateContour(lightedContour)
                                            

getPolysFromJson

() Array

extract the polygons out of the PhysicsEditor json file and collect them into an array

Physicseditor json example

Returns:

Example:

{
                                            
                                                "ballon": [
                                            
                                                        {
                                                            "density": 0.05, "friction": 0.5, "bounce": 0,
                                                            "filter": { "categoryBits": 1, "maskBits": 65535 },
                                                            "shape": [   98.5, 210  ,  98.5, 212  ,  92, 215.5  ,  82.5, 205  ,  91.5, 206  ,  97, 207.5  ]
                                                        }  ,
                                                        {
                                                            "density": 0.05, "friction": 0.5, "bounce": 0,
                                                            "filter": { "categoryBits": 1, "maskBits": 65535 },
                                                            "shape": [   81.5, 213  ,  82.5, 205  ,  92, 215.5  ,  83, 215.5  ]
                                                        }  ,
                                            

getPosition

()

hit

(
  • impulse
  • source
)

Parameters:

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/box2d/b2d-polygon.js:31

Options: name {string} image {mixed} texturepacker {string} x {number} y (number} world {object} scale {number} bodyType {box2d.b2BodyType} bullet {boolean}

Parameters:

Returns:

:

makeVecsCentroid

(
  • vecs
)

The origin of the vertices from physicseditor is top/left. This method makes the vecs centroid (centered origin) depending on image size.

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

setPosition

(
  • b2Vec2
)

Parameters:

setType

(
  • b2BodyType
)

Parameters:

Properties

body

B2Body

Inherited from CG.B2DEntity but overwritten in cangaja/box2d/b2d-polygon.js:102

bodyDef

B2BodyDef

bodyDef.alowSleep

Boolean

bodyDef.angle

Number

bodyDef.awake

Boolean

bodyDef.bullet

Inherited from CG.B2DEntity but overwritten in cangaja/box2d/b2d-polygon.js:96

bodyDef.fixedRotation

Boolean

bodyDef.position

Unknown

bodyDef.type

box2d.b2BodyType.b2_staticBody/box2d.b2BodyType.b2_dynamicBody/box2d.b2BodyType.b2_kinematicBody/box2d.b2BodyType.b2_bulletBody

bodyDef.userData

boundingradius

Number

bullet

Inherited from CG.B2DEntity but overwritten in cangaja/box2d/b2d-polygon.js:56

categoryBits

Number

clicked

Boolean

dragable

Boolean

fixDef

B2FixtureDef

fixDef.density

Number

fixDef.filter.categoryBits

Number

fixDef.filter.groupIndex

Number

fixDef.filter.maskBits

Number

fixDef.friction

Number

fixDef.restitution

Number

fixedRotation

Boolean

groupIndex

Number

if groupindex is 0 then use categoryBits and maskBits for collision detection

height

Number

jsondata

mapcollision

Boolean

rotation

Number

scale

Inherited from CG.B2DEntity but overwritten in cangaja/box2d/b2d-entity.js:50

transform

Transform

Transform object for matrix transformation

visible

Boolean

visibility option

world

Inherited from CG.B2DEntity but overwritten in cangaja/box2d/b2d-entity.js:45

xhandle

Number

xscale

Number

yhandle

Number

yscale

Number