nanshaws / LibgdxTutorial

libgdx 教程项目 本项目旨在提供完整的libgdx桌面教程,帮助开发者快速掌握libgdx游戏开发框架的使用。成功的将gdx-ai和ashley的tests从官网剥离出来,并成功运行。libgdx tutorial project This project aims to provide a complete libgdx desktop tutorial to help developers quickly master the use of libgdx game development framework. Successfully separated GDX-AI and Ashley's tests from the official website and ran them
34 stars 5 forks source link

ui控件找不到问题 #9

Open Monsterimpl opened 2 months ago

Monsterimpl commented 2 months ago

package com.mygdx.game;

import com.badlogic.gdx.ApplicationAdapter; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.graphics.GL20; import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.scenes.scene2d.Stage; import com.badlogic.gdx.scenes.scene2d.ui.Button; import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable; import com.badlogic.gdx.utils.viewport.StretchViewport;

public class MyGame3 extends ApplicationAdapter {

//图片控件

Stage stage;

Button button;

Texture up;

Texture drown;

TextureRegionDrawable u;

TextureRegionDrawable d;

@Override
public void create() {

    up = new Texture(Gdx.files.internal("anniu/QQ20240820-103716.png"));
    drown = new Texture(Gdx.files.internal("anniu/QQ20240820-103704.png"));

    u = new TextureRegionDrawable(up);
    d = new TextureRegionDrawable(drown);

    // 创建ButtonStyle
    Button.ButtonStyle style = new Button.ButtonStyle();
    style.up = u;
    style.down = d;

    // 创建按钮
    button = new Button(style);

    stage = new Stage(new StretchViewport(800, 480));

    stage.addActor(button);

    button.setPosition(100, 100);

}

@Override
public void render() {
    Gdx.gl.glClearColor(1, 1, 1, 1);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
    stage.act();

    stage.draw();

}

@Override
public void dispose() {
    stage.dispose();
}

} 点击图片按钮没有变化不知道为什么(图片文件路径没有问题)

Monsterimpl commented 2 months ago
    Gdx.input.setInputProcessor(stage);将对应演员所在的舞台作为参数传递