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");
}
});
}
好吧,我认为我正在使用addListener,所以我真的不明白为什么程序永远不会检测到touchDown。我正在打印很多演员,但是没有人可以检测到touchDown。 边界运作良好:
我的节目中没有听众,因此无法在其他方面处理。现在我只有一个演员
嗯,我想我应该提供更多信息。 这是控制游戏所有逻辑的类。扩展表。
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);
}
.../
这是我实现屏幕界面的抽象类 它只是抽象的空类
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);
}
据我所知,现在我并没有将我的演员与舞台联系起来。舞台可以“看到”一张桌子,但不能“看到”演员。我怎么能连接演员们的舞台?
好的,请求帮忙。问题解决了 对于会发现同样问题的人 如果你有类扩展表,你的数据中的所有演员都需要添加到你的课程中 我解决了改变
this.campos[a][b]=new Box(a,b,this);
的
aux=new Box(a,b,this);
this.campos[a][b]=aux;
super.add(aux);
答案 0 :(得分:1)
您需要将此gdx.input.setinputprocessor
设置为持有演员的舞台或您希望侦听器处理的任何演员。