libgdx 游戏摇杆
来源:互联网 发布:c语言算法 指导书 编辑:程序博客网 时间:2024/05/01 06:25
核心代码
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 FirstGame implements ApplicationListener { Stage stage; Touchpad touchpad; Texture texture; Texture killer; SpriteBatch batch; TextureRegionDrawable background; TextureRegionDrawable knobRegion; TouchpadStyle touchpadStyle; int speed = 3; int x = 0; int y = 0; @Override public void create() { stage = new Stage(); Gdx.input.setInputProcessor(stage); batch = new SpriteBatch(); texture = new Texture(Gdx.files.internal("data/touchpad.png")); killer = new Texture(Gdx.files.internal("data/2.png")); background = new TextureRegionDrawable(new TextureRegion(texture, 0, 0, 128, 128)); knobRegion = new TextureRegionDrawable(new TextureRegion(texture, 128, 0, 128, 128)); touchpadStyle = new TouchpadStyle(background, knobRegion); touchpad = new Touchpad(15, touchpadStyle); touchpad.setBounds(0, 0, 150, 150); stage.addActor(touchpad); } public void update() { if (touchpad.isTouched()) { x += touchpad.getKnobPercentX() * speed; y += touchpad.getKnobPercentY() * speed; } } @Override public void dispose() { } @Override public void render() { Gdx.gl.glClearColor(1, 1, 1, 1); Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT); update(); batch.begin(); batch.draw(killer, x ,y, 50, 50); batch.end(); stage.act(); stage.draw(); } @Override public void resize(int width, int height) { } @Override public void pause() { } @Override public void resume() { }}
0 0
- (libgdx小结)游戏摇杆
- libgdx 游戏摇杆
- liggdx 游戏摇杆类
- Android手机游戏摇杆
- 360度游戏摇杆
- 手机游戏的摇杆
- GameRocker: 360°游戏摇杆
- cocos2d-x游戏摇杆开发
- Arduino使用游戏摇杆joystick
- libgdx游戏引擎教程
- libgdx游戏引擎教程
- libgdx,android游戏框架
- Libgdx开发ios游戏
- libgdx游戏引擎(一)
- (libgdx小结)游戏地图
- (libgdx小结)游戏对话框
- libgdx 游戏走起
- libgdx 游戏设计思路
- 【LeetCode】Subsets & Subsets II
- 红黑树源码与剖析
- GDCPC 2008:I Table tennis
- Flex PopUpManager方法总结
- C++不懂的问题
- libgdx 游戏摇杆
- UVA 11549 - Calculator Conundrum
- Manacher算法--O(n)回文子串算法
- day_8 MV模式,使业务逻辑和网页页面分开,实现低耦合,体现java封装特性
- Portal之Portlet如何与容器交互
- 关系是生产力
- 滚动处理
- 转:Synergy让一个鼠标一个键盘操作多台电脑
- 最长回文字串