I'm making a libgdx game as an exercise. Its pretty simple, something like "escape" kind of game. Just screens with background, some items and go left/right arrows.
As libgdx makes everything easy, I was wandering if there is an easy method of handling actions. Now its just a bunch of "if else" statements in onClick() method. Now its fine, but with tens or houndreds of items it will be messy and probably laggy when clicked.
public void onClick(int scrX, int scrY){
pX = (scrX/viewW)*WORLD_W;
pY = (scrY/viewH)*WORLD_H;
if (pX > 10 && pX < 20 && pY > 10 && pY < 20) {
if (stage.getInfo().getLeft() == true) {
Gdx.app.log("Click", "Left");
stage = new StageGame(stage.getInfo().getLeftStage());
}
}
else if(pX > 80 && pX < 90 && pY > 10 && pY < 20) {
if (stage.getInfo().getRight() == true) {
Gdx.app.log("Click", "Right");
stage = new StageGame(stage.getInfo().getRightStage());
}
}
}
I was thinking about switch here, but i would still have to use some conditions. Other idea was a matrix, lets say 100x100. With every stage it would be read from file. After click x and y would be easly translated into grid values and proper action would happen. But thats good only for static game, and not shure about memory usage, and handling that matrix.
I'm pretty shure thats all wrong but i cant find something that i cant name :P Help pls!