HTML and CSS Reference
In-Depth Information
Q.register('2d',{
added: function() {
var entity = this.entity;
_(entity.p).defaults({
vx: 0,
vy: 0,
ax: 0,
ay: 0,
gravity: 1,
collisionMask: 1
});
entity.bind('step',this,"step");
if(Q.debug) {
entity.bind('draw',this,'debugDraw');
}
},
extend: {
collisionPoints: function(points) {
var p = this.p, w = p.w, h = p.h;
if(!points) {
p.col = {
top: [ [w/2, 0]],
left: [ [0, h/3], [0, 2*h/3]],
bottom:[ [w/2, h]],
right: [ [w, h/3], [w, 2*h/3]]
}
} else {
p.col = points;
}
}
},
step: function(dt) {
var p = this.entity.p,
dtStep = dt;
while(dtStep > 0) {
dt = Math.min(1/30,dtStep);
// Updated based on the velocity and acceleration
p.vx += p.ax * dt + Q.gravityX * dt * p.gravity;
p.vy += p.ay * dt + Q.gravityY * dt * p.gravity;
p.x += p.vx * dt;
p.y += p.vy * dt;
this.entity.parent.collide(this.entity);
dtStep -= 1/30;
Search WWH ::




Custom Search