最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

java實現(xiàn)菜單滑動效果

 更新時間:2015年03月30日 16:30:19   投稿:hebedich  
這篇文章主要介紹了java實現(xiàn)菜單滑動效果,效果非常棒,這里推薦給大家,有需要的小伙伴可以參考下。

菜單滑動效果的實現(xiàn)

public class MenuScrollerActivity extends BaseGameActivity implements IScrollDetectorListener, IOnSceneTouchListener, IClickDetectorListener {
    
    // ===========================================================
    // Constants
    // ===========================================================
    protected static int CAMERA_WIDTH = 480;
    protected static int CAMERA_HEIGHT = 320;
 
    protected static int FONT_SIZE = 24;
    protected static int PADDING = 50;
     
    protected static int MENUITEMS = 7;
     
 
    // ===========================================================
    // Fields
    // ===========================================================
    private Scene mScene;
    private Camera mCamera;
 
    private Font mFont; 
    private BitmapTextureAtlas mFontTexture;   
     
    private BitmapTextureAtlas mMenuTextureAtlas;    
    private TextureRegion mMenuLeftTextureRegion;
    private TextureRegion mMenuRightTextureRegion;
     
    private Sprite menuleft;
    private Sprite menuright;
 
    // Scrolling
    private SurfaceScrollDetector mScrollDetector;
    private ClickDetector mClickDetector;
 
    private float mMinX = 0;
    private float mMaxX = 0;
    private float mCurrentX = 0;
    private int iItemClicked = -1;
     
    private Rectangle scrollBar;    
    private List<TextureRegion> columns = new ArrayList<TextureRegion>();
 
    // ===========================================================
    // Constructors
    // ===========================================================
 
    // ===========================================================
    // Getter & Setter
    // ===========================================================
 
    // ===========================================================
    // Methods for/from SuperClass/Interfaces
    // ===========================================================
 
    @Override
    public void onLoadResources() {
        // Paths
        FontFactory.setAssetBasePath("font/");
        BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("gfx/");
 
        // Font
        this.mFontTexture = new BitmapTextureAtlas(256, 256);
        this.mFont = FontFactory.createFromAsset(this.mFontTexture, this, "Plok.TTF", FONT_SIZE, true, Color.BLACK);
        this.mEngine.getTextureManager().loadTextures(this.mFontTexture);
        this.mEngine.getFontManager().loadFonts(this.mFont);
         
        //Images for the menu
        for (int i = 0; i < MENUITEMS; i++) {        
          BitmapTextureAtlas mMenuBitmapTextureAtlas = new BitmapTextureAtlas(256,256, TextureOptions.BILINEAR_PREMULTIPLYALPHA);
          TextureRegion mMenuTextureRegion = BitmapTextureAtlasTextureRegionFactory.createFromAsset(mMenuBitmapTextureAtlas, this, "menu"+i+".png", 0, 0);
           
          this.mEngine.getTextureManager().loadTexture(mMenuBitmapTextureAtlas);
          columns.add(mMenuTextureRegion);
           
           
        }
        //Textures for menu arrows
        this.mMenuTextureAtlas = new BitmapTextureAtlas(128,128, TextureOptions.BILINEAR_PREMULTIPLYALPHA);
        this.mMenuLeftTextureRegion = BitmapTextureAtlasTextureRegionFactory.createFromAsset(mMenuTextureAtlas, this, "menu_left.png", 0, 0);
        this.mMenuRightTextureRegion = BitmapTextureAtlasTextureRegionFactory.createFromAsset(mMenuTextureAtlas, this, "menu_right.png",64, 0);
        this.mEngine.getTextureManager().loadTexture(mMenuTextureAtlas);
      
    }
 
    @Override
    public Engine onLoadEngine() {
        this.mCamera = new Camera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT);
 
        final EngineOptions engineOptions = new EngineOptions(true, ScreenOrientation.LANDSCAPE, new FillResolutionPolicy(), this.mCamera);
        engineOptions.getTouchOptions().setRunOnUpdateThread(true);
 
