[AndEngineLimbo] Swing widget

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

[AndEngineLimbo] Swing widget

Postby nazgee » Mon May 13, 2013 4:10 pm

What is AndEngineLimbo?
Have a look at first post here: features/positioner-t11930.html

Swing widget
This is new standalone feature available from AndEngineLimbo repository. I hope that we can base some more widgets using provided infrastacture. I am expecting your help and criticism :)

swing.png
swing.png (181.16 KiB) Viewed 1216 times



It is a widget based on ClipEntity. It can be used as a fancy way to display e.g. "current score" or "cash balance". You can modify how Swing's content will be animated: easing, time and direction can be chosen for both animations (out- hiding old text, and in- showing it back with new value). It's constructor expects font to be used and texture of face Sprite (9patches are used- maybe this should be changed).

It should be also pretty easy to use current structure for "swinging" something else than Text - for example one can implement it to swing sprites or entities (and maybe whole Scenes?).

TODO
- add means to decide whether sprite should be created in front of, or behind content
- add means to resize clip entity, e.g. so it can be made smaller than the whole Swing

Example
To get what you see on the picture/video, try this:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public Scene() {
  2.         ITextureRegion texture = pResources.TEXTURES.get("steel-ninepatch-viewport-bare.png");
  3.         ITextureRegion bgTexture = pResources.TEXTURES.get("bg-mountains-1.png");
  4.         Font font = pResources.TEXTURES.getFontHUD();
  5.         VertexBufferObjectManager vbom = pResources.ENGINE.getVertexBufferObjectManager();
  6.  
  7.         setSize(GameConstants.CAMERA_WIDTH, GameConstants.CAMERA_HEIGHT);
  8.         setBackground(new SpriteBackground(
  9.                 new Sprite(
  10.                         GameConstants.CAMERA_WIDTH/2, GameConstants.CAMERA_HEIGHT/2,
  11.                         GameConstants.CAMERA_WIDTH, GameConstants.CAMERA_HEIGHT, bgTexture, vbom)));
  12.  
  13.         final SwingSpriteText s1 = createSwingSpriteText(
  14.                 font, texture, vbom, eAnimationDirection.LEFT, eAnimationDirection.LEFT,
  15.                 0.5f, 0.5f, EaseSineIn.getInstance(), EaseSineOut.getInstance());
  16.         final SwingSpriteText s2 = createSwingSpriteText(
  17.                 font, texture, vbom, eAnimationDirection.RIGHT, eAnimationDirection.RIGHT,
  18.                 1, 0.5f, EaseSineIn.getInstance(), EaseElasticOut.getInstance());
  19.         final SwingSpriteText s3 = createSwingSpriteText(
  20.                 font, texture, vbom, eAnimationDirection.UP, eAnimationDirection.LEFT,
  21.                 1, 0.5f, EaseSineIn.getInstance(), EaseQuadOut.getInstance());
  22.         final SwingSpriteText s4 = createSwingSpriteText(
  23.                 font, texture, vbom, eAnimationDirection.LEFT, eAnimationDirection.UP,
  24.                 1, 0.5f, EaseSineIn.getInstance(), EaseElasticOut.getInstance());
  25.         final SwingSpriteText s5 = createSwingSpriteText(
  26.                 font, texture, vbom, eAnimationDirection.UP, eAnimationDirection.DOWN,
  27.                 0.5f, 1f, EaseSineIn.getInstance(), EaseBounceOut.getInstance());
  28.         final SwingSpriteText s6 = createSwingSpriteText(
  29.                 font, texture, vbom, eAnimationDirection.DOWN, eAnimationDirection.UP,
  30.                 0.25f, 0.25f, EaseSineOut.getInstance(), EaseSineIn.getInstance());
  31.  
  32.         attachChild(s1);
  33.         attachChild(s2);
  34.         attachChild(s3);
  35.         attachChild(s4);
  36.         attachChild(s5);
  37.         attachChild(s6);
  38.  
  39.         PositionerSceneRelative.getInstance().alignTopLeftEdges(this, s1);
  40.         PositionerSceneRelative.getInstance().alignTopRightEdges(this, s2);
  41.         PositionerSceneRelative.getInstance().alignBottomRightEdges(this, s3);
  42.         PositionerSceneRelative.getInstance().alignBottomLeftEdges(this, s4);
  43.         PositionerSceneRelative.getInstance().center(this, s5);
  44.         PositionerSceneRelative.getInstance().placeBelowOfAndCenter(s5, s6);
  45.  
  46.         registerUpdateHandler(new TimerHandler(2, true, new ITimerCallback() {
  47.                 float pTimePassed = 0;
  48.                 @Override
  49.                 public void onTimePassed(TimerHandler pTimerHandler) {
  50.                         s1.setValue("s1; " + pTimePassed);
  51.                         s2.setValue("s2; " + pTimePassed);
  52.                         s3.setValue("s3; " + pTimePassed);
  53.                         s4.setValue("s4; " + pTimePassed);
  54.                         s5.setValue("s5; " + pTimePassed);
  55.                         s6.setValue("s6; " + pTimePassed);
  56.                         pTimePassed += pTimerHandler.getTimerSeconds();
  57.                 }
  58.         }));
  59. }
  60. /**
  61.  * This is a wrapper for fucked up contructor of Swing. It is needs A LOT
  62.  * of parameters., hence this wrapper. You should replace ninesilce insets
  63.  * calculations with values that match your texture region.
  64.  */
  65. private SwingSpriteText createSwingSpriteText(
  66.         final Font pFont, final ITextureRegion pTexture, VertexBufferObjectManager vbom,
  67.         final eAnimationDirection directionOut, final eAnimationDirection directionIn,
  68.         final float timeOut, final float timeIn,
  69.         final IEaseFunction easeOut, final IEaseFunction easeIn) {
  70.  
  71.         SwingSpriteText swing = new SwingSpriteText(
  72.                         0 /*x*/, 0 /*y*/, getWidth() / 3 /*width*/, 54 /*height*/,
  73.                         pFont /*font*/, 40 /*chars max*/, pTexture /*texture*/,
  74.                         32/*9slice inset left*/, 11/*9slice inset top*/,
  75.                         32/*9slice inset right*/, 11/*9slice inset bottom*/,
  76.                         directionOut, directionIn, timeOut, timeIn,
  77.                         easeOut, easeIn, vbom);
  78.         return swing;
  79. }
  80. }));
