GradualScaleMenuItemDecorator

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

GradualScaleMenuItemDecorator

Postby EddieRingle » Sat Jan 01, 2011 12:31 am

Hey all, AndEngine is a great framework for getting any game up and running. I'm glad I found it. :-)

Anyways, while developing our game, we ran into a few issues where the engine just didn't meet our needs (but hey, no engine is perfect, right?). One such occasion was animating menu items so that they gracefully scale up or down, instead of abruptly changing the scale factor like ScaleMenuItemDecorator does. To fix this, I dug around in the AndEngine source code to learn how everything connected, and wrote this class up to fulfill the needed functionality.

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. package org.anddev.andengine.entity.scene.menu.item.decorator;
  2.  
  3. import org.anddev.andengine.entity.scene.menu.item.IMenuItem;
  4. import org.anddev.andengine.entity.shape.modifier.ScaleModifier;
  5.  
  6. /**
  7.  * @author Eddie Ringle
  8.  * @since 16:38:29 - 31.12.2010
  9.  */
  10. public class GradualScaleMenuItemDecorator extends BaseMenuItemDecorator {
  11.         // ===========================================================
  12.         // Fields
  13.         // ===========================================================
  14.  
  15.         private final float mSelectedScale;
  16.         private final float mUnselectedScale;
  17.         private final float mDuration;
  18.  
  19.         // ===========================================================
  20.         // Constructors
  21.         // ===========================================================
  22.  
  23.         public GradualScaleMenuItemDecorator(final IMenuItem pMenuItem, final float pSelectedScale, final float pUnselectedScale, final float pDuration) {
  24.                 super(pMenuItem);
  25.  
  26.                 this.mSelectedScale = pSelectedScale;
  27.                 this.mUnselectedScale = pUnselectedScale;
  28.                 this.mDuration = pDuration;
  29.  
  30.                 pMenuItem.setScale(pUnselectedScale);
  31.         }
  32.  
  33.         // ===========================================================
  34.         // Methods for/from SuperClass/Interfaces
  35.         // ===========================================================
  36.  
  37.         @Override
  38.         public void onMenuItemSelected(final IMenuItem pMenuItem) {
  39.             this.clearShapeModifiers();
  40.             this.addShapeModifier(new ScaleModifier(this.mDuration, this.getScaleX(), this.mSelectedScale));
  41.         }
  42.  
  43.         @Override
  44.         public void onMenuItemUnselected(final IMenuItem pMenuItem) {
  45.             this.clearShapeModifiers();
  46.             this.addShapeModifier(new ScaleModifier(this.mDuration, this.getScaleX(), this.mUnselectedScale));
  47.         }
  48.  
  49.         @Override
  50.         public void onMenuItemReset(final IMenuItem pMenuItem) {
  51.             this.clearShapeModifiers();
  52.             if (this.getScaleX() != this.mUnselectedScale) {
  53.                 this.addShapeModifier(new ScaleModifier(this.mDuration, this.getScaleX(), this.mUnselectedScale));
  54.             }
  55.         }
  56. }
  57.  
Parsed in 0.013 seconds, using GeSHi 1.0.8.4


We added this class directly into the engine and recompiled the JAR and things were up and running.

Here's a short (and poorly done) video on just what this class does:


And yes, those are MenuScenes. I also modified the engine to prevent it from grouping all the MenuItems into the center of the screen, allowing for custom positioning. That, however, is for another thread. :-)
EddieRingle
 
Posts: 25
Joined: Fri Dec 10, 2010 12:44 am

Re: GradualScaleMenuItemDecorator

Postby Br0ken » Sat Jan 01, 2011 7:33 pm

Looks great, thanks for posting.

Lets see a teaser video of your game too! :)
Br0ken
 
Posts: 265
Joined: Sun Sep 12, 2010 3:57 pm

Re: GradualScaleMenuItemDecorator

Postby EddieRingle » Sat Jan 01, 2011 11:59 pm

Br0ken wrote:Lets see a teaser video of your game too! :)


Ah, that might come soon. ;)
EddieRingle
 
Posts: 25
Joined: Fri Dec 10, 2010 12:44 am

Re: GradualScaleMenuItemDecorator

Postby MiToNiOeS » Sun Jan 02, 2011 4:36 am

very nice, simple and elegant. Thanks!!
MiToNiOeS
 
Posts: 5
Joined: Wed Dec 29, 2010 12:39 pm

Re: GradualScaleMenuItemDecorator

Postby Nicolas Gramlich » Thu Feb 24, 2011 12:54 am

Cool.
And the nice menu makes us want to see more :) :!:

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: Google [Bot] and 7 guests