Android : Click next button in first screen but detected next for in second screen

on Sunday, September 7, 2014


I have a problem. I made a game with 2 menujema and playfield. When I hit the first menu button next to my senses as I pressed the button next to the other menus (buttons have the same coordinates). Now I wonder how this is possible?



import com.badlogic.gdx.Game;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.math.Vector3;
import com.badlogic.gdx.scenes.scene2d.Stage;

public class AddAtributesPerson implements Screen {
OrthographicCamera guiCam;
SpriteBatch batcher;
Rectangle firstPersonCharacter;
Rectangle secondPersonCharacter;
Rectangle thirdPersonCharacter;
Rectangle forthPersonCharacter;
Rectangle nextBounds;
Rectangle backBounds;
Vector3 touchPoint;
boolean firstPersonCharacterBoolean, secondPersonCharacterBoolean,thirdPersonCharacterBoolean,
forthPersonCharacterBoolean;
Game game;


public AddAtributesPerson(Game game) {
this.game = game;
// Gdx.app.getApplicationListener().setScreen(new Screen());
Gdx.input.setInputProcessor(null);
// Gdx.input.setInputProcessor(new Stage());
guiCam = new OrthographicCamera(320, 480);
guiCam.position.set(320 / 2, 480 / 2, 0);
batcher = new SpriteBatch();


}


public void update() {
if (Gdx.input.isTouched()) {

guiCam.unproject(touchPoint.set(Gdx.input.getX(), Gdx.input.getY(), 0));

if (firstPersonCharacter.contains(touchPoint.x, touchPoint.y)) {

Assets.playSound(Assets.clickSound);

firstPersonCharacterBoolean=true;
return;
}
if (secondPersonCharacter.contains(touchPoint.x, touchPoint.y)) {
Assets.playSound(Assets.clickSound);
secondPersonCharacterBoolean=true;

return;
}
if (thirdPersonCharacter.contains(touchPoint.x, touchPoint.y)) {
Assets.playSound(Assets.clickSound);
thirdPersonCharacterBoolean=true;

return;
}
if (forthPersonCharacter.contains(touchPoint.x, touchPoint.y)) {
Assets.playSound(Assets.clickSound);
forthPersonCharacterBoolean=true;
return;
}


if (nextBounds.contains(touchPoint.x, touchPoint.y)) {
Assets.playSound(Assets.clickSound);
game.setScreen(new GameScreen(game));
return;
}

if (backBounds.contains(touchPoint.x, touchPoint.y)) {
Assets.playSound(Assets.clickSound);
game.setScreen(new ChoosePerson(game));
return;
}


}
}


@Override
public void resume() {

}

@Override
public void dispose() {
}

@Override
public void render(float delta) {
update();
draw();
// TODO Auto-generated method stub

}

@Override
public void resize(int width, int height) {
// TODO Auto-generated method stub

}

@Override
public void show() {
// TODO Auto-generated method stub

}

@Override
public void hide() {
// TODO Auto-generated method stub

}


@Override
public void pause() {
// TODO Auto-generated method stub

}
}

0 comments:

Post a Comment