Home Game Development libgdx – How to mix Actor.setPosition and Actor.hit?

libgdx – How to mix Actor.setPosition and Actor.hit?

0
libgdx – How to mix Actor.setPosition and Actor.hit?

[ad_1]

Why after utilizing Actor.setPosition, enter coordinates in Actor.hit include a shift within the values ​​laid out in setPosition?

Create scene:

public class MyActor extends Actor {
...
    int width = 70;
    int top = 70;

    public MyActor(Texture img, int x, int y, int realX, int realY) {
...
        sprite = new Sprite(img, x, y, width, top);
        this.setPosition(realX, realY);

Standard search Actor:

public class SportScreen implements Screen, InputProcessor {

    @Override
    public boolean touchDown(int screenX, int screenY, int pointer, int button) {
        Vector2 coord = stage.screenToStageCoordinates(new Vector2((float)screenX,(float)screenY));
        Gdx.app.log("touchDown", "" + coord.x +","+ coord.y);

        chosenActor = (MyActor)stage.hit(coord.x,coord.y,false);

public class MyActor extends Actor {

    @Override
    public Actor hit(float x, float y, boolean touchable) {
        if(!touchable)
            Gdx.app.log("Actor.hit:", "" + x +":"+ y);
        return x < getX()|| x >= getX() + width || y < getY()||  y >= getY() + top ? null : this;

But come the distorted values.

Coordinates Click: touchDown: 26.25,81.250015.

MyActor within the values ​​obtained from the offset, the a number of of 70:

  • Actor.hit: -43.75:11.250015

  • Actor.hit: -43.75:81.250015

  • Actor.hit: 26.25:11.250015

  • Actor.hit: 26.25:81.250015

Why? How to repair?

UPDATE

public class MyStage extends Stage {
...
    @Override
    public Actor hit(float x, float y, boolean touchable) {

        return tremendous.hit(x,y,touchable);

[ad_2]

LEAVE A REPLY

Please enter your comment!
Please enter your name here