        final Engine engine = new Engine(engineOptions);
        return engine;
    }
 
    @Override
    public Scene onLoadScene() {
        this.mEngine.registerUpdateHandler(new FPSLogger());
 
        this.mScene = new Scene();
        this.mScene.setBackground(new ColorBackground(0, 0, 0));
        
        this.mScrollDetector = new SurfaceScrollDetector(this);
        this.mClickDetector = new ClickDetector(this);
 
        this.mScene.setOnSceneTouchListener(this);
        this.mScene.setTouchAreaBindingEnabled(true);
        this.mScene.setOnSceneTouchListenerBindingEnabled(true);
 
        CreateMenuBoxes();
 
        return this.mScene;
 
    }
 
    @Override
    public boolean onSceneTouchEvent(final Scene pScene, final TouchEvent pSceneTouchEvent) {
        this.mClickDetector.onTouchEvent(pSceneTouchEvent);
        this.mScrollDetector.onTouchEvent(pSceneTouchEvent);
        return true;
    }
 
    @Override
    public void onScroll(final ScrollDetector pScollDetector, final TouchEvent pTouchEvent, final float pDistanceX, final float pDistanceY) {
 
        //Disable the menu arrows left and right (15px padding)
        if(mCamera.getMinX()<=15)
           menuleft.setVisible(false);
         else
           menuleft.setVisible(true);
         
         if(mCamera.getMinX()>mMaxX-15)
           menuright.setVisible(false);
         else
           menuright.setVisible(true);
           
        //Return if ends are reached
        if ( ((mCurrentX - pDistanceX) < mMinX) ){          
          return;
        }else if((mCurrentX - pDistanceX) > mMaxX){
           
          return;
        }
         
        //Center camera to the current point
        this.mCamera.offsetCenter(-pDistanceX,0 );
        mCurrentX -= pDistanceX;
           
        
        //Set the scrollbar with the camera
        float tempX =mCamera.getCenterX()-CAMERA_WIDTH/2;
        // add the % part to the position
        tempX+= (tempX/(mMaxX+CAMERA_WIDTH))*CAMERA_WIDTH;   
        //set the position
        scrollBar.setPosition(tempX, scrollBar.getY());
         
        //set the arrows for left and right
        menuright.setPosition(mCamera.getCenterX()+CAMERA_WIDTH/2-menuright.getWidth(),menuright.getY());
        menuleft.setPosition(mCamera.getCenterX()-CAMERA_WIDTH/2,menuleft.getY());
         
        
         
        //Because Camera can have negativ X values, so set to 0
        if(this.mCamera.getMinX()<0){
          this.mCamera.offsetCenter(0,0 );
          mCurrentX=0;
        }
         
 
    }
 
    @Override
    public void onClick(ClickDetector pClickDetector, TouchEvent pTouchEvent) {
        loadLevel(iItemClicked);
    };
 
    // ===========================================================
    // Methods
    // ===========================================================
     
    private void CreateMenuBoxes() {
       
       int spriteX = PADDING;
       int spriteY = PADDING;
       
       //current item counter
       int iItem = 1;
 
       for (int x = 0; x < columns.size(); x++) {
         
         //On Touch, save the clicked item in case it's a click and not a scroll.
         final int itemToLoad = iItem;
         
         Sprite sprite = new Sprite(spriteX,spriteY,columns.get(x)){
           
           public boolean onAreaTouched(final TouchEvent pSceneTouchEvent, final float pTouchAreaLocalX, final float pTouchAreaLocalY) {
             iItemClicked = itemToLoad;
             return false;
           }           
         };         
         iItem++;
         
         
         this.mScene.attachChild(sprite);         
         this.mScene.registerTouchArea(sprite);         
  
         spriteX += 20 + PADDING+sprite.getWidth();
      }
       
       mMaxX = spriteX - CAMERA_WIDTH;
       
       //set the size of the scrollbar
       float scrollbarsize = CAMERA_WIDTH/((mMaxX+CAMERA_WIDTH)/CAMERA_WIDTH);
       scrollBar = new Rectangle(0,CAMERA_HEIGHT-20,scrollbarsize, 20);
       scrollBar.setColor(1,0,0);
       this.mScene.attachChild(scrollBar);
       
       menuleft = new Sprite(0,CAMERA_HEIGHT/2-mMenuLeftTextureRegion.getHeight()/2,mMenuLeftTextureRegion);
       menuright = new Sprite(CAMERA_WIDTH-mMenuRightTextureRegion.getWidth(),CAMERA_HEIGHT/2-mMenuRightTextureRegion.getHeight()/2,mMenuRightTextureRegion);
       this.mScene.attachChild(menuright);
       menuleft.setVisible(false);
       this.mScene.attachChild(menuleft);
    }
     
     
 
    @Override
    public void onLoadComplete() {
 
    }
 
    //Here is where you call the item load.
    private void loadLevel(final int iLevel) {
        if (iLevel != -1) {
            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                       
                    Toast.makeText(MenuScrollerActivity.this, "Load Item" + String.valueOf(iLevel), Toast.LENGTH_SHORT).show();
                    iItemClicked = -1;
                }
            });
        }
    }
}

