SlideMenuAnimator

  ... the case you feel the need for a new feature or want to submit one.

SlideMenuAnimator

Postby Method » Fri Dec 17, 2010 11:56 pm

Hi there, I'm new to these forums but recently I have been building a small game which I hope to release on the market within the next few days.

Using this engine, I have come to these forums a lot and appreciate all they offer, so I thought I would add a few of the smaller things I have made to hopefully add a little bit back towards the project.

I created a new Menu Animator to allow for a little bit nicer and more thoughtfully laid out menu configuration.
The new animator requires the use of a configuration array, that outlines the positions/actions of the items.

SlideMenuConfig.java
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public class SlideMenuConfig {
  2.     public int menuID;
  3.     public float targetX;
  4.     public float targetY;
  5.     public boolean slideFromLeft;
  6.     public float delay;
  7.     public SlideMenuConfig(int menuID, float targetX, float targetY) {
  8.         this(menuID,targetX,targetY,0);
  9.     }
  10.     public SlideMenuConfig(int menuID, float targetX, float targetY, float delay) {
  11.         this(menuID,targetX,targetY,delay,false);
  12.     }
  13.     public SlideMenuConfig(int menuID, float targetX, float targetY, float delay, boolean slideFromLeft) {
  14.         super();
  15.         this.menuID = menuID;
  16.         this.targetX = targetX;
  17.         this.targetY = targetY;
  18.         this.slideFromLeft = slideFromLeft;
  19.         this.delay = delay;
  20.     }
  21. }
Parsed in 0.012 seconds, using GeSHi 1.0.8.4


SlideMenuAnimator.java
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public class HeightSlideMenuAnimator implements IMenuAnimator {
  2.    
  3.     protected final IEaseFunction mEaseFunction;
  4.    
  5.     static public float SLIDE_DURATION = 1.5f;
  6.    
  7.     static public float LEFT_SLIDE_POINT = -100.0f;
  8.     static public float RIGHT_SLIDE_POINT = 580.0f;
  9.    
  10.     protected final HashMap<Integer, SlideMenuConfig> menuConfig;
  11.    
  12.     public HeightSlideMenuAnimator(HashMap<Integer, SlideMenuConfig> pMenuConfig){
  13.         this(pMenuConfig, IEaseFunction.DEFAULT);
  14.     }
  15.  
  16.     public HeightSlideMenuAnimator(HashMap<Integer, SlideMenuConfig> pMenuConfig,IEaseFunction pEaseFunction) {
  17.         super();
  18.         this.mEaseFunction = pEaseFunction;
  19.         this.menuConfig = pMenuConfig;
  20.     }
  21.  
  22.     public void buildAnimations(final ArrayList<IMenuItem> pMenuItems, final float pCameraWidth, final float pCameraHeight) {
  23.         final int menuItemCount = pMenuItems.size();
  24.         for(int i = 0; i < menuItemCount; i++) {
  25.             final IMenuItem menuItem = pMenuItems.get(i);
  26.             final SlideMenuConfig config = this.menuConfig.get(menuItem.getID());
  27.             final float toX = config.targetX;
  28.             final float baseY = config.targetY;
  29.             final float fromX;
  30.             if(config.slideFromLeft)
  31.             {
  32.                 fromX = LEFT_SLIDE_POINT - ( (toX - LEFT_SLIDE_POINT) * (config.delay/SLIDE_DURATION)  );
  33.             }
  34.             else
  35.             {
  36.                 fromX = RIGHT_SLIDE_POINT - ( (toX - RIGHT_SLIDE_POINT) * (config.delay/SLIDE_DURATION)  );
  37.             }
  38.            
  39.             final MoveModifier moveModifier = new MoveModifier(SLIDE_DURATION+config.delay, fromX, toX, baseY, baseY, mEaseFunction);
  40.             moveModifier.setRemoveWhenFinished(false);
  41.             menuItem.addShapeModifier(moveModifier);
  42.         }
  43.     }
  44.  
  45.     public void prepareAnimations(final ArrayList<IMenuItem> pMenuItems, final float pCameraWidth, final float pCameraHeight) {
  46.         final int menuItemCount = pMenuItems.size();
  47.         for(int i = 0; i < menuItemCount; i++) {
  48.             final IMenuItem menuItem = pMenuItems.get(i);
  49.             final SlideMenuConfig config = this.menuConfig.get(menuItem.getID());
  50.             final float toX = config.targetX;
  51.             final float baseY = config.targetY;
  52.             final float fromX;
  53.             if(config.slideFromLeft)
  54.             {
  55.                 fromX = LEFT_SLIDE_POINT - ( (toX - LEFT_SLIDE_POINT) * (config.delay/SLIDE_DURATION)  );
  56.             }
  57.             else
  58.             {
  59.                 fromX = RIGHT_SLIDE_POINT - ( (toX - RIGHT_SLIDE_POINT) * (config.delay/SLIDE_DURATION)  );
  60.             }
  61.            
  62.             menuItem.setPosition(fromX, baseY);
  63.         }
  64.     }
  65.  
  66. }
  67.  
Parsed in 0.015 seconds, using GeSHi 1.0.8.4



Example usage:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.         this.creditsScene = new MenuScene(this.mCamera);
  2.         final HashMap<Integer, SlideMenuConfig> creditConfig = new HashMap<Integer, SlideMenuConfig>();
  3.         //the following config allows x, y, slide direction, and delay
  4.         creditConfig.put(MENU_CREDITS, new SlideMenuConfig(MENU_CREDITS, 70, 170));
  5.         final SpriteMenuItem creditMenuItem = new SpriteMenuItem(MENU_CREDITS, this.creditFrameRegion);
  6.         this.creditsScene.addMenuItem(creditMenuItem);
  7.         this.creditsScene.setMenuAnimator(new HeightSlideMenuAnimator(creditConfig));
  8.         this.creditsScene.setBackgroundEnabled(false);
  9.         this.creditsScene.buildAnimations();
Parsed in 0.012 seconds, using GeSHi 1.0.8.4
Method
 
Posts: 2
Joined: Fri Dec 17, 2010 11:43 pm

Re: SlideMenuAnimator

Postby Nicolas Gramlich » Sun Dec 19, 2010 5:26 pm

Hi,

so this class allows to make a menu that has menu-items that slide from left/right to specific/custom positions :?:

Also, why the name: HeightSlideMenuAnimator (couldn't see a reason for the "Height" from my brief look at the code).

Best Regards,
Nicolas
Nicolas Gramlich
Site Admin
 
Posts: 1734
Joined: Mon Jun 07, 2010 6:20 pm
Location: Schriesheim, Germany


Return to Features

Who is online

Users browsing this forum: No registered users and 10 guests