- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我的 Sprite 移动得太慢了。基本上我想用更少的力来移动我的玩家。目前这个:
getBody().applyForceToCenter(new Vector2(-10000000f,0f), true);
是使其移动一点点所需的力。
我知道我无法移动它的原因是因为我没有缩放 Sprite (64x64),它的重量超过 400 公斤。正确的比例应该是多少?
这是我的游戏屏幕。
public class GameScreen implements Screen {
//Reference to our Game, used to set Screens
private Logang game;
//basic playscreen variables
private OrthographicCamera gamecam;
private Viewport gamePort;
//Box2d variables
private World world;
private Box2DDebugRenderer b2dr;
boolean drawn = true;
private Player p;
private int pX = 100, pY = 300;
public GameScreen(Logang game) {
this.game = game;
//create cam used to follow mario through cam world
gamecam = new OrthographicCamera();
gamePort = new ScalingViewport(Scaling.stretch, Logang.GWIDTH, Logang.GHEIGHT, gamecam);
gamePort.apply();
gamecam.position.set(gamecam.viewportWidth / 2, gamecam.viewportHeight / 2, 0);
gamecam.update();
Box2D.init();
//create our Box2D world, setting no gravity in X, -10 gravity in Y, and allow bodies to sleep
world = new World(new Vector2(0, Logang.GRAVITY), true);
//allows for debug lines of our box2d world.
b2dr = new Box2DDebugRenderer();
//create a FitViewport to maintain virtual aspect ratio despite screen size
p = new Player(new Sprite(new Texture("hud_p3.png")), world, pX, pY, 1);
//initially set our gamcam to be centered correctly at the start of of map
line();
}
@Override
public void show() {
}
public void update(float dt) {
//handle user input first
p.update(dt);
//update our gamecam with correct coordinates after changes
}
@Override
public void render(float delta) {
//separate our update logic from render
update(delta);
//Clear the game screen with Black
Gdx.gl.glClearColor(0, 0, 0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
world.step(1f / 60f, 6, 2);
gamecam.position.set(p.getSprite().getX(),Logang.GHEIGHT / 2, 0); // x and y could be changed by Keyboard input for example
gamecam.update();
game.getBatch().setProjectionMatrix(gamecam.combined);
//renderer our Box2DDebugLines
b2dr.render(world, gamecam.combined);
System.out.println("Player x: " + p.getSprite().getX() + " Camera X: " + gamecam.position.x + " Body X: " + p.getBody().getPosition().x);
//System.out.println("Player y: " + p.getSprite().getY() + " Camera Y: " + gamecam.position.y + " Body Y: " + p.getBody().getPosition().y);
game.getBatch().begin();
if (p.getBody() != null)
p.render(game.getBatch());
EntityManager.renderTerra(game.getBatch(), delta);
game.getBatch().end();
}
public void line() {
Texture tmp = new Texture("hud_p3.png");
tmp.setWrap(Texture.TextureWrap.MirroredRepeat, Texture.TextureWrap.MirroredRepeat);
for (int i = 0; i < 50; i++) {
EntityManager.add(new Ground(new Sprite(tmp), world, (int)(i * Logang.TILE), 1, 2));
}
// EntityManager.changeSize(((Logang.TILE) * 5),Logang.TILE);
}
@Override
public void resize(int width, int height) {
//updated our game viewport
gamePort.update(width, height);
gamecam.position.set(gamecam.viewportWidth / 2, gamecam.viewportHeight / 2, 0);
}
public World getWorld() {
return world;
}
@Override
public void pause() {
}
@Override
public void resume() {
}
@Override
public void hide() {
}
@Override
public void dispose() {
world.dispose();
b2dr.dispose();
}
这是我的实体类
private World world;
private Sprite sprite;
private Body body;
private int tipo;
public Entity(Sprite sprite, World world, int x, int y, int tipo) {
this.sprite = sprite;
this.world = world;
getSprite().setPosition(x, y);
sprite.setSize(Logang.TILE, Logang.TILE);
sprite.setOriginCenter();
define(tipo);
this.tipo = tipo;
}
public void update(float dt){
if(Gdx.input.isKeyPressed(Input.Keys.LEFT)){
getBody().applyForceToCenter(new Vector2(-10000000f,0f), true);
}
if(Gdx.input.isKeyPressed(Input.Keys.RIGHT)){
getBody().applyForceToCenter(new Vector2(10000000f,0f), true);
}
if(Gdx.input.isKeyPressed(Input.Keys.SPACE)){
//getBody().applyLinearImpulse(0f,-Logang.GRAVITY,
getBody().getPosition().x, getBody().getPosition().y, true);
}
}
public void define(int tipo) {
BodyDef bdef = new BodyDef();
bdef.position.set((getSprite().getX() + getSprite().getWidth() / 2),
(getSprite().getY() + getSprite().getHeight() / 2));
switch (tipo) {
case 1: {
bdef.type = BodyDef.BodyType.DynamicBody;
break;
}
case 2: {
bdef.type = BodyDef.BodyType.StaticBody;
break;
}
case 3: {
bdef.type = BodyDef.BodyType.DynamicBody;
break;
}
}
body = world.createBody(bdef);
FixtureDef fdef = new FixtureDef();
fdef.density=0.001f; // (weight: range 0.01 to 1 is good)
PolygonShape shape = new PolygonShape();
shape.setAsBox(getSprite().getWidth() / 2, getSprite().getHeight() / 2);
fdef.shape = shape;
body.createFixture(fdef);
body.setUserData(this);
shape.dispose();
}
public void render(SpriteBatch batch) {
if (tipo != 2) {
float posX = getBody().getPosition().x;
float posY = getBody().getPosition().y;
getSprite().setPosition(posX - getSprite().getWidth() / 2, posY -
getSprite().getHeight() / 2);
}
getSprite().draw(batch);
}
public Sprite getSprite() {
return sprite;
}
public void setSprite(Sprite sprite) {
this.sprite = sprite;
}
public Body getBody() {
return body;
}
public void setBody(Body body) {
this.body = body;
}
这是游戏中的变量
public static final int GWIDTH = 800;
public static final int GHEIGHT = (GWIDTH/16)*9;
public static final float PPM = 100f;
public static final float GRAVITY = -10f;
public static final float TILE = 64;
你能帮我解决一下吗?我已经尝试划分 body 和游戏机位置仍然没有效果
最佳答案
正确的比例应该是多少?
正确的比例应该是现实生活中的比例,其中 LibGDX (Box2D) 中的 1 个单位代表现实生活中的 1 米。我总是建议人们使用这个比例并正确缩放相机。
但请注意,如果您使用非常大的物体并将相机一直向后变焦,则物体看起来会缓慢下落。这显然是因为您的相机包含更大的空间。如果该元素变小,它不仅会缓慢下落,而且无法与世界正确交互。
让相机适应您的世界,而不是让您的世界适应您的相机。
关于java - Libgdx - PPM 世界转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47164432/
一个关于Lua和元表的初学者问题,以一个简单的Hello-World为例,涉及len事件,不幸的是它没有返回预期的结果(我使用的是从 Ubuntu 官方存储库安装的 Lua 5.1)。 案子 这是示例
我正在开发一个 OpenGL 应用程序。我需要一个地球自转模型(蓝色的水,绿色的土地)。我的问题不是处理 OpenGL/图形……而是处理数据。 我在哪里可以获得这些数据? (各个国家的边界)。如果
我试图了解在 OpenGL 中创建空间: 对象空间 世界空间 相机空间 投影空间 我对这些阶段的理解是否正确? “立方体”是在笛卡尔坐标系的中心创建的,直接在程序内部输入顶点坐标。 坐标转换为“世界”
我有一个Entity和Bundle的Components,我想附加到将成为第一个实体的子实体的实体上。我可以使用Commands生成带有我的组件的实体,但是我无法获得实际的Entity,这意味着我不能
我想创建一个游戏,它有一个无尽的(实际上是一个非常大的)世界,玩家可以在其中移动。我是否会抽出时间来实现游戏是一回事,但我发现这个想法很有趣,并且希望就如何实现它提供一些意见。 关键是要有一个所有数据
以下代码片段来自维基百科,是标准 Hello World! 的序言! Brainfuck 中的程序... 1. +++++ +++++ initialize counter (
就目前情况而言,这个问题不太适合我们的问答形式。我们期望答案得到事实、引用资料或专业知识的支持,但这个问题可能会引发辩论、争论、民意调查或扩展讨论。如果您觉得这个问题可以改进并可能重新开放,visit
我正在尝试获取特定日期剩余的确切秒数、分钟数等。这听起来可能很愚蠢,但为什么结果会翻倍呢?这看起来不对,是吗? setInterval(function() { var startDate =
如果我有两个嵌套元素,假设: Foo 然后我对外部元素应用旋转,假设顺时针旋转 45 度: Foo 现在我想将内部 div 向下移动一点。 Foo http://j
在 WindowsForms 世界中,您可以获得可用图像编码器/解码器的列表 System.Drawing.ImageCodecInfo.GetImageDecoders() / GetImageEn
因此,作为我的计算机体系结构类(class)的一部分,我需要熟悉 Assembly,或者至少足够舒适,我正在尝试读取用户的输入然后重新打印(暂时),这是我的我是如何尝试用伪代码来展示它的: 声明 ms
在 HLSL 中有很多矩阵乘法,虽然我了解如何以及在何处使用它们,但我不确定它们是如何导出的或它们的实际目标是什么。 所以我想知道是否有在线资源可以解释这一点,我特别好奇将世界矩阵乘以 View 矩阵
我正在使用 http://jvectormap.owl-hollow.net/ 中的 jVectorMap一切正常。但世界地图的标准尺寸非常小。如果有人想打例如波斯尼亚和黑塞哥维那,他需要大眼镜!有可
我在做游戏。游戏由一个无限平面组成。单位必须在一个离散的正方形上,因此可以使用简单的 Location { x :: Int, y :: Int } 来定位它们。 可能有很多种Unit s。有些可能是
所以我创建了一个顶点着色器,它接受一个角度并计算旋转。尽管模型围绕世界中心而不是它自己的轴/原点旋转,但存在一个问题。 旁注:这是 2D 旋转。 如何让模型绕着自己的轴旋转? 这是我当前的顶点着色器:
所以我创建了一个顶点着色器,它接受一个角度并计算旋转。尽管模型围绕世界中心而不是它自己的轴/原点旋转,但存在一个问题。 旁注:这是 2D 旋转。 如何让模型绕着自己的轴旋转? 这是我当前的顶点着色器:
我最近萌生了创建标签云的想法,就像地球形状的动画一样。我从 ngdc.noaa.gov 中提取了海岸线坐标,并编写了一个小脚本,将其显示在我的浏览器中。现在您可以想象,整个海岸线由大约 48919 个
我使用 3d 模式渲染我的 2d 游戏,因为相机旋转和放大/缩小比 2d 模式容易得多。 现在我遇到了一个我似乎想不出如何解决的问题: 如何使我的世界的 2d 平面以 1 个纹理像素匹配屏幕上的 1
我正在寻找一种简单快捷的方法来清除整个 Phaser 屏幕,就像在 HTML5 canvas 中,您可以通过将 Canvas 的宽度重置为自身来删除所有内容。我无法通过搜索找到任何此类方法 - 只有
是否可以为这样的游戏创建一个 2.5D 世界(双龙)http://www.youtube.com/watch?v=xb9P0YTeq5Y使用box2d? 你知道任何工作示例吗? 预先感谢您的时间。 最
我是一名优秀的程序员,十分优秀!