CG.B2DPolygon Class
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
})
Item Index
Methods
Properties
- allowSleep
- alpha
- angle
- awake
- body
- bodyDef
- bodyDef.alowSleep
- bodyDef.angle
- bodyDef.awake
- bodyDef.bullet
- bodyDef.fixedRotation
- bodyDef.position
- bodyDef.type
- bodyDef.userData
- boundingradius
- bullet
- categoryBits
- clicked
- dead
- density
- dragable
- fixDef
- fixDef.density
- fixDef.filter.categoryBits
- fixDef.filter.groupIndex
- fixDef.filter.maskBits
- fixDef.friction
- fixDef.restitution
- fixedRotation
- friction
- groupIndex
- height
- hover
- id
- isHit
- jsondata
- mapcollision
- maskBits
- polys
- restitution
- rotation
- scale
- strength
- transform
- vecs
- visible
- width
- world
- x
- xhandle
- xscale
- y
- yhandle
- yscale
Methods
AABB
()
Object
returns the bounds of rotated rectangle
Returns:
returns the calculated bounds
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
Arraya array of objects to check for collision => Sprites, Animations, MapAreas
-
callback
Callbackwhat to do after collision?
getPolysFromBitmapTrace
-
image
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:
-
image
Object
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
()
ifClicked
()
True/false
checks click inside of the rectangle, supports rotation
Returns:
ifMouseOver
()
checks if the mouse/pointer is over the rectangle
init
-
options
Options: name {string} image {mixed} texturepacker {string} x {number} y (number} world {object} scale {number} bodyType {box2d.b2BodyType} bullet {boolean}
Parameters:
-
options
Object
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:
-
vecs
Object
setImage
-
image
initialize image for object. for now => sprite, particle, buffer, bitmap and button use it
Parameters:
-
image
Imageimage path, image or atlasimage
Properties
body
B2Body
bodyDef
B2BodyDef
bodyDef.bullet
bodyDef.position
Unknown
bodyDef.type
box2d.b2BodyType.b2_staticBody/box2d.b2BodyType.b2_dynamicBody/box2d.b2BodyType.b2_kinematicBody/box2d.b2BodyType.b2_bulletBody
bodyDef.userData
bullet
fixDef
B2FixtureDef
jsondata
scale
transform
Transform
Transform object for matrix transformation