简体   繁体   中英

libgdx 0.9.7 actor hit doesn't receive actor system coordinates

In my stage I have several actors added. I have Input Processor set for actors as well as for the stage itself.

The problem is that, when I tap on the actor the hit method of the actor receives quite big x and y values (I can see this while debugging) and that means these x and y weren't converted to appropriate coordinates in actor's coordinate system. The documentation states vice version.

Do I miss something in there? Any help is appreciated.

I had a lot of problems with my project and the position of the actors.

Try to use stageToLocalCoordinates, localToParentCoordinates of the group if your Actor is grouped.

If it's a only Actor, try to override the setX and setY or setPosition method and put your coordinates in the constructor of the Actor. This has worked for my. With this method the Actor will have the same coordinates system that the Stage.

Use

Vector2 coords = stage.screenToStageCoordinates(new Vector2(Gdx.input.getX(), Gdx.input.getY()));

then use coords.x and coords.y as your new coordinates in stage.hit() function

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM