libgdx中的表有问题

时间:2018-01-08 03:23:42

标签: java android libgdx

package Controller;

import Play.Play;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.physics.box2d.World;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.InputListener;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.badlogic.gdx.utils.viewport.StretchViewport;
import com.badlogic.gdx.utils.viewport.Viewport;
import com.mygdx.game.MyGdxGame;
import player.Player;

public class Controller {
    Viewport viewport;
    MyGdxGame game;
    Stage stage;
    World world;
    public boolean rightpressed,leftpressed;
    OrthographicCamera cam;
    public void Controllermaker(){
        game=new MyGdxGame();
        cam=new OrthographicCamera(MyGdxGame.width/100,MyGdxGame.hight/100);
        viewport=new StretchViewport(MyGdxGame.width/100,MyGdxGame.hight/100,cam);
        stage=new Stage(viewport,MyGdxGame.batch);
        Gdx.input.setInputProcessor(stage);


        Image image=new Image(new Texture("img2.png"));
        Table table=new Table();
        table.left().bottom();
        image.setSize(image.getImageWidth(),image.getHeight());
        table.add();
        table.add(image).size(1,1);
        table.add();
        table.row().pad(5);


        image.addListener(new InputListener(){
            @Override
            public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
                rightpressed=true;
                return true;
            }

            @Override
            public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
                rightpressed=false;
            }
        });
        Image image1=new Image(new Texture("arrow_keys.png"));
        table.add();
        table.add(image1).size(1,1);
        table.add();
        table.row().pad(5);
        image1.addListener(new InputListener(){
            @Override
            public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
                rightpressed=true;
                return true;
            }

            @Override
            public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
                rightpressed=false;
            }
        });

        stage.addActor(table);
        stage.act();
        stage.draw();
    }`

我不知道这个代码有什么问题,但是当我添加第二个图像(imge1)时,两个图像都没有显示但是当我用一个图像启动它时它工作不完美,因为当我改变表的大小时小于0.5时图像消失但是我只能在此表中添加一个图像并且图像显示。

0 个答案:

没有答案