CG.B2DTerrain Class
B2DTerrain looks similar to B2DPolygon but has more features for polygon manipulation like clipping and triangulation.
var terrainShapes =
[{
outer: [{
x: 0,
y: 100.5
}, {
x: 1024,
y: 100.5
}, {
x: 1024,
y: 768
}, {
x: 0,
y: 768
}],
holes: []
}]
b2world.createTerrain({
name: 'terrain',
image: false
terrainShape: terrainShapes,
x:0,
y:0,
world: b2world,
scale: 40
})
Item Index
Methods
Properties
- allowSleep
- alpha
- angle
- awake
- bitmap
- 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
- holes
- hover
- id
- image
- isHit
- mapcollision
- maskBits
- polys
- restitution
- rotation
- scale
- strength
- terrainShape
- terrainTriangles
- transform
- 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?
cleanTerrain
()
Experimental not working yet. Try to use the Clipperlib Clean method
clipTerrain
-
opt
Using Clipper to clip a hole in a given polygonshape. Important: the outer polygon points have to be in CW orientation, the hole polygons must ordered in CCW
Options: points - points for clipping, radius - radius for clipping, x - x pos for clipping, y - y pos for clipping
Parameters:
-
opt
Object
createCircle
-
opts
creates a ccw wise circle vertices array for clipping
Options: points - number of points of circle, radius - radius for circle, x - x position for circle, y - y position for circle
Parameters:
-
opts
Objectexample {points: 16, radius: 30, x: 320, y: 240}
Returns:
createTerrain
()
deleteTerrain
()
deletes the terrain
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} points {array} x {number} y {number} world {object} scale {number}
Parameters:
-
options
Object
Returns:
lightenTerrain
()
this method uses the Clipper Lighten method to reduce vertices for better triangulation
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
bodyDef
B2BodyDef
bodyDef.position
Unknown
bodyDef.type
box2d.b2BodyType.b2_staticBody/box2d.b2BodyType.b2_dynamicBody/box2d.b2BodyType.b2_kinematicBody/box2d.b2BodyType.b2_bulletBody
bodyDef.userData
bullet
B2Body
fixDef
B2FixtureDef
image
Strng
scale
terrainShape
transform
Transform
Transform object for matrix transformation