Mike Baranczak
unread,Mar 27, 2011, 8:59:42 PM3/27/11Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to the-rend...@googlegroups.com
I'm trying to get started with the physics engine, and can't get anywhere. I'm creating a square object, which should start in the middle of the play area, then fall down. Instead, it gets placed in the upper left corner, and never moves. What am I doing wrong?
/** Run the game as soon as all resources are ready.
*/
run: function() {
var gravity = Vector2D.create(0, 650);
this.simulation = Simulation.create("simulation", this.fieldBox, gravity);
this.simulation.setIntegrations(3);
this.renderContext.add(this.simulation);
Engine.getDefaultContext().add(this.renderContext)
this.cModel = SpatialGrid.create(this.fieldWidth, this.fieldHeight, 8);
this.addThing(Box.create(), 100, 100)
},
addThing: function(thing, x, y) {
var p = Point2D.create(x, y)
thing.setSimulation(this.simulation)
this.renderContext.add(thing)
thing.simulate()
thing.setPosition(p)
p.destroy()
},
And the Box class:
Engine.initObject("Box", "PhysicsActor", function() {
var Box = PhysicsActor.extend({
constructor: function() {
this.base("Box")
this.setBoundingBox(0, 0, 30, 30)
var body = BoxBodyComponent.create('physics', this.getBoundingBox().getDims())
body.setDensity(2)
body.setFriction(0)
this.add(body)
body.setRenderComponent(SpriteComponent.create("draw"))
},
setPosition: function(point) {
this.base(point)
this.getComponent("physics").setPosition(point)
},
update: function(renderContext, time) {
//console.log('update: '+time);
this.base(renderContext, time)
renderContext.setFillStyle("#ff0000")
renderContext.drawFilledRectangle(this.getBoundingBox())
}
}, { // Static
getClassName: function() {
return "Box"
}
})
return Box
})