我有2個類,inputHandlerMenu和GameWorld,我想從inputHanlerMenu獲得一個整數並在GameWorld中使用它!它嘗試了很多,但我沒有工作。誰能幫我 ?我怎麼能保存一個類的整數,並在另一個類中使用它
我聲明:public GameWorld seter;
@Override
public boolean touchUp(int screenX, int screenY, int pointer, int button) {
screenX = scaleX(screenX);
screenY = scaleY(screenY);
if (menuButtons.get(0).isTouchUp(screenX, screenY)) {
world.getMenuObject().getPad().end();
seter.setModes(1);
for (int i = 0; i < menuButtons.size(); i++) {
menuButtons.get(i).end();
}
world.getMenuObject().getVolumeButton().end();
menuButtons.get(0).tranToGameScreen();
}if (menuButtons.get(1).isTouchUp(screenX, screenY)) {
world.getMenuObject().getPad().end();
seter.setModes(2);
for (int i = 0; i < menuButtons.size(); i++) {
menuButtons.get(i).end();
}
world.getMenuObject().getVolumeButton().end();
menuButtons.get(1).tranToGameScreen();
}if (menuButtons.get(2).isTouchUp(screenX, screenY)) {
world.getMenuObject().getPad().end();
seter.setModes(3);
for (int i = 0; i < menuButtons.size(); i++) ....
我宣佈模式爲公共int模式;
public void setModes (int mode){
this.mode = mode;
}
private void collisions() {
{
if (!ball.hasCollided()) {
for (int i = 0; i < pad.getcolCircles().size(); i++)
if (Intersector.overlaps(pad.getcolCircles().get(i), ball.getColCircle())) {
ball.collide();
ball.setCollided(true);
//Gdx.app.log("Angle", ball.getVelocity().toString());
//double perp = 2.0 * ball.getVelocity().cpy().dot(pad.returnNormal(i));
//Vector2 reflectDir = ball.getVelocity().cpy().sub((pad.returnNormal(i).scl((float) perp))).scl(1);
float newAngle = getAngle2Vecs(ball.getVelocity(), pad.returnNormal(i));
//Gdx.app.log("Angle", newAngle + "");
ball.setVelocity(new Vector2(gameWidth/2 - ball.getColCircle().x, gameHeight/2 - ball.getColCircle().y));
int rand = (int) Math.random() * 90 + 5;
if (pad.getAngularVelocity() < 0) {
ball.setVelocity(ball.getVelocity().cpy().rotate((float) (rand + Math.random() * 50)));
} else if (pad.getAngularVelocity() > 0) {
ball.setVelocity(ball.getVelocity().cpy().rotate((float) (-rand - Math.random() * 50)));
} else {
ball.setVelocity(ball.getVelocity().cpy().rotate(Math.random() < 0.5 ? -rand : rand));
System.out.println(mode);
if (mode == 1) {
if (score <= 5) {
ball.setVelocity(ball.getVelocity().cpy().scl(Configuration.E_VELOCITY_OVER_0));
} else if (score >= 5 && score < 50) {
ball.setVelocity(ball.getVelocity().cpy().scl(Configuration.E_VELOCITY_OVER_5));
} else if (score >= 10 && score < 50) {
ball.setVelocity(ball.getVelocity().cpy().scl(Configuration.E_VELOCITY_OVER_10));
} else if (score >= 20 && score < 50) {
ball.setVelocity(ball.getVelocity().cpy().scl(Configuration.E_VELOCITY_OVER_20));
} else if (score >= 35 && score < 50) {
ball.setVelocity(ball.getVelocity().cpy().scl(Configuration.E_VELOCITY_OVER_35));
} else if (score >= 50 && score < 75) {
ball.setVelocity(ball.getVelocity().cpy().scl(Configuration.E_VELOCITY_OVER_50));
} else if (score >= 65 && score < 75) {
ball.setVelocity(ball.getVelocity().cpy().scl(Configuration.E_VELOCITY_OVER_65));
} else if (score >= 75 && score < 100) {
ball.setVelocity(ball.getVelocity().cpy().scl(Configuration.E_VELOCITY_OVER_75));
} else if (score >= 100) {
ball.setVelocity(ball.getVelocity().cpy().scl(Configuration.E_VELOCITY_OVER_100));
} ....
我使用的每一個按鈕她的模式,就像如果他按下按鈕0,速度會有所改變,按鍵1 =>速度變化......
這裏的INT保持爲0。它不會改變!
任何人都知道該怎麼做! ?
您應該將值傳遞給活動。將值設置爲一個模型類,並在其他模型類中設置值不會工作... – 2015-03-13 16:55:49
您可以將變量聲明爲'protected static',而不是'public'。然後將它引用到包含類的名稱前面。 I.e .:'score = Class1.intValue + 5;' – 2015-03-13 17:07:40
idk該怎麼做? – 2015-03-13 22:45:15