模拟移动选择图片,采用相机实现。

 package com.fxb.newtest;

 import com.badlogic.gdx.ApplicationAdapter;
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.glutils.ShapeRenderer;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer.ShapeType;
import com.badlogic.gdx.input.GestureDetector;
import com.badlogic.gdx.input.GestureDetector.GestureAdapter;
import com.badlogic.gdx.scenes.scene2d.Action;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.actions.Actions;
import com.badlogic.gdx.scenes.scene2d.ui.Image; public class Lib025_PicChange extends ApplicationAdapter{ GestureAdapter gestureAdapter = new GestureAdapter(){
@Override
public boolean fling(float velocityX, float velocityY, int button) {
// TODO Auto-generated method stub
/* if( velocityX > 0 ){
System.out.println( "fling right" );
stage.getCamera().translate( -stage.getWidth(), 0, 0 );
}
else{
System.out.println( "fling left" );
stage.getCamera().translate( stage.getWidth(), 0, 0 );
}*/ return super.fling(velocityX, velocityY, button);
} @Override
public boolean pan(float x, float y, float deltaX, float deltaY) {
// TODO Auto-generated method stub
System.out.println( "pan" );
if( index>0 && deltaX>0 || index<imgs.length-1 && deltaX<0 ){
stage.getCamera().translate( -deltaX, 0, 0 );
add = deltaX > 0? -1: 1;
} return super.pan(x, y, deltaX, deltaY);
} @Override
public boolean panStop(float x, float y, int pointer, int button) {
// TODO Auto-generated method stub
System.out.println( "pan stop" );
if( index>0 && add==-1 || index<imgs.length-1 && add==1 ){
index += add;
stage.getCamera().position.set( index*500+stage.getWidth()/2, stage.getHeight()/2, 0 );
}
return super.panStop(x, y, pointer, button);
} };
GestureDetector detector = new GestureDetector( gestureAdapter ); Stage stage;
Image img1, img2, img3, img4;
Image[] imgs;
int index;
int add = 0;
ShapeRenderer rend; @Override
public void create() {
// TODO Auto-generated method stub
super.create();
Gdx.input.setInputProcessor( detector ); img1 = new Image( new Texture( Gdx.files.internal( "data/pal4_0.jpg" ) ) );
img2 = new Image( new Texture( Gdx.files.internal( "data/pal4_1.jpg" ) ) );
img3 = new Image( new Texture( Gdx.files.internal( "data/pal4_2.jpg" ) ) );
img4 = new Image( new Texture( Gdx.files.internal( "data/pal4_3.jpg" ) ) ); stage = new Stage();
stage.addActor( img1 );
stage.addActor( img2 );
stage.addActor( img3 );
stage.addActor( img4 ); imgs = new Image[]{ img1, img2, img3, img4 }; for( int i=0; i<imgs.length; ++i ){
imgs[i].setSize( 400, 240 );
imgs[i].setPosition( i*500 + stage.getWidth()/2-imgs[i].getWidth()/2, stage.getHeight()/2-imgs[i].getHeight()/2 );
} //imgs[1].setVisible( false );
//imgs[2].setVisible( false );
index = 0;
rend = new ShapeRenderer();
} @Override
public void render() {
// TODO Auto-generated method stub
super.render();
Gdx.gl.glClearColor( 1, 1, 1, 1 );
Gdx.gl.glClear( GL10.GL_COLOR_BUFFER_BIT );
stage.act();
stage.draw(); rend.begin( ShapeType.Filled );
rend.setColor( Color.LIGHT_GRAY );
rend.rect( 0, 0, 100, 480 );
rend.rect( 700, 0, 100, 480 );
rend.rect( 100, 0, 700, 60 );
rend.rect( 100, 420, 700, 60 );
rend.end(); } @Override
public void dispose() {
// TODO Auto-generated method stub
rend.dispose();
stage.dispose();
super.dispose();
} }

运行结果:

