0
votes
    package com.mygdx.game;
    public class Box extends Actor implements Disposable{
    private int matPosX,matPosY,nearBombs;
    private boolean bomb,disarmed; 
    private enum selectedValue{notselected,bombed,unknown};
    private selectedValue value;
    protected MinerLogic logicaJuego;
    private Texture caja;
    private TextureRegion miCaja;


    protected Box(int x,int y,MinerLogic game)
    {
        this.setPosMatX(x);
        this.setPosMatY(y);
        setBomb(false);
        setSelected(selectedValue.notselected);
        setDisarmed(false);
        setNearBombs(0);
        this.logicaJuego=game;

        caja = new Texture("minerjpg/box.jpg");
        miCaja =new TextureRegion(caja,Constants.size,Constants.size);
        super.setBounds(Constants.startX+Constants.size*matPosX, 
                Constants.startY+Constants.size*matPosY, 
                Constants.size, Constants.size);
        setTouchable(Touchable.enabled);
        System.out.println("Bound creados");
        System.out.println(super.getX());
        System.out.println(super.getY());
        System.out.println(super.getWidth());
        System.out.println(super.getHeight());
        this.addListener(new InputListener() {
            public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) 
            {
                //Se ejecuta cuando se hace click sobre el actor.
                System.out.println("down");
                logicaJuego.intento(matPosX,matPosY);
                return true;
            }
            public void touchUp (InputEvent event, float x, float y, int pointer, int button) {
                System.out.println("up");
            }
        });
    }

Well, i think i am using well the addListener, so i really dont understand why program never detect the touchDown.I am printing a lot of actors, but noone can detect touchDown. bounds are working well:

I dont have anymore listeners on my program, so it cannt be handled in other side. For now i only have one actor

Well, i think i should give more information. This is class that controll all the logic of game. Extending of table.

   import com.badlogic.gdx.graphics.g2d.Batch;
   import com.badlogic.gdx.scenes.scene2d.ui.Table;

public class MinerLogic extends Table{
protected Box[][] campos;
protected botonDeNuevo boton;
protected int freeBoxes;
public PantallaMineer pantalla;
public MyGdxGame game;

public MinerLogic(MyGdxGame game,PantallaMineer pantalla,int numX,int  numY,int numBombs)
{
    //Inisicalizamos el los campos a partir del tamanio dado
    this.campos= new Box[numX][numY];
    this.freeBoxes=numX*numY-numBombs;
    this.game=game;
    this.pantalla=pantalla;
    for(int a=0;a<=numX-1;a++)
    {
        for(int b=0;b<=numY-1;b++)
        {
            this.campos[a][b]=new Box(a,b,this);

        }
    }
    boton=new botonDeNuevo(this);
    int c=0;
    //armamos las bombas
    while(c<numBombs){
        int x=(int) (Math.random()*(numX-1));
        int y=(int) (Math.random()*(numY-1));
        if(!(this.campos[x][y].isBomb())){
            this.campos[x][y].arm();
            c++;
        }
    }
}



@Override
public void draw(Batch batch, float parentAlpha) {
    // TODO Auto-generated method stub
    int numX=this.campos.length;
    int numY=this.campos[0].length;
    for(int a=0;a<=numX-1;a++)
    {
        for(int b=0;b<=numY-1;b++)
        {
            this.campos[a][b].draw(batch, parentAlpha);
        }
    }
    boton.draw(batch, parentAlpha);
}
.../

And here my abstract class that implementens screen interface Its just abstract empty class

package com.mygdx.game;

import com.badlogic.gdx.Screen;

public abstract class Pantalla implements Screen {

@Override
public void render(float delta) {
    // TODO Auto-generated method stub

}

@Override
public void resize(int width, int height) {
    // TODO Auto-generated method stub

}


package com.mygdx.game;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.scenes.scene2d.Stage;

public class PantallaMineer extends Pantalla{
private MyGdxGame game;
private Stage stage;
private MinerLogic logic ;

public PantallaMineer(MyGdxGame game,int numX,int  numY,int numBombs){
    this.game=game;
    logic=new MinerLogic(this.game,this,numX,numY,numBombs);
    this.stage=new Stage();
    Gdx.input.setInputProcessor(stage);
    logic.setFillParent(true);
    stage.addActor(logic);
}

@Override
public void render(float delta) {

    logic.draw(game.batch, delta);
    stage.act(Gdx.graphics.getDeltaTime());
    stage.draw();
    super.render(delta);
}

As I can understand, now i am not connectiong my actors with the stage. Stage can "see" a table, but cannt "see" actors. How could I connect actors woth stage??

OK, ty for help. Question solved For people who will find the same problem If you have class extending table, all actors you have in your data strucutre, you need to add to your class pather i solved it changing

            this.campos[a][b]=new Box(a,b,this);

for

            aux=new Box(a,b,this);
            this.campos[a][b]=aux;
            super.add(aux);
1

1 Answers

1
votes

You need to set this gdx.input.setinputprocessor to either the stage holding your actors or whatever actor you want to have the listeners work on.