2017-10-27 3 views

답변

1

이 최소한의 예를 어떻게 당신이 그것을 만지면 무언가를 모바일 장치의 경우 Libgdx 에서 클릭 할 버튼을 만드는 말해 줄 수 있습니다 당신은 코멘트를 달성하려고하는 무엇

package com.mygdx.gtest; 

import com.badlogic.gdx.ApplicationAdapter; 
import com.badlogic.gdx.Gdx; 
import com.badlogic.gdx.graphics.GL20; 
import com.badlogic.gdx.scenes.scene2d.Actor; 
import com.badlogic.gdx.scenes.scene2d.Stage; 
import com.badlogic.gdx.scenes.scene2d.ui.Skin; 
import com.badlogic.gdx.scenes.scene2d.ui.TextButton; 
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener; 

public class Test extends ApplicationAdapter{ 


    private Skin skin; 
    private TextButton button; 
    private Stage stage; 

    @Override 
    public void create() { 
     //make a stage for your button to go on 
     stage = new Stage(); 

     //load a skin(a collection of styles for objects) 
     // skin is from gdx-skins (https://github.com/czyzby/gdx-skins) 
     skin = new Skin(Gdx.files.internal("neon-ui.json")); 

     //create your button 
     button = new TextButton("Button1", skin); 

     //add it to your stage 
     stage.addActor(button); 

     // add a listener to your buttons so it does something when clicked 
     button.addListener(new ChangeListener() { 
      @Override 
      public void changed(ChangeEvent event, Actor actor) { 
       System.out.println("I was clicked"); 
      } 
     }); 

     // set the sgae as the input processor so it will respond to clicks etc 
     Gdx.input.setInputProcessor(stage); 

    } 

    @Override 
    public void render() { 
     //clear the screen 
     Gdx.gl.glClearColor(0.3f, 0.3f, 0.3f, 1f); 
     Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); 

     // tell stage to do action and then draw itself 
     stage.draw(); 
     stage.act(); 
    } 
} 
+0

이것은 좋아 보이지만 그 순간에 할 수있는 시간이 없습니다. 곧 알려 드리겠습니다. –

+0

아니요 내가 원하는 것 –

+0

그것에 대해 작동하지 않는 무엇입니까? 그것은 내 인쇄에 잘 작동합니다 클릭했을 때 "나는 클릭했습니다" – dfour

관련 문제