以上所述就是本文的全部內(nèi)容了,希望大家能夠喜歡。

相關(guān)文章

  • MyBatis別名和settings設(shè)置方式

    MyBatis別名和settings設(shè)置方式

    這篇文章主要介紹了MyBatis別名和settings設(shè)置方式,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2021-07-07
  • 基于Java實現(xiàn)QQ郵箱發(fā)送工具類

    基于Java實現(xiàn)QQ郵箱發(fā)送工具類

    我們在日常開發(fā)中,需要實現(xiàn)一個對郵箱的發(fā)送,今天就實現(xiàn)郵箱的發(fā)送工具類,只需要一些注冊郵箱之后的配置即可,感興趣的小伙伴可以了解下
    2023-12-12
  • SpringCloud:feign對象傳參和普通傳參及遇到的坑解決

    SpringCloud:feign對象傳參和普通傳參及遇到的坑解決

    這篇文章主要介紹了SpringCloud:feign對象傳參和普通傳參及遇到的坑解決,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-03-03
  • java中的常見關(guān)鍵字解析

    java中的常見關(guān)鍵字解析

    這篇文章主要介紹了java中的常見關(guān)鍵字,需要的朋友可以參考下
    2014-08-08
  • Java找不到或無法加載主類及編碼錯誤問題的解決方案

    Java找不到或無法加載主類及編碼錯誤問題的解決方案

    今天小編就為大家分享一篇關(guān)于Java找不到或無法加載主類及編碼錯誤問題的解決方案,小編覺得內(nèi)容挺不錯的,現(xiàn)在分享給大家,具有很好的參考價值,需要的朋友一起跟隨小編來看看吧
    2019-02-02
  • Java數(shù)據(jù)結(jié)構(gòu)之簡單的連接點(link)實現(xiàn)方法示例

    Java數(shù)據(jù)結(jié)構(gòu)之簡單的連接點(link)實現(xiàn)方法示例

    這篇文章主要介紹了Java數(shù)據(jù)結(jié)構(gòu)之簡單的連接點(link)實現(xiàn)方法,涉及java指針指向節(jié)點的相關(guān)使用技巧,需要的朋友可以參考下
    2017-10-10
  • Java的訪問修飾符與變量的作用域講解

    Java的訪問修飾符與變量的作用域講解

    這篇文章主要介紹了Java的訪問修飾符與變量的作用域講解,是Java入門學(xué)習(xí)中的基礎(chǔ)知識,需要的朋友可以參考下
    2015-09-09
  • mybatis-plus中更新null值的問題解決

    mybatis-plus中更新null值的問題解決

    本文主要介紹 mybatis-plus 中常使用的 update 相關(guān)方法的區(qū)別,以及更新 null 的方法,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2024-04-04
  • java 多線程饑餓現(xiàn)象的問題解決方法

    java 多線程饑餓現(xiàn)象的問題解決方法

    這篇文章主要介紹了java 多線程饑餓現(xiàn)象的問題解決方法的相關(guān)資料,需要的朋友可以參考下
    2017-06-06
  • spring boot測試打包部署的方法

    spring boot測試打包部署的方法

    spring boot項目如何測試,如何部署,在生產(chǎn)中有什么好的部署方案嗎?這篇文章就來介紹一下spring boot 如何開發(fā)、調(diào)試、打包到最后的投產(chǎn)上線,感興趣的朋友一起看看吧
    2018-01-01

最新評論

原平市| 夏津县| 金寨县| 宿州市| 博野县| 三穗县| 海城市| 钟祥市| 唐海县| 方城县| 和政县| 通城县| 兰州市| 聊城市| 揭东县| 东乌| 张家界市| 交城县| 莱州市| 大英县| 黄大仙区| 交口县| 上饶市| 理塘县| 阜城县| 汪清县| 沁阳市| 大冶市| 紫金县| 新宁县| 古丈县| 台山市| 鲜城| 邳州市| 松阳县| 定陶县| 珲春市| 九江市| 武强县| 湘西| 西青区|