Skip to content

Commit

Permalink
Added Entity.setColor(pARGBPackedInt).
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicolas Gramlich committed Feb 17, 2013
1 parent e1722bc commit c7fa4c0
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 2 deletions.
8 changes: 8 additions & 0 deletions src/org/andengine/entity/Entity.java
Expand Up @@ -14,6 +14,7 @@
import org.andengine.opengl.util.GLState;
import org.andengine.util.Constants;
import org.andengine.util.adt.color.Color;
import org.andengine.util.adt.color.ColorUtils;
import org.andengine.util.adt.list.SmartList;
import org.andengine.util.adt.transformation.Transformation;
import org.andengine.util.algorithm.collision.EntityCollisionChecker;
Expand Down Expand Up @@ -692,6 +693,13 @@ public void setColor(final Color pColor) {
this.onUpdateColor();
}

@Override
public void setColor(final int pARGBPackedInt) {
ColorUtils.convertARGBPackedIntToColor(pARGBPackedInt, this.mColor);

this.onUpdateColor();
}

/**
* @param pRed from <code>0.0f</code> to <code>1.0f</code>
*/
Expand Down
1 change: 1 addition & 0 deletions src/org/andengine/entity/IEntity.java
Expand Up @@ -167,6 +167,7 @@ public interface IEntity extends IDrawHandler, IUpdateHandler, IDisposable, ITou
public void setBlue(final float pBlue);
public void setAlpha(final float pAlpha);
public void setColor(final Color pColor);
public void setColor(final int pARGBPackedInt);
public void setColor(final float pRed, final float pGreen, final float pBlue);
public void setColor(final float pRed, final float pGreen, final float pBlue, final float pAlpha);

Expand Down
Expand Up @@ -2,6 +2,7 @@

import org.andengine.entity.IEntity;
import org.andengine.entity.particle.Particle;
import org.andengine.util.adt.color.Color;
import org.andengine.util.modifier.ease.EaseLinear;
import org.andengine.util.modifier.ease.IEaseFunction;

Expand All @@ -25,6 +26,14 @@ public class ColorParticleModifier<T extends IEntity> extends BaseTripleValueSpa
// Constructors
// ===========================================================

public ColorParticleModifier(final float pFromTime, final float pToTime, final Color pFromColor, final Color pToColor) {
this(pFromTime, pToTime, pFromColor.getRed(), pToColor.getRed(), pFromColor.getGreen(), pToColor.getGreen(), pFromColor.getBlue(), pToColor.getBlue());
}

public ColorParticleModifier(final float pFromTime, final float pToTime, final Color pFromColor, final Color pToColor, final IEaseFunction pEaseFunction) {
super(pFromTime, pToTime, pFromColor.getRed(), pToColor.getRed(), pFromColor.getGreen(), pToColor.getGreen(), pFromColor.getBlue(), pToColor.getBlue(), pEaseFunction);
}

public ColorParticleModifier(final float pFromTime, final float pToTime, final float pFromRed, final float pToRed, final float pFromGreen, final float pToGreen, final float pFromBlue, final float pToBlue) {
this(pFromTime, pToTime, pFromRed, pToRed, pFromGreen, pToGreen, pFromBlue, pToBlue, EaseLinear.getInstance());
}
Expand Down
Expand Up @@ -204,6 +204,11 @@ public void setColor(final Color pColor) {
this.mMenuItem.setColor(pColor);
}

@Override
public void setColor(final int pARGBPackedInt) {
this.mMenuItem.setColor(pARGBPackedInt);
}

@Override
public void setColor(final float pRed, final float pGreen, final float pBlue) {
this.mMenuItem.setColor(pRed, pGreen, pBlue);
Expand Down
4 changes: 4 additions & 0 deletions src/org/andengine/util/adt/color/Color.java
Expand Up @@ -87,6 +87,10 @@ public class Color {
// Constructors
// ===========================================================

/* package */ Color() {

}

public Color(final Color pColor) {
this.set(pColor);
}
Expand Down
20 changes: 18 additions & 2 deletions src/org/andengine/util/adt/color/ColorUtils.java
Expand Up @@ -64,21 +64,37 @@ public static final Color convertHSVToColor(final float pHue, final float pSatur


public static Color convertARGBPackedIntToColor(final int pARGBPackedInt) {
final Color color = new Color();

ColorUtils.convertARGBPackedIntToColor(pARGBPackedInt, color);

return color;
}

public static void convertARGBPackedIntToColor(final int pARGBPackedInt, final Color pColor) {
final float alpha = ColorUtils.extractAlphaFromARGBPackedInt(pARGBPackedInt);
final float red = ColorUtils.extractRedFromARGBPackedInt(pARGBPackedInt);
final float green = ColorUtils.extractGreenFromARGBPackedInt(pARGBPackedInt);
final float blue = ColorUtils.extractBlueFromARGBPackedInt(pARGBPackedInt);

return new Color(red, green, blue, alpha);
pColor.set(red, green, blue, alpha);
}

public static Color convertABGRPackedIntToColor(final int pABGRPackedInt) {
final Color color = new Color();

ColorUtils.convertABGRPackedIntToColor(pABGRPackedInt, color);

return color;
}

public static void convertABGRPackedIntToColor(final int pABGRPackedInt, final Color pColor) {
final float alpha = ColorUtils.extractAlphaFromABGRPackedInt(pABGRPackedInt);
final float blue = ColorUtils.extractBlueFromABGRPackedInt(pABGRPackedInt);
final float green = ColorUtils.extractGreenFromABGRPackedInt(pABGRPackedInt);
final float red = ColorUtils.extractRedFromABGRPackedInt(pABGRPackedInt);

return new Color(red, green, blue, alpha);
pColor.set(red, green, blue, alpha);
}


Expand Down

0 comments on commit c7fa4c0

Please sign in to comment.