42 videos
238 minutes
Finally, to associate this adapter or this processor we have created as we are interested, all you need to do is, in the main game, when we want to associate, to build the instance of the processor, for example processor = new Processor (), and ask libgdx that use the processor to manage these events with a call to Gdx.input.setInputProcessor (). When we begin to make our game with Scene2D
it is important that we remember this line, because Scene2D brings its own processor to treat entrance, so we have to remember to put that line, I will explain at the time. The important thing is that when we make the call to setInputProccesor, from that moment libgdx redirect all calls made or all events that occur regarding entry, such as touching the screen or pressing a key,
to the class that we desired of him we passed as a parameter. And in this case the class has to be either a InputProcessor or InputAdapter. With that we acquire the advantage that in our game we must not waste time checking if pressing a key or not, and that all events are treated asynchronously without affecting the ability to execute our game. Everything is done in parallel without any problem.
All we have to keep in mind, however, is that if we are going to use this system, when we have to control objects or when we have to control other classes, somehow it is necessary that the processor knows those instances so you can manipulate it. Apart from that with this you can try. For example, in the case of this code that had here created, the main feature is that now
when we touch the screen, which is something we do widely from the time in which we play, we can get the message on the screen that says we have pressed a button, the left because it is what I pressed, but if you hit the right tells me is 1 or central, 2. In particular this is repeated for each of the methods we have. The only thing, it is important to return true if they have processed. It seems silly
Touchdown but if I make a false return and try my touchup event, because touchup as when lifting the finger and Touchdown when pressed, to have given false here is not going to treat touchup. Be consistent with what you do, if you have to treat a touchup, try before touchdown. Although you do only one return true. But if the down returns false, the up is not going to be able to run, because it will not consider it necessary
if it has not been treated the down. You know, always usad this. For any of the methods that have, as scrolled, indicating whether we clicked mouse wheel. With them it is important. Anyway when we start the game Scene2D normally will abstracting enough well as we not have to use processors, we use another class that looks like a processor but is not equal. We pass events and
We checked, and we tell if we tried or not. But if we do something so basic, and I could not think of a better way to explain to separately, it is one thing to consider.
About the Author
Biography: Analyst-Programmer in different languages. Tutor PREMIUM platforms recognized worldwide as CodigoFacilito. Editor Cristalab articles. My YouTube Channel is sponsored by the ANAYA and LaTostadora publisher. I like to explain in detail and give several examples for the avoidance of doubt.