現在、box2Dweb でゲームを作成しています。シェイプがキャンバスの右下隅に向かって移動するたびに、そのスプライトはオフセットを伴って移動するように見え、それがどんどん大きくなります (シェイプをキャンバスの左上隅に向かって移動すると、スプライトの位置合わせはますます良くなります)。 、そしてその理由が本当にわかりません。私の表示ループに何か問題がありますか?
このスニペットで正方形の立方体を作成しています:
this.createSquare= function(x, y, bodyDef, fixtureDef, object){
if(object.isStatic){
bodyDef.type = b2Body.b2_staticBody;
}else{
bodyDef.type = b2Body.b2_dynamicBody;
}
fixtureDef.shape = new object.shape;
polygonShape = fixtureDef.shape;
polygonShape.SetAsBox(object.width,object.height);
bodyDef.position.Set(x/game.worldScale,y/game.worldScale);
}
そして、表示ループでこの関数を使用して、いくつかのスプライトを表示します。
for(var i=0; i < tab.length; i++) {
context.save();
console.log(context);
context.translate(tab[i].GetBody().GetPosition().x * 30, tab[i].GetBody().GetPosition().y * 30);
context.rotate(tab[i].GetBody().GetAngle());
var dataResize = { 'image' : tab[i].GetUserData().img,
'imgPosX' : tab[i].GetBody().GetPosition().x,
'imgPosY' : tab[i].GetBody().GetPosition().y,
'imgWidth' : tab[i].m_shape.m_vertices[2].x*60,
'imgHeight': tab[i].m_shape.m_vertices[2].y*60
}
context.drawImage(
dataResize.image,
(dataResize.imgPosX) - (dataResize.imgWidth/2), //img pos x
(dataResize.imgPosY) - (dataResize.imgHeight/2), //img pos y
dataResize.imgWidth, //img wdith
dataResize.imgHeight //img height
)
context.restore();
}
何が欠けていますか?SOFLOW で見つけたほとんどすべてのものを読んでみましたが、問題を確認できませんでした。
ありがとう