【发布时间】:2015-02-18 23:05:38
【问题描述】:
box2d 出现问题。我想添加到已经存在的游戏物理,但遇到了问题。一、我用计算绘制的游戏世界
public Hero(float x, float y, int width, int height) {
this.width = width;
this.height = height;
position = new Vector2(x, y);
velocity = new Vector2(0, 0);
acceleration = new Vector2(0, -420);
}
public void update(float delta){
velocity.mulAdd(acceleration, delta);
if(velocity.y < -200){
velocity.y = -200;
}
position.mulAdd(velocity,delta);
}
public void onTap(){
velocity.y = 140;
}
英雄的身体从标准设置中掉下来,但是我添加到测试中的身体盒子表现得很奇怪。
问题1.为什么box2d的box比hero多用这个设置,但是当我除以2的时候,就变成和hero的贴图大小差不多了?可能会关联这样的效果,使身体以所有方向的中心为基础绘制 2. 为什么重力-420的世界中的身体以相同的速度连续下降,但没有我的英雄那么多。如何达到类似的效果呢?
hero = new Hero(30, midPointY, 18, 21);
hero1 = new Box2Dhero(world, 90, midPointY, 18, 21);
它的 box2d hero 构造函数
public Box2Dhero(World world, float x, float y, int width, int height ) {
bodyDef = new BodyDef();
bodyDef.position.set(x,y);
bodyDef.type = BodyDef.BodyType.DynamicBody;
body = world.createBody(bodyDef);
box = new PolygonShape();
box.setAsBox(width,height);
fixtureDef = new FixtureDef();
fixtureDef.shape = box;
body.createFixture(fixtureDef);
}
我的游戏世界大小
float screenWidth = Gdx.graphics.getWidth();
float screenHeight = Gdx.graphics.getHeight();
float gameHeight = 385;
float gameWidth = screenWidth / (screenHeight / gameHeight);
【问题讨论】:
-
考虑为您的单位命名。加速度或重力为 420 看起来您使用了错误的单位。 420什么?