Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ui控件找不到问题 #9

Open
Monsterimpl opened this issue Aug 20, 2024 · 1 comment
Open

ui控件找不到问题 #9

Monsterimpl opened this issue Aug 20, 2024 · 1 comment

Comments

@Monsterimpl
Copy link

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
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant