LIBGDX study record 23--picture Move selection

Source: Internet
Author: User

Analog mobile selection of pictures, using the camera implementation.

1  Packagecom.fxb.newtest;2 3 ImportCom.badlogic.gdx.ApplicationAdapter;4 ImportCom.badlogic.gdx.Gdx;5 ImportCom.badlogic.gdx.graphics.Color;6 Importcom.badlogic.gdx.graphics.GL10;7 Importcom.badlogic.gdx.graphics.Texture;8 ImportCom.badlogic.gdx.graphics.glutils.ShapeRenderer;9 ImportCom.badlogic.gdx.graphics.glutils.ShapeRenderer.ShapeType;Ten ImportCom.badlogic.gdx.input.GestureDetector; One ImportCom.badlogic.gdx.input.GestureDetector.GestureAdapter; A Importcom.badlogic.gdx.scenes.scene2d.Action; - ImportCom.badlogic.gdx.scenes.scene2d.Stage; - Importcom.badlogic.gdx.scenes.scene2d.actions.Actions; the ImportCom.badlogic.gdx.scenes.scene2d.ui.Image; -  -  Public classLib025_picchangeextendsapplicationadapter{ -      +Gestureadapter Gestureadapter =NewGestureadapter () { - @Override +          Public BooleanFlingfloatVelocityx,floatVelocityy,intbutton) { A             //TODO auto-generated Method Stub at /*if (Velocityx > 0) { - System.out.println ("Fling Right"); - Stage.getcamera (). Translate (-stage.getwidth (), 0, 0); -             } - else{ - System.out.println ("Fling left"); in Stage.getcamera (). Translate (Stage.getwidth (), 0, 0); -             }*/ to              +             return Super. Fling (Velocityx, Velocityy, button); -         } the  *          $         Panax Notoginseng @Override -          Public BooleanPanfloatXfloatYfloatDeltaX,floatDeltaY) { the             //TODO auto-generated Method Stub +SYSTEM.OUT.PRINTLN ("Pan" ); A             if(index>0 && deltax>0 | | index ){ theStage.getcamera (). Translate (-deltax, 0, 0 ); +Add = deltax > 0? -1:1;  -             }             $              $             return Super. Pan (x, Y, DeltaX, deltay); -         } -  the  - Wuyi @Override the          Public BooleanPanstop (floatXfloatYintPointerintbutton) { -             //TODO auto-generated Method Stub WuSYSTEM.OUT.PRINTLN ("Pan Stop" ); -             if(index>0 && add==-1 | | index ){ AboutIndex + =add; $Stage.getcamera (). Position.set (Index*500+stage.getwidth ()/2, Stage.getheight ()/2, 0 );  -             } -             return Super. Panstop (x, y, pointer, button); -         }     A          +          the          -          $     }; theGesturedetector detector =NewGesturedetector (gestureadapter); the      the Stage stage; the Image img1, Img2, IMG3, IMG4; - image[] IMGs; in     intindex; the     intAdd = 0; the shaperenderer rend; About      the @Override the      Public voidCreate () { the         //TODO auto-generated Method Stub +         Super. Create (); - Gdx.input.setInputProcessor (detector); the         BayiIMG1 =NewImage (NewTexture (Gdx.files.internal ("Data/pal4_0.jpg" ) ) ); theImg2 =NewImage (NewTexture (Gdx.files.internal ("Data/pal4_1.jpg" ) ) ); theIMG3 =NewImage (NewTexture (Gdx.files.internal ("Data/pal4_2.jpg" ) ) ); -IMG4 =NewImage (NewTexture (Gdx.files.internal ("Data/pal4_3.jpg" ) ) ); -          thestage =NewStage (); the Stage.addactor (IMG1); the Stage.addactor (IMG2); the Stage.addactor (IMG3); - Stage.addactor (IMG4); the          theIMGs =Newimage[]{img1, Img2, IMG3, img4}; the         94          for(inti=0; ii) { theImgs[i].setsize (400, 240 ); theImgs[i].setposition (i*500 + stage.getwidth ()/2-imgs[i].getwidth ()/2, Stage.getheight ()/2-imgs[i].getheight ()/2 ); the         }98              About         //imgs[1].setvisible (false); -         //imgs[2].setvisible (false);101index = 0;102rend =Newshaperenderer ();103     }104  the @Override106      Public voidrender () {107         //TODO auto-generated Method Stub108         Super. Render ();109Gdx.gl.glClearColor (1, 1, 1, 1 ); the Gdx.gl.glClear (gl10.gl_color_buffer_bit);111 stage.act (); the Stage.draw ();113          the Rend.begin (shapetype.filled); the Rend.setcolor (color.light_gray); theRend.rect (0, 0, 100, 480 );117Rend.rect (700, 0, 100, 480 );118Rend.rect (100, 0, 700, 60 );119Rend.rect (100, 420, 700, 60 ); - rend.end ();121         122     }123 124 @Override the      Public voidDispose () {126         //TODO auto-generated Method Stub127 rend.dispose (); - stage.dispose ();129         Super. Dispose (); the     }131  the}

Operation Result:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.