Parsed in 0.017 seconds, using GeSHi 1.0.8.4
Last edited by nazgee on Tue May 14, 2013 12:27 am, edited 8 times in total.
Dirt Rider Mayhem is PUBLISHED now!
Image
User avatar
nazgee
 
Posts: 527
Joined: Fri Oct 21, 2011 10:31 pm
Location: Poland, Wrocław

Re: [AndEngineLimbo] Swing widget

Postby Niffy » Mon May 13, 2013 5:33 pm

Nice work so far !
Niffy
 
Posts: 284
Joined: Sat Sep 17, 2011 8:39 pm

Re: [AndEngineLimbo] Swing widget

Postby Mathew » Mon May 13, 2013 7:30 pm

Looks interesting, why not making another andengine extension instead?
User avatar
Mathew
 
Posts: 1073
Joined: Sun Jul 31, 2011 2:49 pm
Location: Tarnów, Poland

Re: [AndEngineLimbo] Swing widget

Postby nazgee » Mon May 13, 2013 8:24 pm

Errrmm... sarcasm? :)
I am affraid that managing a dozen of extensions will be an overkill for me. So far I am the only that contributes to Limbo, so there is no risk that it will get too bloated... But I agree- if I will get nice codebase of widgets deserving an extension, we'll create one.
Dirt Rider Mayhem is PUBLISHED now!
Image
User avatar
nazgee
 
Posts: 527
Joined: Fri Oct 21, 2011 10:31 pm
Location: Poland, Wrocław


Return to Features

Who is online

Users browsing this forum: No registered users and 7 guests