Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modifiers improved to be able to use them in more general pools : #208

Open
wants to merge 1 commit into
base: GLES2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,13 @@ public void reset(final float pDuration, final float pFromValue, final float pTo
// ===========================================================
// Methods
// ===========================================================

public void reset(final float pDuration, final float pFromValueA, final float pToValueA, final float pFromValueB, final float pToValueB) {
super.reset(pDuration, pFromValueA, pToValueA);
reset(pDuration, pFromValueA, pToValueA, pFromValueB, pToValueB, mEaseFunction);
}

public void reset(final float pDuration, final float pFromValueA, final float pToValueA, final float pFromValueB, final float pToValueB, final IEaseFunction pEaseFunction) {
super.reset(pDuration, pFromValueA, pToValueA, pEaseFunction);

this.mFromValueB = pFromValueB;
this.mValueSpanB = pToValueB - pFromValueB;
Expand Down
9 changes: 9 additions & 0 deletions src/org/andengine/util/modifier/BaseModifier.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ public void addModifierListener(final IModifierListener<T> pModifierListener) {
}
}

@Override
public void clearModifierListeners() {
this.mModifierListeners.clear();
}

@Override
public boolean removeModifierListener(final IModifierListener<T> pModifierListener) {
if(pModifierListener == null) {
Expand All @@ -74,6 +79,10 @@ public boolean removeModifierListener(final IModifierListener<T> pModifierListen
return this.mModifierListeners.remove(pModifierListener);
}
}

@Override
public void onUnregister(final T pItem) {
}

@Override
public abstract IModifier<T> deepCopy() throws DeepCopyNotSupportedException;
Expand Down
14 changes: 12 additions & 2 deletions src/org/andengine/util/modifier/BaseSingleValueSpanModifier.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public abstract class BaseSingleValueSpanModifier<T> extends BaseDurationModifie
private float mFromValue;
private float mValueSpan;

protected final IEaseFunction mEaseFunction;
protected IEaseFunction mEaseFunction;

// ===========================================================
// Constructors
Expand Down Expand Up @@ -67,6 +67,11 @@ public float getFromValue() {
public float getToValue() {
return this.mFromValue + this.mValueSpan;
}

public IEaseFunction getEaseFunction() {
return mEaseFunction;
}


// ===========================================================
// Methods for/from SuperClass/Interfaces
Expand All @@ -90,13 +95,18 @@ protected void onManagedUpdate(final float pSecondsElapsed, final T pItem) {
// ===========================================================
// Methods
// ===========================================================

public void reset(final float pDuration, final float pFromValue, final float pToValue) {
reset(pDuration, pFromValue, pToValue, mEaseFunction);
}

public void reset(final float pDuration, final float pFromValue, final float pToValue, final IEaseFunction pEaseFunction) {
super.reset();

this.mDuration = pDuration;
this.mFromValue = pFromValue;
this.mValueSpan = pToValue - pFromValue;
this.mEaseFunction = pEaseFunction;
}

// ===========================================================
Expand Down
3 changes: 3 additions & 0 deletions src/org/andengine/util/modifier/IModifier.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,12 @@ public int compare(final IModifier<?> pModifierA, final IModifier<?> pModifierB)
public float getDuration();

public float onUpdate(final float pSecondsElapsed, final T pItem);

public void onUnregister(final T pItem);

public void addModifierListener(final IModifierListener<T> pModifierListener);
public boolean removeModifierListener(final IModifierListener<T> pModifierListener);
public void clearModifierListeners();

// ===========================================================
// Inner and Anonymous Classes
Expand Down
21 changes: 21 additions & 0 deletions src/org/andengine/util/modifier/ModifierList.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,26 @@ public boolean add(final IModifier<T> pModifier) {
return super.add(pModifier);
}
}

@Override
public void clear() {
final int modifierCount = this.size();
if(modifierCount > 0) {
for(int i = modifierCount - 1; i >= 0; i--) {
final IModifier<T> modifier = this.get(i);
modifier.onUnregister(this.mTarget);
}
}
super.clear();
}

@Override
public boolean remove(final Object pObject) {
@SuppressWarnings("unchecked")
final IModifier<T> modifier = (IModifier<T>) pObject;
modifier.onUnregister(this.mTarget);
return super.remove(pObject);
}

@Override
public void onUpdate(final float pSecondsElapsed) {
Expand All @@ -66,6 +86,7 @@ public void onUpdate(final float pSecondsElapsed) {
modifier.onUpdate(pSecondsElapsed, this.mTarget);
if(modifier.isFinished() && modifier.isAutoUnregisterWhenFinished()) {
this.remove(i);
modifier.onUnregister(this.mTarget);
}
}
}
Expand Down