libgdx学习记录23——图片移动选择的更多相关文章

  1. libgdx学习记录19——图片动态打包PixmapPacker

    libgdx中,opengl 1.x要求图片长宽必须为2的整次幂,一般有如下解决方法 1. 将opengl 1.x改为opengl 2.0.(libgdx 1.0版本后不支持1.x,当然不存在这个问题 ...

  2. libgdx学习记录1——图片显示Texture

    libgdx底层采用opengl渲染,对图片进行了优化处理,与android原生态的bitmap不太一样. 相比而言,效率要高一些,不过只支持png,jpg,bmp三种格式. 显示中,一般将图片放在a ...

  3. libgdx学习记录20——多线程MultiThread资源处理

    在libgdx中,一般的逻辑流程都在rende()函数中执行,这个函数是由opengl的渲染线程调用的,一般的图形显示和逻辑处理都在这个线程中. 一般情形下,在这个线程中处理就行了.但是当某些逻辑处理 ...

  4. libgdx学习记录17——照相机Camera

    照相机在libgdx中的地位举足轻重,贯穿于整个游戏开发过程的始终.一般我们都通过Stage封装而间接使用Camera,同时我们也可以单独使用Camera以完成背景的移动.元素的放大.旋转等操作. C ...

  5. libgdx学习记录16——资源加载器AssetManager

    AssetManager用于对游戏中的资源进行加载.当游戏中资源(图片.背景音乐等)较大时,加载时会需要较长时间,可能会阻塞渲染线程,使用AssetManager可以解决此类问题. 主要优点: 1. ...

  6. libgdx学习记录11——平铺地图TiledMap

    地图对于游戏场景十分重要,很多游戏都需要对地图进行编辑,可使用TileMap进行编辑并生成对应的tmx格式地图文件. 编辑好后,可通过TmxMapLoader来读取地图文件.可通过一个正交相机Otho ...

  7. libgdx学习记录6——动作Action

    libgdx中的Action类能够有效的帮助我们实现位移.旋转.缩放.淡入淡出等效果,对游戏的设计很有用. Action是一个抽象类,本身不可以实例化.一般使用的它的继承类,常用的有 MoveToAc ...

  8. libgdx学习记录5——演员Actor

    Actor也是libgdx中非常重要的一个元素,一般与stage配合一起使用.Actor能够设置大小,位置,旋转和动画等. 我们自定义的Actor一般需要继承于Actor,并且重写其中的act和dra ...

  9. libgdx学习记录4——舞台Stage

    libgdx总的来说是一个框架,而不是一个成熟的游戏引擎.Stage是其中一个比较好的封装,里面自带Camera.SpriteBatch等常用渲染绘图工具. 下面是一个简单的添加图片,并让镜头左右上下 ...

随机推荐

  1. eclipse中svn插件的工程不能与svn资源库同步的解决方法

    eclipse中svn插件的工程不能与svn资源库同步的解决办法 最近几天自己的工程与资源库同步总是出现问题,重启机器后发现资源库丢失了,无法进行同步. 解决办法如下: 1.右键工程---->选 ...

  2. Oracle EBS AP 取消付款

    --取消付款 created by jenrry 20170425 declare l_return_status varchar2(50); l_msg_count number; l_msg_da ...

  3. Linux命令(自学)

    1.立刻关机: shutdown -h now 2.立刻重启: shutdown -r now reboot 3.注销: logout 4.进入vi编辑器,写一个hello的java程序: vi he ...

  4. 使用Amanda ZRM备份远程MySQL数据库

    本文写道最后的时候,我才发现ZRM for MySQL的一个致命问题,就我目前的理解和测试来看,它恢复数据的时候是采取覆盖的方式,举个例子,假定某台数据库服务器上有两个数据库test1,test2,你 ...

  5. IBM ServerGuide引导盘全系列下载网址

    IBM ServerGuide引导盘全系列下载网址 官网链接 https://www.ibm.com/support/home/docdisplay?lndocid=SERV-GUIDE v9.30 ...

  6. Skype 服务器客户端策略参数优化

    1.skype通讯录原理 对于skype客户端的通讯录同步,首先说说原理,通讯簿信息是从AD同步的skype前端服务器(每天1:30),在从前端服务器同步的客户端(大概1小时内同步一次). skype ...

  7. [LOJ 2146][BZOJ 4873][Shoi2017]寿司餐厅

    [LOJ 2146][BZOJ 4873][Shoi2017]寿司餐厅 题意 比较复杂放LOJ题面好了qaq... Kiana 最近喜欢到一家非常美味的寿司餐厅用餐. 每天晚上,这家餐厅都会按顺序提供 ...

  8. MPT树详解

    目录 MPT树定义 MPT树的作用是什么? 前缀树与默克尔树 前缀树 默克尔树 三种节点类型 MPT中的Merkle HP编码 官方表示形式 相关MPT树 参考目录 @ MPT树定义 一种经过改良的. ...

  9. CentOS7安装Java

    通过下载Oracle官网的jdk来安装 不使用openjdk 访问 http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downl ...

  10. 如何安装Firebug

    Firebug是firefox下的一个插件,能够调试所有网站语言,如Html,Css等,但FireBug最吸引我的就是javascript调试功能,使用起来非常方便,而且在各种浏览器下都能使用(IE, ...