java - Input - Action Handling in LibGdx -
i'm making libgdx game exercise. pretty simple, "escape" kind of game. screens background, items , go left/right arrows.
as libgdx makes easy, wandering if there easy method of handling actions. bunch of "if else" statements in onclick() method. fine, tens or houndreds of items messy , 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 thinking switch here, still have use conditions. other idea matrix, lets 100x100. every stage read file. after click x , y easly translated grid values , proper action happen. thats static game, , not shure memory usage, , handling matrix.
i'm pretty shure thats wrong cant find cant name :p pls!
i think can use libgdx actors infrastructure (aka scene2d) organize on-screen elements. actors can have location on screen, , own onclick
handlers. libgdx take care of figuring out actor has been clicked , invoke handler. see when use actors in libgdx? cons , pros? , https://github.com/libgdx/libgdx/wiki/scene2d
as aside, don't need worry performance of click detection unless have 1000s of objects on screen (and have other problems). more worried making code maintainable , debuggable @ point.
Comments
Post a Comment