그래서 게임에서 주인공의 움직임을 유발하는 키를 구현하려고합니다.플레이어 이동 (점프 문제)
public class Play implements Screen{
변수 :
World world;
Box2DDebugRenderer b2Dr;
OrthographicCamera camera;
OrthographicCamera hudCamera;
private SpriteBatch batch;
private Body toniBody;
private RHContactListener rhcl;
렌더링 물건 (가 InputAdapter를 확장하고 설정 특정 키를 GOTS, 나는 setInputProcessor에 대한 InputController라는 이름의 자바 클래스가 있습니다 여기 내 코드입니다 다운 및 업 상태) :
여기@Override
public void render(float delta) {
Gdx.gl.glClearColor(1, 1, 1, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
Gdx.input.setInputProcessor(new InputController());
RHInput.update();
camera.update();
handleInput();
world.step(delta, 6, 2);
batch.setProjectionMatrix(camera.combined);
batch.begin();
batch.end();
b2Dr.render(world, camera.combined);
}
카메라는 특정 줌
로 설정된다 난 내 장면의 객체, 지상 플레이어 정의 된 곳 여기@Override
public void show() {
world = new World(new Vector2(0, -9.81f),true);
rhcl = new RHContactListener();
world.setContactListener(rhcl);
b2Dr = new Box2DDebugRenderer();
batch = new SpriteBatch();
camera= new OrthographicCamera();
은 다음과 같습니다 : 6,
@Override
public void resize(int width, int height) {
camera.viewportWidth = width/24;
camera.viewportHeight = height/24;
camera.update();
}
물건이 화면에있을 여기
////Box2D////
//CREATE GROUND
//body definition
BodyDef bDef = new BodyDef();
bDef.position.set(0,-14);//meters
bDef.type = BodyDef.BodyType.StaticBody;
Body body = world.createBody(bDef);
//shape definition
PolygonShape ground = new PolygonShape();
ground.setAsBox(25, 1);//meters
//fixture definition
FixtureDef fDef = new FixtureDef();
fDef.friction= .5f;
fDef.shape = ground;
fDef.filter.categoryBits = B2DVariables.BIT_ground;//colision type
fDef.filter.maskBits = B2DVariables.BIT_can;//matching collision type
body.createFixture(fDef).setUserData("ground");
//CREATE TONI
//body definition
bDef.position.set(-10,-10);//meters
bDef.type = BodyDef.BodyType.DynamicBody;
toniBody = world.createBody(bDef);
//shape definition
PolygonShape tBox = new PolygonShape();
tBox.setAsBox(0.5f,2);//meters
//fixture definition
fDef.shape = tBox;
fDef.filter.categoryBits = B2DVariables.BIT_can;//colision type can step on ground
fDef.filter.maskBits = B2DVariables.BIT_ground;
toniBody.createFixture(fDef).setUserData("toni");
//Toni's foot the Ground Sensor
tBox.setAsBox(.2f , 0.2f, new Vector2(0, -2),0);
fDef.shape = tBox;
fDef.filter.categoryBits = B2DVariables.BIT_can;
fDef.filter.maskBits = B2DVariables.BIT_ground;
fDef.isSensor = true;
toniBody.createFixture(fDef).setUserData("toniFoot");
ground.dispose();
tBox.dispose();
}
하는 부분입니다 어디에 특정 키 트리거 동작
public void handleInput(){
//press W key aka Up key or BTNup
if (RHInput.isDown(RHInput.BTNup)){
if(rhcl.isPlayerOnGround()) {
toniBody.setLinearVelocity(0,100);
System.out.println("Toni jumps");
}
}
if (RHInput.isDown(RHInput.BTNright)){
rhcl.isPlayerOnGround();
toniBody.setLinearVelocity(5,0);
System.out.println("Toni walks right");
}else {
toniBody.setLinearVelocity(0,0);
}
if (RHInput.isDown(RHInput.BTNleft)){
if(rhcl.isPlayerOnGround()) {
toniBody.setLinearVelocity(-5,0);
System.out.println("Toni walks left");
}
else {
toniBody.setLinearVelocity(0,0);
}
}
if (RHInput.isPressed(RHInput.BTNdown)){
System.out.println("pressed s");
}
if (RHInput.isDown(RHInput.BTNdown)){
System.out.println("holding s");
}
}
기타 libGDX stuff
@Override
public void hide() {
dispose();
}
@Override
public void pause() {
}
@Override
public void resume() {
}
@Override
public void dispose() {
world.dispose();
b2Dr.dispose();
}
} 코드가 작동
. 문자는 선형 속도로 좌우로 움직입니다. 그러나 그것은 매우 높게 뛰어 오르지 않으며 떨어질 때 매우 느리게 떨어집니다. 이 문제를 어떻게 해결할 수 있습니까?
감사합니다.
물건을 빨리 떨어 뜨리는 간단한 방법은 중력을 높이는 것입니다. 플레이어가 더 높은 도약을하도록하는 간단한 방법은 그를 도약시키려는 충동/속도를 증가시키는 것입니다. – iforce2d