我的Y轴是翻转所以它在左上角,但这个问题只发生在
bounds = new Rectangle()
我正在使用OrthographicCamera
这样的
camera= new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
camera.setToOrtho(false, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
我的问题是,如何翻转Y轴以使(0,0)最终位于左下角
public class MyGdxGame extends ApplicationAdapter {
SpriteBatch batch;
Player player;
Player2 player2;
InputProcessor inputprocessor;
Texture img;
Vector2 pos;
Rectangle bounds;
GameTime gameTime;
ShapeRenderer sr;
Rectangle p1,p2,p3,p4;
Rectangle tSwitch;
Rectangle Bplayer;
Vector2 p;
Vector2 button1,button2,button3,button4;
Vector2 tButton;
BitmapFont font;
OrthographicCamera camera;
int xi = 0;
int yi = 0;
int Movetime = 0;
int playerSwitch = 0;
float totalTime = 3*60;
Rectangle touchPos;
@Override
public void create () {
camera= new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
camera.setToOrtho(false, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
batch = new SpriteBatch();
img = new Texture("badlogic.jpg");
player = new Player(new Vector2(Gdx.graphics.getHeight() / 2 , Gdx.graphics.getWidth() / 2),"badlogic.jpg");
player2 = new Player2(new Vector2(Gdx.graphics.getHeight() / 2 , Gdx.graphics.getWidth() / 2),"Fagot.jpg");
pos = new Vector2(player.getPosition().x,player.getPosition().y);
gameTime = new GameTime();
button1 = new Vector2(0,0);
button2 = new Vector2(200,0);
button3 = new Vector2(1620,0);
button4 = new Vector2(1820,0);
tButton = new Vector2(800,0);
p1 = new Rectangle(button1.x + 100,button1.y+1225,100,100);
p2 = new Rectangle(button2.x + 100,button2.y+1225,100,100);
p3 = new Rectangle(button3.x + 100,button3.y+1225,100,100);
p4 = new Rectangle(button4.x + 100,button4.y+1225,100,100);
Bplayer = new Rectangle(player2.getPosition().x,player2.getPosition().y,100,100);
tSwitch = new Rectangle(tButton.x+100, tButton.y+1225 ,100,100);
sr = new ShapeRenderer();
font = new BitmapFont();
player.getPosition().x = 100;
player.getPosition().y = 100;
player2.setPosition(new Vector2(500, 500));
bounds = new Rectangle(player.getPosition().x , player.getPosition().y , 255, 255);
touchPos = new Rectangle(Gdx.input.getX(), Gdx.input.getY(),200,200);
}
@Override
public void render () {
Gdx.gl.glClearColor(1, 0, 0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
camera.update(false);
bounds.setPosition(player.getPosition().x,player.getPosition().y);
//bounds = new Rectangle(player.getPosition().x, player.getPosition().y + 800, 255, 255);
float deltaTime = Gdx.graphics.getRawDeltaTime();
totalTime -= deltaTime;
String time = String.valueOf(totalTime);
String meow = String.valueOf(playerSwitch);
String Mtime = String.valueOf(Movetime);
batch.begin();
font.draw(batch, meow, 500, 500);
batch.end();
if(Gdx.input.isTouched(1)){
xi = Gdx.input.getX();
yi = Gdx.input.getY();
}
if(Gdx.input.isTouched()) {
Vector3 pointerPos = new Vector3();
pointerPos.set(Gdx.input.getX(), Gdx.input.getY(), 0);
touchPos.x = pointerPos.x /*+ 64 / 2*/;
touchPos.y = pointerPos.y /* + 64 / 2*/;
}
if(touchPos.overlaps(tSwitch)&& Gdx.input.isTouched()){
playerSwitch++;
try {
Thread.sleep(200);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//}else if(touchPos.overlaps(tSwitch)&& Gdx.input.isTouched() ){
// playerSwitch=1;
}
if(touchPos.overlaps(bounds)&& Gdx.input.isTouched()){
batch.begin();
font.draw(batch,"K",900,1000);
batch.end();
}
if(playerSwitch == 1){
if(touchPos.overlaps(p1)&& Gdx.input.isTouched()){
player.getPosition().x += 5f;
Movetime++;
}
if(touchPos.overlaps(p2)&& Gdx.input.isTouched()){
player.getPosition().y += 5f;
Movetime++;
}
if(touchPos.overlaps(p3)&& Gdx.input.isTouched()){
player.getPosition().x -= 5f;
Movetime++;
}
if(touchPos.overlaps(p4)&& Gdx.input.isTouched()){
player.getPosition().y -= 5f;
Movetime++;
}
}
if(playerSwitch == 2){
if(touchPos.overlaps(p1)&& Gdx.input.isTouched()){
player2.getPosition().x += 5f;
}
if(touchPos.overlaps(p2)&& Gdx.input.isTouched()){
player2.getPosition().y += 5f;
}
if(touchPos.overlaps(p3)&& Gdx.input.isTouched()){
player2.getPosition().x -= 5f;
}
if(touchPos.overlaps(p4)&& Gdx.input.isTouched()){
player2.getPosition().y -= 5f;
}
}
//Draw method
font.setScale(5, 5);
batch.begin();
batch.draw(player.getTexture(), player.getPosition().x, player.getPosition().y);
batch.draw(player2.getTexture(),player2.getPosition().x, player2.getPosition().y);
font.draw(batch, time, 900, 1100);
font.draw(batch, meow, 500, 500);
font.draw(batch, Mtime, 200,200 );
batch.end();
sr.begin(ShapeType.Line);
sr.setColor(255,255,255,255);
sr.rect(player.getPosition().x , player.getPosition().y, 255, 255);
sr.rect(player2.getPosition().x, player2.getPosition().y, 200, 200);
sr.end();
}
}