liggdx 游戏摇杆类
来源:互联网 发布:2016年饮料行业数据 编辑:程序博客网 时间:2024/05/01 13:46
运行结果
核心代码:
package com.example.androidgame12mapnew;import javax.microedition.khronos.opengles.GL10;import com.badlogic.gdx.ApplicationListener;import com.badlogic.gdx.Gdx;import com.badlogic.gdx.graphics.Texture;import com.badlogic.gdx.graphics.g2d.SpriteBatch;import com.badlogic.gdx.graphics.g2d.TextureRegion;import com.badlogic.gdx.scenes.scene2d.Stage;import com.badlogic.gdx.scenes.scene2d.ui.Touchpad;import com.badlogic.gdx.scenes.scene2d.ui.Touchpad.TouchpadStyle;import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable;public class MyGame implements ApplicationListener {SpriteBatch batch;Stage stage;Touchpad touchpad;float x = 10;float y = 10;float speed = 1;Texture show1;@Overridepublic void create() {stage = new Stage();batch = new SpriteBatch();show1 = new Texture(Gdx.files.internal("data/show1.png"));TextureRegionDrawable background = new TextureRegionDrawable(new TextureRegion(new Texture(Gdx.files.internal("data/touchpad_bg.png"))));TextureRegionDrawable knob = new TextureRegionDrawable(new TextureRegion(new Texture(Gdx.files.internal("data/touchpad_knob.png"))));TouchpadStyle touchpadStyle = new TouchpadStyle(background, knob);touchpad = new Touchpad(3, touchpadStyle);touchpad.setSize(touchpad.getWidth(), touchpad.getHeight());touchpad.setPosition(touchpad.getWidth() / 4, 0);Gdx.input.setInputProcessor(stage);stage.addActor(touchpad);}public void update() {if (touchpad.isTouched()) {x += touchpad.getKnobPercentX() * speed;y += touchpad.getKnobPercentY() * speed;if (x < 20)x = 20;if (x > Gdx.graphics.getWidth() - 120)x = Gdx.graphics.getWidth() - 120;if (y < 20)y = 20;if (y > Gdx.graphics.getHeight() - 120)y = Gdx.graphics.getHeight() - 120;}}@Overridepublic void render() {Gdx.gl.glClearColor(1, 1, 1, 1);Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);update();batch.begin();batch.draw(show1, x, y, 100, 100);batch.end();stage.act();stage.draw();}@Overridepublic void resize(int arg0, int arg1) {// TODO Auto-generated method stub}@Overridepublic void resume() {// TODO Auto-generated method stub}@Overridepublic void dispose() {// TODO Auto-generated method stub}@Overridepublic void pause() {// TODO Auto-generated method stub}}
封装的摇杆工具类
0 0
- liggdx 游戏摇杆类
- liggdx 实现摇杆控制角色移动
- (libgdx小结)游戏摇杆
- libgdx 游戏摇杆
- Android手机游戏摇杆
- 360度游戏摇杆
- 手机游戏的摇杆
- GameRocker: 360°游戏摇杆
- cocos2d-x游戏摇杆开发
- Arduino使用游戏摇杆joystick
- 摇杆
- 摇杆
- 360°平滑游戏摇杆 Rocker
- cocos2d-x游戏摇杆的实现方法
- 用SurfaceView实现Android游戏摇杆
- 游戏摇杆之Easy Touch 3教程
- 游戏摇杆之Easy Touch 3教程
- iPhone游戏中模拟摇杆的教程
- poj3660Cow Contest
- Warning: strftime() [function.strftime]: It is not safe to rely on the system's timezone settings.
- CGI, FastCGI 理解
- 汽车销售大王朱孝明:18元到2000万的发家致富路
- 实例经验教程:代理服务器架设与维护(代理服务器学习)
- liggdx 游戏摇杆类
- 【MySQL 复制】20G以下的mysql数据库从库快速搭建
- python中的异常处理
- C#调用 Oracle 存储过程例子代码
- make a package for tcl << Tcl/Tk
- java demo在eclips编译正常 在命令行编译报错问题
- modprobe 命令
- TreeSet 集合
- BCD码、十六进制与十进制互转