首页 > 其他分享 >libgdx——常见UI的使用

libgdx——常见UI的使用

时间:2023-04-12 10:02:05浏览次数:38  
标签:badlogic gdx libgdx 常见 UI void import com public


libgdx——常见UI的使用_ide


libgdx——常见UI的使用_ide_02


libgdx——常见UI的使用_2d_03


libgdx——常见UI的使用_2d_04


libgdx——常见UI的使用_2d_05


libgdx——常见UI的使用_Image_06


label

package com.doodle.uitest;

import com.badlogic.gdx.ApplicationListener;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.GL10;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.Label.LabelStyle;

public class FirstGame implements ApplicationListener {

	private Stage stage;
	private BitmapFont font;
	private LabelStyle style;
	private Label label;
	
	@Override
	public void create() {
		font = new BitmapFont(Gdx.files.internal("hhjd.fnt"),Gdx.files.internal("hhjd.png"),false);//file,image,flip(是否翻转)
		
		style = new LabelStyle(font,font.getColor());//所使用的字符库,和字符的颜色
		label = new Label("Hello potato",style);//两个参数分别为:要显示的内容,labelstyle
		stage = new Stage(400,320,false);
		
		label.setPosition(50, 150);
		label.setFontScale(2);
		label.setColor(Color.GREEN);
		
		stage.addActor(label);
		
		Gdx.input.setInputProcessor(stage);
	}

	@Override
	public void dispose() {
		// TODO Auto-generated method stub

	}

	@Override
	public void pause() {
		// TODO Auto-generated method stub

	}

	@Override
	public void render() {
		Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
		
		stage.act();
		stage.draw();
		
	}

	@Override
	public void resize(int arg0, int arg1) {
		// TODO Auto-generated method stub

	}

	@Override
	public void resume() {
		// TODO Auto-generated method stub

	}

}



iamge

package com.doodle.uitest;

import com.badlogic.gdx.ApplicationListener;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.GL10;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.Label.LabelStyle;

public class FirstGame implements ApplicationListener {

	private Stage stage;
	private Image image;
	private Texture texture;
	private TextureRegion region;
	
	@Override
	public void create() {
		stage = new Stage(480,320,false);
		Gdx.input.setInputProcessor(stage);
		
		texture = new Texture(Gdx.files.internal("image2.jpg"));
		region = new TextureRegion(texture,0,0,512,512);
		image = new Image(region);
		
		image.setColor(Color.PINK);//设置图片的颜色
		image.setScale(0.5f);//设置图片的缩放大小
		image.setPosition(230, 40);//设置图片的位置
		image.setOrigin(0, 0);//设置旋转中心
		image.setRotation(45);//设置旋转角度
		image.setSize(300, 300);//设置大小
		
		stage.addActor(image);
	}

	@Override
	public void dispose() {
		// TODO Auto-generated method stub

	}

	@Override
	public void pause() {
		// TODO Auto-generated method stub

	}

	@Override
	public void render() {
		Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
		
		stage.act();
		stage.draw();
		
	}

	@Override
	public void resize(int arg0, int arg1) {
		// TODO Auto-generated method stub

	}

	@Override
	public void resume() {
		// TODO Auto-generated method stub

	}

}




button

package com.doodle.uitest;

import com.badlogic.gdx.ApplicationListener;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.GL10;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.badlogic.gdx.scenes.scene2d.ui.ImageButton;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.Label.LabelStyle;
import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable;

public class FirstGame implements ApplicationListener {

	private Stage stage;
	
	private TextureRegionDrawable up;
	private TextureRegionDrawable down;
	private TextureRegion buttonUp;
	private TextureRegion buttonDown;
	private Texture text;
	private ImageButton button;
	
	
	@Override
	public void create() {
		stage = new Stage(480,320,false);
		Gdx.input.setInputProcessor(stage);
		
		text = new Texture(Gdx.files.internal("image2.jpg"));
		TextureRegion[][] temp = TextureRegion.split(text, 120, 120);
		
		buttonUp = temp[0][0];
		buttonDown = temp[0][1];
		
		up = new TextureRegionDrawable(buttonUp);
		down = new TextureRegionDrawable(buttonDown);
		
		button = new ImageButton(up, down);
		
		stage.addActor(button);
		
	}

	@Override
	public void dispose() {
		// TODO Auto-generated method stub

	}

	@Override
	public void pause() {
		// TODO Auto-generated method stub

	}

