MoveByModifier

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

MoveByModifier

Postby vertti » Fri Aug 05, 2011 7:58 am

It would be great to a new version of MoveModifier that wouldn't need absolute coordinates (from / to) but just the amount it moves. So that when it starts, it would gradually move like say 100 pixels to the left where ever it would be when it started.

I want my bonus sprites to random direction when they are spawned. They also have other modifiers, so it would be nice to just reset all the mods, move the sprite to a new location and it would be moved by the modifier certain relative amount to some direction.
Catch me on Twitter and our development blog.
Check out our game SCAWAR Space Combat and it's trailer.
Image
vertti
 
Posts: 82
Joined: Fri Jul 08, 2011 11:19 am
Location: Finland

Re: MoveByModifier

Postby tajny » Sat Aug 06, 2011 5:18 pm

Hi, i didnt tested it but it should work

edit : Yep, they work

MoveXByModifier :
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. package com.axl.modifiers;
  2.  
  3. import org.anddev.andengine.entity.IEntity;
  4. import org.anddev.andengine.entity.modifier.SingleValueChangeEntityModifier;
  5.  
  6. public class MoveByXModifier extends SingleValueChangeEntityModifier {
  7.         // ===========================================================
  8.         // Constants
  9.         // ===========================================================
  10.  
  11.         // ===========================================================
  12.         // Fields
  13.         // ===========================================================
  14.  
  15.         // ===========================================================
  16.         // Constructors
  17.         // ===========================================================
  18.  
  19.         public MoveByXModifier(final float pDuration, final float pValueX) {
  20.                 super(pDuration, pValueX);
  21.         }
  22.  
  23.         protected MoveByXModifier(final MoveByXModifier pMoveXByModifier) {
  24.                 super(pMoveXByModifier);
  25.         }
  26.  
  27.         @Override
  28.         public MoveByXModifier clone(){
  29.                 return new MoveByXModifier(this);
  30.         }
  31.  
  32.         // ===========================================================
  33.         // Getter & Setter
  34.         // ===========================================================
  35.  
  36.         // ===========================================================
  37.         // Methods for/from SuperClass/Interfaces
  38.         // ===========================================================
  39.  
  40.         @Override
  41.         protected void onChangeValue(final IEntity pEntity, final float pValue) {
  42.                 pEntity.setPosition(pEntity.getX()+pValue, pEntity.getY());
  43.         }
  44.  
  45.         // ===========================================================
  46.         // Methods
  47.         // ===========================================================
  48.  
  49.         // ===========================================================
  50.         // Inner and Anonymous Classes
  51.         // ===========================================================
  52. }
  53.  
  54.  
Parsed in 0.015 seconds, using GeSHi 1.0.8.4


and Y version :
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. package com.axl.modifiers;
  2.  
  3. import org.anddev.andengine.entity.IEntity;
  4. import org.anddev.andengine.entity.modifier.SingleValueChangeEntityModifier;
  5.  
  6. public class MoveByYModifier extends SingleValueChangeEntityModifier {
  7.         // ===========================================================
  8.         // Constants
  9.         // ===========================================================
  10.  
  11.         // ===========================================================
  12.         // Fields
  13.         // ===========================================================
  14.  
  15.         // ===========================================================
  16.         // Constructors
  17.         // ===========================================================
  18.  
  19.         public MoveByYModifier(final float pDuration, final float pValueY) {
  20.                 super(pDuration, pValueY);
  21.         }
  22.  
  23.         protected MoveByYModifier(final MoveByYModifier pMoveYByModifier) {
  24.                 super(pMoveYByModifier);
  25.         }
  26.  
  27.         @Override
  28.         public MoveByYModifier clone(){
  29.                 return new MoveByYModifier(this);
  30.         }
  31.  
  32.         // ===========================================================
  33.         // Getter & Setter
  34.         // ===========================================================
  35.  
  36.         // ===========================================================
  37.         // Methods for/from SuperClass/Interfaces
  38.         // ===========================================================
  39.  
  40.         @Override
  41.         protected void onChangeValue(final IEntity pEntity, final float pValue) {
  42.                 pEntity.setPosition(pEntity.getX(), pEntity.getY() + pValue);
  43.         }
  44.  
  45.         // ===========================================================
  46.         // Methods
  47.         // ===========================================================
  48.  
  49.         // ===========================================================
  50.         // Inner and Anonymous Classes
  51.         // ===========================================================
  52. }
  53.  
  54.  
