[postlink]
https://the-best-way-of-life-is-islam.blogspot.com/2015/07/mainmenu-screen-touch-irresponsive.html
[/postlink]
My app starts perfectly fine but all I see is my mainmenu screen and it does not respond to touch. I have looked everywhere for the answer, but to no avail...
package com.androidgames.greed;
import java.util.List;
import com.androidgames.framework.Game;
import com.androidgames.framework.Graphics;
import com.androidgames.framework.Input.TouchEvent;
import com.androidgames.framework.Screen;
public class MainMenuScreen extends Screen {
public MainMenuScreen(Game game) {
super(game);
}
@Override
public void update(float deltaTime) {
Graphics g = game.getGraphics();
List<TouchEvent> touchEvents = game.getInput().getTouchEvents();
int len = touchEvents.size();
for(int i = 0; i < len; i++) {
TouchEvent event = touchEvents.get(i);
if(event.type == TouchEvent.TOUCH_UP) {
if(inBounds(event, 0, g.getHeight() - 64, 64, 64)) {
Settings.soundEnabled = !Settings.soundEnabled;
if(Settings.soundEnabled)
Assets.Click.play(1);
}
// if(inBounds(event, 64, 220, 192, 42)) {
// game.setScreen(new GameScreen(game));
// if(Settings.soundEnabled)
// Assets.Click.play(1);
// return;
// }
// if(inBounds(event, 64, 220 + 42, 192, 42)) {
// game.setScreen(new HighscoreScreen(game));
// if(Settings.soundEnabled)
// Assets.Click.play(1);
// return;
// }
if(inBounds(event, 64, 220 + 84, 192, 42)) {
game.setScreen(new HowToPlayScreen(game));
if(Settings.soundEnabled)
Assets.Click.play(1);
return;
}
}
}
}
private boolean inBounds(TouchEvent event, int x, int y, int width, int height) {
if(event.x > x && event.x < x + width - 1 && event.y > y && event.y < y + height - 1)
return true;
else
return false;
}
@Override
public void present(float deltaTime) {
Graphics g = game.getGraphics();
g.drawPixmap(Assets.Background, 0, 0);
g.drawPixmap(Assets.Logo, 32, 20);
g.drawPixmap(Assets.Mainmenu, 64, 220);
if(Settings.soundEnabled)
g.drawPixmap(Assets.Buttons, 0, 416, 0, 0, 64, 64);
else
g.drawPixmap(Assets.Buttons, 0, 416, 64, 0, 64, 64);
}
@Override
public void pause() {
Settings.save(game.getFileIO());
}
@Override
public void resume() {
}
@Override
public void dispose() {
}
}
My main concern is the inbounds. I believe that is where my error is. Did I mess up my private Boolean? Is there a possibility that where I think 0,0 is could be wrong? If theres any other code you need to help solve the issue I'll provide it asap
Enregistrer un commentaire