	@Override
	public void render() {
		Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
		
		stage.act();
		stage.draw();
		
	}

	@Override
	public void resize(int arg0, int arg1) {
		// TODO Auto-generated method stub

	}

	@Override
	public void resume() {
		// TODO Auto-generated method stub

	}

}




标签:badlogic,gdx,libgdx,常见,UI,void,import,com,public
From: https://blog.51cto.com/u_5290007/6185102

相关文章

  • 【AGC】崩溃服务数据上报常见的几个问题
    最近开发者使用崩溃服务遇到的一些数据异常问题,我在这里汇总一下,以后遇到相似的问题可以以此为参考。 【问题描述1】iOS崩溃数据“按用户搜索”页,“过去7天”是有数据的,但“统计”页没有。​​【解决方案】查询了后台上报日志,发现没有上报应用的启动事件,只上报了$HA_ERRO......
  • 【THM】Burp Suite:Extender(Burp Suite-扩展器)-学习
    本文相关的TryHackMe实验房间链接:https://tryhackme.com/room/burpsuiteextender本文相关内容:了解如何使用Extender来扩展BurpSuite的功能Extender-扩展器主界面Extender界面如下图所示:Extender的默认视图将为我们提供已加载到BurpSuite中的扩展的概览,在Extender的Extensi......
  • 三类常见的可积函数积分
    常见可积函数积分三角有理积分令\(tanx\frac{x}{x}=t\)\(\intR(sinx,cosx)dx=\intR(\frac{2t}{1+t^2},\frac{1-t^2}{1+t^2})\frac{2}{1+t^2}\)推导公式\(\tanx与\sinx的转化\)令\(\tan\frac{x}{2}=t\)\(sinx=2*sin\frac{x}{2}*cos\frac{x}{2}\),分......
  • 介绍一个简易的MAUI安卓打包工具
    介绍一个简易的MAUI安卓打包工具它可以帮助进行MAUI安卓的打包。虽然也是用MAUI写的,但是只考虑了Windows版本,mac还不太会。没什么高级的功能,甚至很简陋,它能做的,只是节省你从MAUI官方文档复制命令行命令的时间开源地址:https://github.com/Yu-Core/MAUIAndroidReleaseTool......
  • 微信小程序开发——getLocation:fail the api need to be declared in the requiredPr
    getLocation:failtheapineedtobedeclaredintherequiredPrivateInfosfieldinapp.json/ext.json异常解析:app.json中没配置requiredPrivateInfos参数,按下边示例代码配置即可。示例代码:{..."permission":{"scope.userLocation":{"desc&qu......
  • 基于elementui的Tree虚线,实线绘制,以及懒加载,如图
     加减号用的是阿里的矢量图标库。自行去下载 路径:https://www.iconfont.cn/home/index?spm=a313x.7781069.1998910419.2 <template><divclass="content-box"><divclass="content-top-lable">系统设置</div><divstyle="padd......
  • UIScrollView SnapKit使用
    直接上代码,看ViewDidLoad方法中的注释。一共10个约束,UIScrollView上下左右4个,其子试图contentView上下左右宽高6个。注意点:(以要求可以上下滚动为例,可以先看完代码再回头理解注意事项)1、contentView的宽高根据需求设置优先级,哪边需要滚动,优先级就必须低,因此这里设置高度优先......
  • vue3使用elmentui-plus中的图标
    按照官网这样直接引入使用,不知道为啥行不通:import{Document,MenuasIconMenu,Location,Setting,}from'@element-plus/icons-vue'使用时,需要<script>import{UserFilled}from'@element-plus/icons-vue'//使用的时候需要单独引入这个图标从......
  • html概览和head常见标签,body内标签布局
    前端与后端的概念前端 任何与用户直接打交道的操作界面都可以称之为前端>>>:接待员后端 不直接与用户打交道主要负责内部真正的业务逻辑的执行>>>:幕后操作者前端学习之路 专业的前端也需要培训至少六个月而我们作为后端开发工程师前端只学最基本最核心的一块目的不是......
  • Power BI里面常见的图标
      数值列:列值是数字    日期列:列值是日期 计算列(数字):添加的计算列,列值是数字   计算列(非数字):添加的计算列,列值不是数字    字段的层次结构:比如日期字段,就可以分成年、季度、月、日展示 文件夹:字段的分组,可以将一个/多个列或者度量......