Parsed in 0.012 seconds, using GeSHi 1.0.8.4

Paweł P.

--------------------------------------
Portfolio

Run Santa Run Link
Xelorians Link
User avatar
tajny
 
Posts: 216
Joined: Mon May 30, 2011 10:23 pm
Location: Poland

Re: MoveByModifier

Postby vertti » Fri Aug 12, 2011 6:38 pm

Thank you!

I see that Nicholas has done a MoveByModifier now but it's in the GLE2 branch. I wonder how broken that branch currently is?
Catch me on Twitter and our development blog.
Check out our game SCAWAR Space Combat and it's trailer.
Image
vertti
 
Posts: 82
Joined: Fri Jul 08, 2011 11:19 am
Location: Finland

Re: MoveByModifier

Postby Scott Kennedy » Sat Aug 20, 2011 2:07 am

vertti wrote:Thank you!

I see that Nicholas has done a MoveByModifier now but it's in the GLE2 branch. I wonder how broken that branch currently is?


The bigger issue, I believe, is that OpenGL ES 2.0 will only work on Android 2.2 and higher.

GLES2 has worked fairly well from what I've seen of it, but it's definitely not done.
Scott Kennedy
 
Posts: 5
Joined: Thu Aug 04, 2011 10:47 pm
Location: Ontario, Canada

Re: MoveByModifier

Postby cousin_itt » Sat Jan 07, 2012 4:05 am

I needed to be able to use ease functions too.
To keep the movement relative we need to store how much it's already moved by. (And reset that upon every loop)
This is based on the GLES2 branch.
I should probably add support for listeners too.
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. package your.package;
  2.  
  3. import org.anddev.andengine.entity.IEntity;
  4. import org.anddev.andengine.entity.modifier.SingleValueSpanEntityModifier;
  5. import org.anddev.andengine.util.modifier.ease.IEaseFunction;
  6.  
  7. public class MoveByXModifier extends SingleValueSpanEntityModifier {
  8.         // ===========================================================
  9.         // Constants
  10.         // ===========================================================
  11.  
  12.         // ===========================================================
  13.         // Fields
  14.         // ===========================================================
  15.  
  16.         private float lastValueX;
  17.  
  18.         // ===========================================================
  19.         // Constructors
  20.         // ===========================================================
  21.  
  22.         public MoveByXModifier(final float pDuration, final float pValueX) {
  23.                 super(pDuration, 0, pValueX);
  24.         }
  25.        
  26.         public MoveByXModifier(final float pDuration, final float pValueX, final IEaseFunction pEaseFunction) {
  27.                 super(pDuration, 0, pValueX, pEaseFunction);
  28.         }
  29.  
  30.         protected MoveByXModifier(final MoveByXModifier pMoveXByModifier) {
  31.                 super(pMoveXByModifier);
  32.         }
  33.        
  34.  
  35.         @Override
  36.         public MoveByXModifier clone(){
  37.                 return new MoveByXModifier(this);
  38.         }
  39.  
  40.         // ===========================================================
  41.         // Getter & Setter
  42.         // ===========================================================
  43.  
  44.         // ===========================================================
  45.         // Methods for/from SuperClass/Interfaces
  46.         // ===========================================================
  47.  
  48.  
  49.         @Override
  50.         protected void onSetInitialValue(IEntity pItem, float pValue) {
  51.                 //lastValueX = 0;
  52.                 // reseting lastValueX here was not reliable, occasionally it would reset before the last move
  53.                 // and thus make the move full value ( pValue - 0)
  54.         }
  55.  
  56.         @Override
  57.         protected void onSetValue(IEntity pItem, float pPercentageDone, float pValue) {
  58.                 float moveByX = pValue - lastValueX;
  59.                 lastValueX = pValue;
  60.                 pItem.setPosition(pItem.getX() + moveByX, pItem.getY());
  61.  
  62.                 if(pPercentageDone == 1.0)  lastValueX = 0;        // is reliable even though it's a float
  63.         }
  64.  
  65.  
  66.         // ===========================================================
  67.         // Methods
  68.         // ===========================================================
  69.  
  70.         // ===========================================================
  71.         // Inner and Anonymous Classes
  72.         // ===========================================================
  73. }
Parsed in 0.013 seconds, using GeSHi 1.0.8.4
cousin_itt
 
Posts: 3
Joined: Wed Dec 21, 2011 3:18 pm


Return to Features

Who is online

Users browsing this forum: No registered users and 7 guests