热门标签 | HotTags
当前位置:  开发笔记 > 小程序 > 正文

java实现菜单滑动效果

这篇文章主要介绍了java实现菜单滑动效果,效果非常棒,这里推荐给大家,有需要的小伙伴可以参考下。

菜单滑动效果的实现

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 columns = new ArrayList();
 
    // ===========================================================
    // 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 mMaxX-15)
           menuright.setVisible(false);
         else
           menuright.setVisible(true);
           
        //Return if ends are reached
        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 

以上所述就是本文的全部内容了,希望大家能够喜欢。


推荐阅读
author-avatar
骏马奔腾09
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有