code
stringlengths
3
1.18M
language
stringclasses
1 value
package org.anddev.andengine.entity.sprite; import java.util.Arrays; import org.anddev.andengine.opengl.texture.region.TiledTextureRegion; import org.anddev.andengine.opengl.vertex.RectangleVertexBuffer; import org.anddev.andengine.util.MathUtils; import org.anddev.andengine.util.constants.TimeConstants; public class AnimatedSprite extends TiledSprite implements TimeConstants { // =========================================================== // Constants // =========================================================== private static final int LOOP_CONTINUOUS = -1; // =========================================================== // Fields // =========================================================== private boolean mAnimationRunning; private long mAnimationProgress; private long mAnimationDuration; private long[] mFrameEndsInNanoseconds; private int mFirstTileIndex; private int mInitialLoopCount; private int mLoopCount; private IAnimationListener mAnimationListener; private int mFrameCount; private int[] mFrames; // =========================================================== // Constructors // =========================================================== public AnimatedSprite(final float pX, final float pY, final TiledTextureRegion pTiledTextureRegion) { super(pX, pY, pTiledTextureRegion); } public AnimatedSprite(final float pX, final float pY, final float pTileWidth, final float pTileHeight, final TiledTextureRegion pTiledTextureRegion) { super(pX, pY, pTileWidth, pTileHeight, pTiledTextureRegion); } public AnimatedSprite(final float pX, final float pY, final TiledTextureRegion pTiledTextureRegion, final RectangleVertexBuffer pRectangleVertexBuffer) { super(pX, pY, pTiledTextureRegion, pRectangleVertexBuffer); } public AnimatedSprite(final float pX, final float pY, final float pTileWidth, final float pTileHeight, final TiledTextureRegion pTiledTextureRegion, final RectangleVertexBuffer pRectangleVertexBuffer) { super(pX, pY, pTileWidth, pTileHeight, pTiledTextureRegion, pRectangleVertexBuffer); } // =========================================================== // Getter & Setter // =========================================================== public boolean isAnimationRunning() { return this.mAnimationRunning; } // =========================================================== // Methods for/from SuperClass/Interfaces // =========================================================== @Override protected void onManagedUpdate(final float pSecondsElapsed) { super.onManagedUpdate(pSecondsElapsed); if(this.mAnimationRunning) { final long nanoSecondsElapsed = (long) (pSecondsElapsed * TimeConstants.NANOSECONDSPERSECOND); this.mAnimationProgress += nanoSecondsElapsed; if(this.mAnimationProgress > this.mAnimationDuration) { this.mAnimationProgress %= this.mAnimationDuration; if(this.mInitialLoopCount != AnimatedSprite.LOOP_CONTINUOUS) { this.mLoopCount--; } } if(this.mInitialLoopCount == AnimatedSprite.LOOP_CONTINUOUS || this.mLoopCount >= 0) { final int currentFrameIndex = this.calculateCurrentFrameIndex(); if(this.mFrames == null) { this.setCurrentTileIndex(this.mFirstTileIndex + currentFrameIndex); } else { this.setCurrentTileIndex(this.mFrames[currentFrameIndex]); } } else { this.mAnimationRunning = false; if(this.mAnimationListener != null) { this.mAnimationListener.onAnimationEnd(this); } } } } // =========================================================== // Methods // =========================================================== public void stopAnimation() { this.mAnimationRunning = false; } public void stopAnimation(final int pTileIndex) { this.mAnimationRunning = false; this.setCurrentTileIndex(pTileIndex); } private int calculateCurrentFrameIndex() { final long animationProgress = this.mAnimationProgress; final long[] frameEnds = this.mFrameEndsInNanoseconds; final int frameCount = this.mFrameCount; for(int i = 0; i < frameCount; i++) { if(frameEnds[i] > animationProgress) { return i; } } return frameCount - 1; } public AnimatedSprite animate(final long pFrameDurationEach) { return this.animate(pFrameDurationEach, true); } public AnimatedSprite animate(final long pFrameDurationEach, final boolean pLoop) { return this.animate(pFrameDurationEach, (pLoop) ? AnimatedSprite.LOOP_CONTINUOUS : 0, null); } public AnimatedSprite animate(final long pFrameDurationEach, final int pLoopCount) { return this.animate(pFrameDurationEach, pLoopCount, null); } public AnimatedSprite animate(final long pFrameDurationEach, final boolean pLoop, final IAnimationListener pAnimationListener) { return this.animate(pFrameDurationEach, (pLoop) ? AnimatedSprite.LOOP_CONTINUOUS : 0, pAnimationListener); } public AnimatedSprite animate(final long pFrameDurationEach, final int pLoopCount, final IAnimationListener pAnimationListener) { final long[] frameDurations = new long[this.getTextureRegion().getTileCount()]; Arrays.fill(frameDurations, pFrameDurationEach); return this.animate(frameDurations, pLoopCount, pAnimationListener); } public AnimatedSprite animate(final long[] pFrameDurations) { return this.animate(pFrameDurations, true); } public AnimatedSprite animate(final long[] pFrameDurations, final boolean pLoop) { return this.animate(pFrameDurations, (pLoop) ? AnimatedSprite.LOOP_CONTINUOUS : 0, null); } public AnimatedSprite animate(final long[] pFrameDurations, final int pLoopCount) { return this.animate(pFrameDurations, pLoopCount, null); } public AnimatedSprite animate(final long[] pFrameDurations, final boolean pLoop, final IAnimationListener pAnimationListener) { return this.animate(pFrameDurations, (pLoop) ? AnimatedSprite.LOOP_CONTINUOUS : 0, pAnimationListener); } public AnimatedSprite animate(final long[] pFrameDurations, final int pLoopCount, final IAnimationListener pAnimationListener) { return this.animate(pFrameDurations, 0, this.getTextureRegion().getTileCount() - 1, pLoopCount, pAnimationListener); } public AnimatedSprite animate(final long[] pFrameDurations, final int pFirstTileIndex, final int pLastTileIndex, final boolean pLoop) { return this.animate(pFrameDurations, pFirstTileIndex, pLastTileIndex, (pLoop) ? AnimatedSprite.LOOP_CONTINUOUS : 0, null); } public AnimatedSprite animate(final long[] pFrameDurations, final int pFirstTileIndex, final int pLastTileIndex, final int pLoopCount) { return this.animate(pFrameDurations, pFirstTileIndex, pLastTileIndex, pLoopCount, null); } public AnimatedSprite animate(final long[] pFrameDurations, final int[] pFrames, final int pLoopCount) { return this.animate(pFrameDurations, pFrames, pLoopCount, null); } /** * Animate specifics frames * * @param pFrameDurations must have the same length as pFrames. * @param pFrames indices of the frames to animate. * @param pLoopCount * @param pAnimationListener */ public AnimatedSprite animate(final long[] pFrameDurations, final int[] pFrames, final int pLoopCount, final IAnimationListener pAnimationListener) { final int frameCount = pFrames.length; if(pFrameDurations.length != frameCount) { throw new IllegalArgumentException("pFrameDurations must have the same length as pFrames."); } return this.init(pFrameDurations, frameCount, pFrames, 0, pLoopCount, pAnimationListener); } /** * @param pFrameDurations * must have the same length as pFirstTileIndex to * pLastTileIndex. * @param pFirstTileIndex * @param pLastTileIndex * @param pLoopCount * @param pAnimationListener */ public AnimatedSprite animate(final long[] pFrameDurations, final int pFirstTileIndex, final int pLastTileIndex, final int pLoopCount, final IAnimationListener pAnimationListener) { if(pLastTileIndex - pFirstTileIndex < 1) { throw new IllegalArgumentException("An animation needs at least two tiles to animate between."); } final int frameCount = (pLastTileIndex - pFirstTileIndex) + 1; if(pFrameDurations.length != frameCount) { throw new IllegalArgumentException("pFrameDurations must have the same length as pFirstTileIndex to pLastTileIndex."); } return this.init(pFrameDurations, frameCount, null, pFirstTileIndex, pLoopCount, pAnimationListener); } private AnimatedSprite init(final long[] pFrameDurations, final int frameCount, final int[] pFrames, final int pFirstTileIndex, final int pLoopCount, final IAnimationListener pAnimationListener) { this.mFrameCount = frameCount; this.mAnimationListener = pAnimationListener; this.mInitialLoopCount = pLoopCount; this.mLoopCount = pLoopCount; this.mFrames = pFrames; this.mFirstTileIndex = pFirstTileIndex; if(this.mFrameEndsInNanoseconds == null || this.mFrameCount > this.mFrameEndsInNanoseconds.length) { this.mFrameEndsInNanoseconds = new long[this.mFrameCount]; } final long[] frameEndsInNanoseconds = this.mFrameEndsInNanoseconds; MathUtils.arraySumInto(pFrameDurations, frameEndsInNanoseconds, TimeConstants.NANOSECONDSPERMILLISECOND); final long lastFrameEnd = frameEndsInNanoseconds[this.mFrameCount - 1]; this.mAnimationDuration = lastFrameEnd; this.mAnimationProgress = 0; this.mAnimationRunning = true; return this; } // =========================================================== // Inner and Anonymous Classes // =========================================================== public static interface IAnimationListener { // =========================================================== // Constants // =========================================================== // =========================================================== // Fields // =========================================================== public void onAnimationEnd(final AnimatedSprite pAnimatedSprite); } }
Java
package org.anddev.andengine.entity.sprite; import org.anddev.andengine.opengl.texture.region.TextureRegion; import org.anddev.andengine.opengl.vertex.RectangleVertexBuffer; /** * (c) 2010 Nicolas Gramlich * (c) 2011 Zynga Inc. * * @author Nicolas Gramlich * @since 19:22:38 - 09.03.2010 */ public class Sprite extends BaseSprite { // =========================================================== // Constants // =========================================================== // =========================================================== // Fields // =========================================================== // =========================================================== // Constructors // =========================================================== public Sprite(final float pX, final float pY, final TextureRegion pTextureRegion) { super(pX, pY, pTextureRegion.getWidth(), pTextureRegion.getHeight(), pTextureRegion); } public Sprite(final float pX, final float pY, final float pWidth, final float pHeight, final TextureRegion pTextureRegion) { super(pX, pY, pWidth, pHeight, pTextureRegion); } public Sprite(final float pX, final float pY, final TextureRegion pTextureRegion, final RectangleVertexBuffer pRectangleVertexBuffer) { super(pX, pY, pTextureRegion.getWidth(), pTextureRegion.getHeight(), pTextureRegion, pRectangleVertexBuffer); } public Sprite(final float pX, final float pY, final float pWidth, final float pHeight, final TextureRegion pTextureRegion, final RectangleVertexBuffer pRectangleVertexBuffer) { super(pX, pY, pWidth, pHeight, pTextureRegion, pRectangleVertexBuffer); } // =========================================================== // Getter & Setter // =========================================================== // =========================================================== // Methods for/from SuperClass/Interfaces // =========================================================== @Override public TextureRegion getTextureRegion() { return (TextureRegion)this.mTextureRegion; } // =========================================================== // Methods // =========================================================== // =========================================================== // Inner and Anonymous Classes // =========================================================== }
Java
package org.anddev.andengine.entity.sprite; import org.anddev.andengine.opengl.texture.region.TiledTextureRegion; import org.anddev.andengine.opengl.vertex.RectangleVertexBuffer; /** * (c) 2010 Nicolas Gramlich * (c) 2011 Zynga Inc. * * @author Nicolas Gramlich * @since 19:30:13 - 09.03.2010 */ public class TiledSprite extends BaseSprite { // =========================================================== // Constants // =========================================================== // =========================================================== // Fields // =========================================================== // =========================================================== // Constructors // =========================================================== public TiledSprite(final float pX, final float pY, final TiledTextureRegion pTiledTextureRegion) { super(pX, pY, pTiledTextureRegion.getTileWidth(), pTiledTextureRegion.getTileHeight(), pTiledTextureRegion); } public TiledSprite(final float pX, final float pY, final float pTileWidth, final float pTileHeight, final TiledTextureRegion pTiledTextureRegion) { super(pX, pY, pTileWidth, pTileHeight, pTiledTextureRegion); } public TiledSprite(final float pX, final float pY, final TiledTextureRegion pTiledTextureRegion, final RectangleVertexBuffer pRectangleVertexBuffer) { super(pX, pY, pTiledTextureRegion.getTileWidth(), pTiledTextureRegion.getTileHeight(), pTiledTextureRegion, pRectangleVertexBuffer); } public TiledSprite(final float pX, final float pY, final float pTileWidth, final float pTileHeight, final TiledTextureRegion pTiledTextureRegion, final RectangleVertexBuffer pRectangleVertexBuffer) { super(pX, pY, pTileWidth, pTileHeight, pTiledTextureRegion, pRectangleVertexBuffer); } // =========================================================== // Getter & Setter // =========================================================== // =========================================================== // Methods for/from SuperClass/Interfaces // =========================================================== @Override public TiledTextureRegion getTextureRegion() { return (TiledTextureRegion)super.getTextureRegion(); } // =========================================================== // Methods // =========================================================== public int getCurrentTileIndex() { return this.getTextureRegion().getCurrentTileIndex(); } public void setCurrentTileIndex(final int pTileIndex) { this.getTextureRegion().setCurrentTileIndex(pTileIndex); } public void setCurrentTileIndex(final int pTileColumn, final int pTileRow) { this.getTextureRegion().setCurrentTileIndex(pTileColumn, pTileRow); } public void nextTile() { this.getTextureRegion().nextTile(); } // =========================================================== // Inner and Anonymous Classes // =========================================================== }
Java
package org.anddev.andengine.entity.layer.tiled.tmx; import java.util.ArrayList; import org.anddev.andengine.entity.layer.tiled.tmx.util.constants.TMXConstants; import org.anddev.andengine.util.SAXUtils; import org.xml.sax.Attributes; /** * (c) 2010 Nicolas Gramlich * (c) 2011 Zynga Inc. * * @author Nicolas Gramlich * @since 11:20:49 - 29.07.2010 */ public class TMXObjectGroup implements TMXConstants { // =========================================================== // Constants // =========================================================== // =========================================================== // Fields // =========================================================== private final String mName; private final int mWidth; private final int mHeight; private final ArrayList<TMXObject> mTMXObjects = new ArrayList<TMXObject>(); private final TMXProperties<TMXObjectGroupProperty> mTMXObjectGroupProperties = new TMXProperties<TMXObjectGroupProperty>(); // =========================================================== // Constructors // =========================================================== public TMXObjectGroup(final Attributes pAttributes) { this.mName = pAttributes.getValue("", TAG_OBJECTGROUP_ATTRIBUTE_NAME); this.mWidth = SAXUtils.getIntAttributeOrThrow(pAttributes, TAG_OBJECTGROUP_ATTRIBUTE_WIDTH); this.mHeight = SAXUtils.getIntAttributeOrThrow(pAttributes, TAG_OBJECTGROUP_ATTRIBUTE_HEIGHT); } // =========================================================== // Getter & Setter // =========================================================== public String getName() { return this.mName; } public int getWidth() { return this.mWidth; } public int getHeight() { return this.mHeight; } void addTMXObject(final TMXObject pTMXObject) { this.mTMXObjects.add(pTMXObject); } public ArrayList<TMXObject> getTMXObjects() { return this.mTMXObjects ; } public void addTMXObjectGroupProperty(final TMXObjectGroupProperty pTMXObjectGroupProperty) { this.mTMXObjectGroupProperties.add(pTMXObjectGroupProperty); } public TMXProperties<TMXObjectGroupProperty> getTMXObjectGroupProperties() { return this.mTMXObjectGroupProperties; } // =========================================================== // Methods for/from SuperClass/Interfaces // =========================================================== // =========================================================== // Methods // =========================================================== // =========================================================== // Inner and Anonymous Classes // =========================================================== }
Java
package org.anddev.andengine.entity.layer.tiled.tmx; import java.io.BufferedInputStream; import java.io.IOException; import java.io.InputStream; import javax.xml.parsers.ParserConfigurationException; import javax.xml.parsers.SAXParser; import javax.xml.parsers.SAXParserFactory; import org.anddev.andengine.entity.layer.tiled.tmx.util.exception.TMXLoadException; import org.anddev.andengine.opengl.texture.TextureManager; import org.anddev.andengine.opengl.texture.TextureOptions; import org.xml.sax.InputSource; import org.xml.sax.SAXException; import org.xml.sax.XMLReader; import android.content.Context; /** * (c) 2010 Nicolas Gramlich * (c) 2011 Zynga Inc. * * @author Nicolas Gramlich * @since 19:10:45 - 20.07.2010 */ public class TMXLoader { // =========================================================== // Constants // =========================================================== // =========================================================== // Fields // =========================================================== private final Context mContext; private final TextureManager mTextureManager; private final TextureOptions mTextureOptions; private final ITMXTilePropertiesListener mTMXTilePropertyListener; // =========================================================== // Constructors // =========================================================== public TMXLoader(final Context pContext, final TextureManager pTextureManager) { this(pContext, pTextureManager, TextureOptions.DEFAULT); } public TMXLoader(final Context pContext, final TextureManager pTextureManager, final TextureOptions pTextureOptions) { this(pContext, pTextureManager, pTextureOptions, null); } public TMXLoader(final Context pContext, final TextureManager pTextureManager, final ITMXTilePropertiesListener pTMXTilePropertyListener) { this(pContext, pTextureManager, TextureOptions.DEFAULT, pTMXTilePropertyListener); } public TMXLoader(final Context pContext, final TextureManager pTextureManager, final TextureOptions pTextureOptions, final ITMXTilePropertiesListener pTMXTilePropertyListener) { this.mContext = pContext; this.mTextureManager = pTextureManager; this.mTextureOptions = pTextureOptions; this.mTMXTilePropertyListener = pTMXTilePropertyListener; } // =========================================================== // Getter & Setter // =========================================================== // =========================================================== // Methods for/from SuperClass/Interfaces // =========================================================== // =========================================================== // Methods // =========================================================== public TMXTiledMap loadFromAsset(final Context pContext, final String pAssetPath) throws TMXLoadException { try { return this.load(pContext.getAssets().open(pAssetPath)); } catch (final IOException e) { throw new TMXLoadException("Could not load TMXTiledMap from asset: " + pAssetPath, e); } } public TMXTiledMap load(final InputStream pInputStream) throws TMXLoadException { try{ final SAXParserFactory spf = SAXParserFactory.newInstance(); final SAXParser sp = spf.newSAXParser(); final XMLReader xr = sp.getXMLReader(); final TMXParser tmxParser = new TMXParser(this.mContext, this.mTextureManager, this.mTextureOptions, this.mTMXTilePropertyListener); xr.setContentHandler(tmxParser); xr.parse(new InputSource(new BufferedInputStream(pInputStream))); return tmxParser.getTMXTiledMap(); } catch (final SAXException e) { throw new TMXLoadException(e); } catch (final ParserConfigurationException pe) { /* Doesn't happen. */ return null; } catch (final IOException e) { throw new TMXLoadException(e); } } // =========================================================== // Inner and Anonymous Classes // =========================================================== public interface ITMXTilePropertiesListener { // =========================================================== // Final Fields // =========================================================== // =========================================================== // Methods // =========================================================== public void onTMXTileWithPropertiesCreated(final TMXTiledMap pTMXTiledMap, final TMXLayer pTMXLayer, final TMXTile pTMXTile, final TMXProperties<TMXTileProperty> pTMXTileProperties); } }
Java
package org.anddev.andengine.entity.layer.tiled.tmx; import org.anddev.andengine.entity.layer.tiled.tmx.util.constants.TMXConstants; import org.anddev.andengine.entity.layer.tiled.tmx.util.exception.TMXParseException; import org.anddev.andengine.opengl.texture.TextureManager; import org.anddev.andengine.opengl.texture.TextureOptions; import org.anddev.andengine.util.SAXUtils; import org.xml.sax.Attributes; import org.xml.sax.SAXException; import org.xml.sax.helpers.DefaultHandler; import android.content.Context; /** * (c) 2010 Nicolas Gramlich * (c) 2011 Zynga Inc. * * @author Nicolas Gramlich * @since 18:37:32 - 08.08.2010 */ public class TSXParser extends DefaultHandler implements TMXConstants { // =========================================================== // Constants // =========================================================== // =========================================================== // Fields // =========================================================== private final Context mContext; private final TextureManager mTextureManager; private final TextureOptions mTextureOptions; private TMXTileSet mTMXTileSet; private int mLastTileSetTileID; @SuppressWarnings("unused") private boolean mInTileset; @SuppressWarnings("unused") private boolean mInImage; @SuppressWarnings("unused") private boolean mInTile; @SuppressWarnings("unused") private boolean mInProperties; @SuppressWarnings("unused") private boolean mInProperty; private final int mFirstGlobalTileID; // =========================================================== // Constructors // =========================================================== public TSXParser(final Context pContext, final TextureManager pTextureManager, final TextureOptions pTextureOptions, final int pFirstGlobalTileID) { this.mContext = pContext; this.mTextureManager = pTextureManager; this.mTextureOptions = pTextureOptions; this.mFirstGlobalTileID = pFirstGlobalTileID; } // =========================================================== // Getter & Setter // =========================================================== TMXTileSet getTMXTileSet() { return this.mTMXTileSet; } // =========================================================== // Methods for/from SuperClass/Interfaces // =========================================================== @Override public void startElement(final String pUri, final String pLocalName, final String pQualifiedName, final Attributes pAttributes) throws SAXException { if(pLocalName.equals(TAG_TILESET)){ this.mInTileset = true; this.mTMXTileSet = new TMXTileSet(this.mFirstGlobalTileID, pAttributes, this.mTextureOptions); } else if(pLocalName.equals(TAG_IMAGE)){ this.mInImage = true; this.mTMXTileSet.setImageSource(this.mContext, this.mTextureManager, pAttributes); } else if(pLocalName.equals(TAG_TILE)) { this.mInTile = true; this.mLastTileSetTileID = SAXUtils.getIntAttributeOrThrow(pAttributes, TAG_TILE_ATTRIBUTE_ID); } else if(pLocalName.equals(TAG_PROPERTIES)) { this.mInProperties = true; } else if(pLocalName.equals(TAG_PROPERTY)) { this.mInProperty = true; this.mTMXTileSet.addTMXTileProperty(this.mLastTileSetTileID, new TMXTileProperty(pAttributes)); } else { throw new TMXParseException("Unexpected start tag: '" + pLocalName + "'."); } } @Override public void endElement(final String pUri, final String pLocalName, final String pQualifiedName) throws SAXException { if(pLocalName.equals(TAG_TILESET)){ this.mInTileset = false; } else if(pLocalName.equals(TAG_IMAGE)){ this.mInImage = false; } else if(pLocalName.equals(TAG_TILE)) { this.mInTile = false; } else if(pLocalName.equals(TAG_PROPERTIES)) { this.mInProperties = false; } else if(pLocalName.equals(TAG_PROPERTY)) { this.mInProperty = false; } else { throw new TMXParseException("Unexpected end tag: '" + pLocalName + "'."); } } // =========================================================== // Methods // =========================================================== // =========================================================== // Inner and Anonymous Classes // =========================================================== }
Java
package org.anddev.andengine.entity.layer.tiled.tmx; import org.anddev.andengine.entity.layer.tiled.tmx.util.constants.TMXConstants; import org.anddev.andengine.util.SAXUtils; import org.xml.sax.Attributes; /** * (c) 2010 Nicolas Gramlich * (c) 2011 Zynga Inc. * * @author Nicolas Gramlich * @since 11:21:01 - 29.07.2010 */ public class TMXObject implements TMXConstants { // =========================================================== // Constants // =========================================================== // =========================================================== // Fields // =========================================================== private final String mName; private final String mType; private final int mX; private final int mY; private final int mWidth; private final int mHeight; private final TMXProperties<TMXObjectProperty> mTMXObjectProperties = new TMXProperties<TMXObjectProperty>(); // =========================================================== // Constructors // =========================================================== public TMXObject(final Attributes pAttributes) { this.mName = pAttributes.getValue("", TAG_OBJECT_ATTRIBUTE_NAME); this.mType = pAttributes.getValue("", TAG_OBJECT_ATTRIBUTE_TYPE); this.mX = SAXUtils.getIntAttributeOrThrow(pAttributes, TAG_OBJECT_ATTRIBUTE_X); this.mY = SAXUtils.getIntAttributeOrThrow(pAttributes, TAG_OBJECT_ATTRIBUTE_Y); this.mWidth = SAXUtils.getIntAttribute(pAttributes, TAG_OBJECT_ATTRIBUTE_WIDTH, 0); this.mHeight = SAXUtils.getIntAttribute(pAttributes, TAG_OBJECT_ATTRIBUTE_HEIGHT, 0); } // =========================================================== // Getter & Setter // =========================================================== public String getName() { return this.mName; } public String getType() { return this.mType; } public int getX() { return this.mX; } public int getY() { return this.mY; } public int getWidth() { return this.mWidth; } public int getHeight() { return this.mHeight; } public void addTMXObjectProperty(final TMXObjectProperty pTMXObjectProperty) { this.mTMXObjectProperties.add(pTMXObjectProperty); } public TMXProperties<TMXObjectProperty> getTMXObjectProperties() { return this.mTMXObjectProperties; } // =========================================================== // Methods for/from SuperClass/Interfaces // =========================================================== // =========================================================== // Methods // =========================================================== // =========================================================== // Inner and Anonymous Classes // =========================================================== }
Java
package org.anddev.andengine.entity.layer.tiled.tmx; import java.util.ArrayList; import javax.microedition.khronos.opengles.GL11; import org.anddev.andengine.entity.layer.tiled.tmx.util.constants.TMXConstants; import org.anddev.andengine.opengl.texture.region.TextureRegion; import org.anddev.andengine.opengl.vertex.RectangleVertexBuffer; import org.anddev.andengine.util.SAXUtils; import org.xml.sax.Attributes; import android.util.SparseArray; /** * (c) 2010 Nicolas Gramlich * (c) 2011 Zynga Inc. * * @author Nicolas Gramlich * @since 19:38:11 - 20.07.2010 */ public class TMXTiledMap implements TMXConstants { // =========================================================== // Constants // =========================================================== // =========================================================== // Fields // =========================================================== private final String mOrientation; private final int mTileColumns; private final int mTilesRows; private final int mTileWidth; private final int mTileHeight; private final ArrayList<TMXTileSet> mTMXTileSets = new ArrayList<TMXTileSet>(); private final ArrayList<TMXLayer> mTMXLayers = new ArrayList<TMXLayer>(); private final ArrayList<TMXObjectGroup> mTMXObjectGroups = new ArrayList<TMXObjectGroup>(); private final RectangleVertexBuffer mSharedVertexBuffer; private final SparseArray<TextureRegion> mGlobalTileIDToTextureRegionCache = new SparseArray<TextureRegion>(); private final SparseArray<TMXProperties<TMXTileProperty>> mGlobalTileIDToTMXTilePropertiesCache = new SparseArray<TMXProperties<TMXTileProperty>>(); private final TMXProperties<TMXTiledMapProperty> mTMXTiledMapProperties = new TMXProperties<TMXTiledMapProperty>(); // =========================================================== // Constructors // =========================================================== TMXTiledMap(final Attributes pAttributes) { this.mOrientation = pAttributes.getValue("", TAG_MAP_ATTRIBUTE_ORIENTATION); if(!this.mOrientation.equals(TAG_MAP_ATTRIBUTE_ORIENTATION_VALUE_ORTHOGONAL)) { throw new IllegalArgumentException(TAG_MAP_ATTRIBUTE_ORIENTATION + ": '" + this.mOrientation + "' is not supported."); } this.mTileColumns = SAXUtils.getIntAttributeOrThrow(pAttributes, TAG_MAP_ATTRIBUTE_WIDTH); this.mTilesRows = SAXUtils.getIntAttributeOrThrow(pAttributes, TAG_MAP_ATTRIBUTE_HEIGHT); this.mTileWidth = SAXUtils.getIntAttributeOrThrow(pAttributes, TAG_MAP_ATTRIBUTE_TILEWIDTH); this.mTileHeight = SAXUtils.getIntAttributeOrThrow(pAttributes, TAG_MAP_ATTRIBUTE_TILEHEIGHT); this.mSharedVertexBuffer = new RectangleVertexBuffer(GL11.GL_STATIC_DRAW, true); this.mSharedVertexBuffer.update(this.mTileWidth, this.mTileHeight); } // =========================================================== // Getter & Setter // =========================================================== public final String getOrientation() { return this.mOrientation; } /** * @deprecated Instead use {@link TMXTiledMap#getTileColumns()} * {@link TMXTiledMap#getTileWidth()}. * @return */ @Deprecated public final int getWidth() { return this.mTileColumns; } public final int getTileColumns() { return this.mTileColumns; } /** * @deprecated Instead use {@link TMXTiledMap#getTileRows()} * {@link TMXTiledMap#getTileHeight()}. * @return */ @Deprecated public final int getHeight() { return this.mTilesRows; } public final int getTileRows() { return this.mTilesRows; } public final int getTileWidth() { return this.mTileWidth; } public final int getTileHeight() { return this.mTileHeight; } public RectangleVertexBuffer getSharedVertexBuffer() { return this.mSharedVertexBuffer; } void addTMXTileSet(final TMXTileSet pTMXTileSet) { this.mTMXTileSets.add(pTMXTileSet); } public ArrayList<TMXTileSet> getTMXTileSets() { return this.mTMXTileSets; } void addTMXLayer(final TMXLayer pTMXLayer) { this.mTMXLayers.add(pTMXLayer); } public ArrayList<TMXLayer> getTMXLayers() { return this.mTMXLayers; } void addTMXObjectGroup(final TMXObjectGroup pTMXObjectGroup) { this.mTMXObjectGroups.add(pTMXObjectGroup); } public ArrayList<TMXObjectGroup> getTMXObjectGroups() { return this.mTMXObjectGroups; } public TMXProperties<TMXTileProperty> getTMXTilePropertiesByGlobalTileID(final int pGlobalTileID) { return this.mGlobalTileIDToTMXTilePropertiesCache.get(pGlobalTileID); } public void addTMXTiledMapProperty(final TMXTiledMapProperty pTMXTiledMapProperty) { this.mTMXTiledMapProperties.add(pTMXTiledMapProperty); } public TMXProperties<TMXTiledMapProperty> getTMXTiledMapProperties() { return this.mTMXTiledMapProperties; } // =========================================================== // Methods for/from SuperClass/Interfaces // =========================================================== @Override protected void finalize() throws Throwable { if(this.mSharedVertexBuffer.isManaged()) { this.mSharedVertexBuffer.unloadFromActiveBufferObjectManager(); } } // =========================================================== // Methods // =========================================================== public TMXProperties<TMXTileProperty> getTMXTileProperties(final int pGlobalTileID) { final SparseArray<TMXProperties<TMXTileProperty>> globalTileIDToTMXTilePropertiesCache = this.mGlobalTileIDToTMXTilePropertiesCache; final TMXProperties<TMXTileProperty> cachedTMXTileProperties = globalTileIDToTMXTilePropertiesCache.get(pGlobalTileID); if(cachedTMXTileProperties != null) { return cachedTMXTileProperties; } else { final ArrayList<TMXTileSet> tmxTileSets = this.mTMXTileSets; for(int i = tmxTileSets.size() - 1; i >= 0; i--) { final TMXTileSet tmxTileSet = tmxTileSets.get(i); if(pGlobalTileID >= tmxTileSet.getFirstGlobalTileID()) { return tmxTileSet.getTMXTilePropertiesFromGlobalTileID(pGlobalTileID); } } throw new IllegalArgumentException("No TMXTileProperties found for pGlobalTileID=" + pGlobalTileID); } } public TextureRegion getTextureRegionFromGlobalTileID(final int pGlobalTileID) { final SparseArray<TextureRegion> globalTileIDToTextureRegionCache = this.mGlobalTileIDToTextureRegionCache; final TextureRegion cachedTextureRegion = globalTileIDToTextureRegionCache.get(pGlobalTileID); if(cachedTextureRegion != null) { return cachedTextureRegion; } else { final ArrayList<TMXTileSet> tmxTileSets = this.mTMXTileSets; for(int i = tmxTileSets.size() - 1; i >= 0; i--) { final TMXTileSet tmxTileSet = tmxTileSets.get(i); if(pGlobalTileID >= tmxTileSet.getFirstGlobalTileID()) { final TextureRegion textureRegion = tmxTileSet.getTextureRegionFromGlobalTileID(pGlobalTileID); /* Add to cache for the all future pGlobalTileIDs with the same value. */ globalTileIDToTextureRegionCache.put(pGlobalTileID, textureRegion); return textureRegion; } } throw new IllegalArgumentException("No TextureRegion found for pGlobalTileID=" + pGlobalTileID); } } // =========================================================== // Inner and Anonymous Classes // =========================================================== }
Java
package org.anddev.andengine.entity.layer.tiled.tmx; import org.anddev.andengine.entity.layer.tiled.tmx.util.constants.TMXConstants; import org.anddev.andengine.entity.layer.tiled.tmx.util.exception.TMXParseException; import org.anddev.andengine.opengl.texture.TextureManager; import org.anddev.andengine.opengl.texture.TextureOptions; import org.anddev.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlas; import org.anddev.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlasFactory; import org.anddev.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlasTextureRegionFactory; import org.anddev.andengine.opengl.texture.atlas.bitmap.source.AssetBitmapTextureAtlasSource; import org.anddev.andengine.opengl.texture.atlas.bitmap.source.decorator.ColorKeyBitmapTextureAtlasSourceDecorator; import org.anddev.andengine.opengl.texture.atlas.bitmap.source.decorator.shape.RectangleBitmapTextureAtlasSourceDecoratorShape; import org.anddev.andengine.opengl.texture.bitmap.BitmapTexture.BitmapTextureFormat; import org.anddev.andengine.opengl.texture.region.TextureRegion; import org.anddev.andengine.util.SAXUtils; import org.xml.sax.Attributes; import android.content.Context; import android.graphics.Color; import android.util.SparseArray; /** * (c) 2010 Nicolas Gramlich * (c) 2011 Zynga Inc. * * @author Nicolas Gramlich * @since 19:03:24 - 20.07.2010 */ public class TMXTileSet implements TMXConstants { // =========================================================== // Constants // =========================================================== // =========================================================== // Fields // =========================================================== private final int mFirstGlobalTileID; private final String mName; private final int mTileWidth; private final int mTileHeight; private String mImageSource; private BitmapTextureAtlas mBitmapTextureAtlas; private final TextureOptions mTextureOptions; private int mTilesHorizontal; @SuppressWarnings("unused") private int mTilesVertical; private final int mSpacing; private final int mMargin; private final SparseArray<TMXProperties<TMXTileProperty>> mTMXTileProperties = new SparseArray<TMXProperties<TMXTileProperty>>(); // =========================================================== // Constructors // =========================================================== TMXTileSet(final Attributes pAttributes, final TextureOptions pTextureOptions) { this(SAXUtils.getIntAttribute(pAttributes, TAG_TILESET_ATTRIBUTE_FIRSTGID, 1), pAttributes, pTextureOptions); } TMXTileSet(final int pFirstGlobalTileID, final Attributes pAttributes, final TextureOptions pTextureOptions) { this.mFirstGlobalTileID = pFirstGlobalTileID; this.mName = pAttributes.getValue("", TAG_TILESET_ATTRIBUTE_NAME); this.mTileWidth = SAXUtils.getIntAttributeOrThrow(pAttributes, TAG_TILESET_ATTRIBUTE_TILEWIDTH); this.mTileHeight = SAXUtils.getIntAttributeOrThrow(pAttributes, TAG_TILESET_ATTRIBUTE_TILEHEIGHT); this.mSpacing = SAXUtils.getIntAttribute(pAttributes, TAG_TILESET_ATTRIBUTE_SPACING, 0); this.mMargin = SAXUtils.getIntAttribute(pAttributes, TAG_TILESET_ATTRIBUTE_MARGIN, 0); this.mTextureOptions = pTextureOptions; } // =========================================================== // Getter & Setter // =========================================================== public final int getFirstGlobalTileID() { return this.mFirstGlobalTileID; } public final String getName() { return this.mName; } public final int getTileWidth() { return this.mTileWidth; } public final int getTileHeight() { return this.mTileHeight; } public BitmapTextureAtlas getBitmapTextureAtlas() { return this.mBitmapTextureAtlas; } public void setImageSource(final Context pContext, final TextureManager pTextureManager, final Attributes pAttributes) throws TMXParseException { this.mImageSource = pAttributes.getValue("", TAG_IMAGE_ATTRIBUTE_SOURCE); final AssetBitmapTextureAtlasSource assetBitmapTextureAtlasSource = new AssetBitmapTextureAtlasSource(pContext, this.mImageSource); this.mTilesHorizontal = TMXTileSet.determineCount(assetBitmapTextureAtlasSource.getWidth(), this.mTileWidth, this.mMargin, this.mSpacing); this.mTilesVertical = TMXTileSet.determineCount(assetBitmapTextureAtlasSource.getHeight(), this.mTileHeight, this.mMargin, this.mSpacing); this.mBitmapTextureAtlas = BitmapTextureAtlasFactory.createForTextureAtlasSourceSize(BitmapTextureFormat.RGBA_8888, assetBitmapTextureAtlasSource, this.mTextureOptions); // TODO Make TextureFormat variable final String transparentColor = SAXUtils.getAttribute(pAttributes, TAG_IMAGE_ATTRIBUTE_TRANS, null); if(transparentColor == null) { BitmapTextureAtlasTextureRegionFactory.createFromSource(this.mBitmapTextureAtlas, assetBitmapTextureAtlasSource, 0, 0); } else { try{ final int color = Color.parseColor((transparentColor.charAt(0) == '#') ? transparentColor : "#" + transparentColor); BitmapTextureAtlasTextureRegionFactory.createFromSource(this.mBitmapTextureAtlas, new ColorKeyBitmapTextureAtlasSourceDecorator(assetBitmapTextureAtlasSource, RectangleBitmapTextureAtlasSourceDecoratorShape.getDefaultInstance(), color), 0, 0); } catch (final IllegalArgumentException e) { throw new TMXParseException("Illegal value: '" + transparentColor + "' for attribute 'trans' supplied!", e); } } pTextureManager.loadTexture(this.mBitmapTextureAtlas); } public String getImageSource() { return this.mImageSource; } public SparseArray<TMXProperties<TMXTileProperty>> getTMXTileProperties() { return this.mTMXTileProperties; } // =========================================================== // Methods for/from SuperClass/Interfaces // =========================================================== // =========================================================== // Methods // =========================================================== public TMXProperties<TMXTileProperty> getTMXTilePropertiesFromGlobalTileID(final int pGlobalTileID) { final int localTileID = pGlobalTileID - this.mFirstGlobalTileID; return this.mTMXTileProperties.get(localTileID); } public void addTMXTileProperty(final int pLocalTileID, final TMXTileProperty pTMXTileProperty) { final TMXProperties<TMXTileProperty> existingProperties = this.mTMXTileProperties.get(pLocalTileID); if(existingProperties != null) { existingProperties.add(pTMXTileProperty); } else { final TMXProperties<TMXTileProperty> newProperties = new TMXProperties<TMXTileProperty>(); newProperties.add(pTMXTileProperty); this.mTMXTileProperties.put(pLocalTileID, newProperties); } } public TextureRegion getTextureRegionFromGlobalTileID(final int pGlobalTileID) { final int localTileID = pGlobalTileID - this.mFirstGlobalTileID; final int tileColumn = localTileID % this.mTilesHorizontal; final int tileRow = localTileID / this.mTilesHorizontal; final int texturePositionX = this.mMargin + (this.mSpacing + this.mTileWidth) * tileColumn; final int texturePositionY = this.mMargin + (this.mSpacing + this.mTileHeight) * tileRow; return new TextureRegion(this.mBitmapTextureAtlas, texturePositionX, texturePositionY, this.mTileWidth, this.mTileHeight); } private static int determineCount(final int pTotalExtent, final int pTileExtent, final int pMargin, final int pSpacing) { int count = 0; int remainingExtent = pTotalExtent; remainingExtent -= pMargin * 2; while(remainingExtent > 0) { remainingExtent -= pTileExtent; remainingExtent -= pSpacing; count++; } return count; } // =========================================================== // Inner and Anonymous Classes // =========================================================== }
Java
package org.anddev.andengine.entity.layer.tiled.tmx; import java.io.BufferedInputStream; import java.io.IOException; import java.io.InputStream; import javax.xml.parsers.ParserConfigurationException; import javax.xml.parsers.SAXParser; import javax.xml.parsers.SAXParserFactory; import org.anddev.andengine.entity.layer.tiled.tmx.util.exception.TSXLoadException; import org.anddev.andengine.opengl.texture.TextureManager; import org.anddev.andengine.opengl.texture.TextureOptions; import org.xml.sax.InputSource; import org.xml.sax.SAXException; import org.xml.sax.XMLReader; import android.content.Context; /** * (c) 2010 Nicolas Gramlich * (c) 2011 Zynga Inc. * * @author Nicolas Gramlich * @since 17:18:37 - 08.08.2010 */ public class TSXLoader { // =========================================================== // Constants // =========================================================== // =========================================================== // Fields // =========================================================== private final Context mContext; private final TextureManager mTextureManager; private final TextureOptions mTextureOptions; // =========================================================== // Constructors // =========================================================== public TSXLoader(final Context pContext, final TextureManager pTextureManager, final TextureOptions pTextureOptions) { this.mContext = pContext; this.mTextureManager = pTextureManager; this.mTextureOptions = pTextureOptions; } // =========================================================== // Getter & Setter // =========================================================== // =========================================================== // Methods for/from SuperClass/Interfaces // =========================================================== // =========================================================== // Methods // =========================================================== public TMXTileSet loadFromAsset(final Context pContext, final int pFirstGlobalTileID, final String pAssetPath) throws TSXLoadException { try { return this.load(pFirstGlobalTileID, pContext.getAssets().open(pAssetPath)); } catch (final IOException e) { throw new TSXLoadException("Could not load TMXTileSet from asset: " + pAssetPath, e); } } private TMXTileSet load(final int pFirstGlobalTileID, final InputStream pInputStream) throws TSXLoadException { try{ final SAXParserFactory spf = SAXParserFactory.newInstance(); final SAXParser sp = spf.newSAXParser(); final XMLReader xr = sp.getXMLReader(); final TSXParser tsxParser = new TSXParser(this.mContext, this.mTextureManager, this.mTextureOptions, pFirstGlobalTileID); xr.setContentHandler(tsxParser); xr.parse(new InputSource(new BufferedInputStream(pInputStream))); return tsxParser.getTMXTileSet(); } catch (final SAXException e) { throw new TSXLoadException(e); } catch (final ParserConfigurationException pe) { /* Doesn't happen. */ return null; } catch (final IOException e) { throw new TSXLoadException(e); } } // =========================================================== // Inner and Anonymous Classes // =========================================================== }
Java
package org.anddev.andengine.entity.layer.tiled.tmx.util.exception; import org.xml.sax.SAXException; /** * (c) 2010 Nicolas Gramlich * (c) 2011 Zynga Inc. * * @author Nicolas Gramlich * @since 00:10:02 - 28.07.2010 */ public class TMXParseException extends SAXException { // =========================================================== // Constants // =========================================================== private static final long serialVersionUID = 2213964295487921492L; // =========================================================== // Fields // =========================================================== // =========================================================== // Constructors // =========================================================== public TMXParseException() { super(); } public TMXParseException(final String pDetailMessage) { super(pDetailMessage); } public TMXParseException(final Exception pException) { super(pException); } public TMXParseException(final String pMessage, final Exception pException) { super(pMessage, pException); } // =========================================================== // Getter & Setter // =========================================================== // =========================================================== // Methods for/from SuperClass/Interfaces // =========================================================== // =========================================================== // Methods // =========================================================== // =========================================================== // Inner and Anonymous Classes // =========================================================== }
Java
package org.anddev.andengine.entity.layer.tiled.tmx.util.exception; /** * (c) 2010 Nicolas Gramlich * (c) 2011 Zynga Inc. * * @author Nicolas Gramlich * @since 00:10:02 - 28.07.2010 */ public class TMXLoadException extends TMXException { // =========================================================== // Constants // =========================================================== private static final long serialVersionUID = -8295358631698809883L; // =========================================================== // Fields // =========================================================== // =========================================================== // Constructors // =========================================================== public TMXLoadException() { super(); } public TMXLoadException(final String pDetailMessage, final Throwable pThrowable) { super(pDetailMessage, pThrowable); } public TMXLoadException(final String pDetailMessage) { super(pDetailMessage); } public TMXLoadException(final Throwable pThrowable) { super(pThrowable); } // =========================================================== // Getter & Setter // =========================================================== // =========================================================== // Methods for/from SuperClass/Interfaces // =========================================================== // =========================================================== // Methods // =========================================================== // =========================================================== // Inner and Anonymous Classes // =========================================================== }
Java
package org.anddev.andengine.entity.layer.tiled.tmx.util.exception; /** * (c) 2010 Nicolas Gramlich * (c) 2011 Zynga Inc. * * @author Nicolas Gramlich * @since 18:37:53 - 08.08.2010 */ public class TSXLoadException extends TMXException { // =========================================================== // Constants // =========================================================== private static final long serialVersionUID = 10055223972707703L; // =========================================================== // Fields // =========================================================== // =========================================================== // Constructors // =========================================================== public TSXLoadException() { super(); } public TSXLoadException(final String pDetailMessage, final Throwable pThrowable) { super(pDetailMessage, pThrowable); } public TSXLoadException(final String pDetailMessage) { super(pDetailMessage); } public TSXLoadException(final Throwable pThrowable) { super(pThrowable); } // =========================================================== // Getter & Setter // =========================================================== // =========================================================== // Methods for/from SuperClass/Interfaces // =========================================================== // =========================================================== // Methods // =========================================================== // =========================================================== // Inner and Anonymous Classes // =========================================================== }
Java
package org.anddev.andengine.entity.layer.tiled.tmx.util.exception; import org.xml.sax.SAXException; /** * (c) 2010 Nicolas Gramlich * (c) 2011 Zynga Inc. * * @author Nicolas Gramlich * @since 18:37:46 - 08.08.2010 */ public class TSXParseException extends SAXException { // =========================================================== // Constants // =========================================================== private static final long serialVersionUID = -7598783248970268198L; // =========================================================== // Fields // =========================================================== // =========================================================== // Constructors // =========================================================== public TSXParseException() { super(); } public TSXParseException(final String pDetailMessage) { super(pDetailMessage); } public TSXParseException(final Exception pException) { super(pException); } public TSXParseException(final String pMessage, final Exception pException) { super(pMessage, pException); } // =========================================================== // Getter & Setter // =========================================================== // =========================================================== // Methods for/from SuperClass/Interfaces // =========================================================== // =========================================================== // Methods // =========================================================== // =========================================================== // Inner and Anonymous Classes // =========================================================== }
Java
package org.anddev.andengine.entity.layer.tiled.tmx.util.exception; /** * (c) 2010 Nicolas Gramlich * (c) 2011 Zynga Inc. * * @author Nicolas Gramlich * @since 17:20:25 - 08.08.2010 */ public abstract class TMXException extends Exception { // =========================================================== // Constants // =========================================================== private static final long serialVersionUID = 337819550394833109L; // =========================================================== // Fields // =========================================================== // =========================================================== // Constructors // =========================================================== public TMXException() { super(); } public TMXException(final String pDetailMessage, final Throwable pThrowable) { super(pDetailMessage, pThrowable); } public TMXException(final String pDetailMessage) { super(pDetailMessage); } public TMXException(final Throwable pThrowable) { super(pThrowable); } // =========================================================== // Getter & Setter // =========================================================== // =========================================================== // Methods for/from SuperClass/Interfaces // =========================================================== // =========================================================== // Methods // =========================================================== // =========================================================== // Inner and Anonymous Classes // =========================================================== }
Java
package org.anddev.andengine.entity.layer.tiled.tmx.util.constants; /** * See: <a href="http://sourceforge.net/apps/mediawiki/tiled/index.php?title=TMX_Map_Format">TMX Map Format</a>. * * (c) 2010 Nicolas Gramlich * (c) 2011 Zynga Inc. * * @author Nicolas Gramlich * @since 19:20:22 - 20.07.2010 */ public interface TMXConstants { // =========================================================== // Final Fields // =========================================================== public static final int BYTES_PER_GLOBALTILEID = 4; public static final String TAG_MAP = "map"; public static final String TAG_MAP_ATTRIBUTE_ORIENTATION = "orientation"; public static final String TAG_MAP_ATTRIBUTE_ORIENTATION_VALUE_ORTHOGONAL = "orthogonal"; public static final String TAG_MAP_ATTRIBUTE_ORIENTATION_VALUE_ISOMETRIC = "isometric"; public static final String TAG_MAP_ATTRIBUTE_WIDTH = "width"; public static final String TAG_MAP_ATTRIBUTE_HEIGHT = "height"; public static final String TAG_MAP_ATTRIBUTE_TILEWIDTH = "tilewidth"; public static final String TAG_MAP_ATTRIBUTE_TILEHEIGHT = "tileheight"; public static final String TAG_TILESET = "tileset"; public static final String TAG_TILESET_ATTRIBUTE_FIRSTGID = "firstgid"; public static final String TAG_TILESET_ATTRIBUTE_SOURCE = "source"; public static final String TAG_TILESET_ATTRIBUTE_NAME = "name"; public static final String TAG_TILESET_ATTRIBUTE_TILEWIDTH = "tilewidth"; public static final String TAG_TILESET_ATTRIBUTE_TILEHEIGHT = "tileheight"; public static final String TAG_TILESET_ATTRIBUTE_SPACING = "spacing"; public static final String TAG_TILESET_ATTRIBUTE_MARGIN = "margin"; public static final String TAG_IMAGE = "image"; public static final String TAG_IMAGE_ATTRIBUTE_SOURCE = "source"; public static final String TAG_IMAGE_ATTRIBUTE_TRANS = "trans"; public static final String TAG_TILE = "tile"; public static final String TAG_TILE_ATTRIBUTE_ID = "id"; public static final String TAG_TILE_ATTRIBUTE_GID = "gid"; public static final String TAG_PROPERTIES = "properties"; public static final String TAG_PROPERTY = "property"; public static final String TAG_PROPERTY_ATTRIBUTE_NAME = "name"; public static final String TAG_PROPERTY_ATTRIBUTE_VALUE = "value"; public static final String TAG_LAYER = "layer"; public static final String TAG_LAYER_ATTRIBUTE_NAME = "name"; public static final String TAG_LAYER_ATTRIBUTE_WIDTH = "width"; public static final String TAG_LAYER_ATTRIBUTE_HEIGHT = "height"; public static final String TAG_LAYER_ATTRIBUTE_VISIBLE = "visible"; public static final int TAG_LAYER_ATTRIBUTE_VISIBLE_VALUE_DEFAULT = 1; public static final String TAG_LAYER_ATTRIBUTE_OPACITY = "opacity"; public static final float TAG_LAYER_ATTRIBUTE_OPACITY_VALUE_DEFAULT = 1.0f; public static final String TAG_DATA = "data"; public static final String TAG_DATA_ATTRIBUTE_ENCODING = "encoding"; public static final String TAG_DATA_ATTRIBUTE_ENCODING_VALUE_BASE64 = "base64"; public static final String TAG_DATA_ATTRIBUTE_COMPRESSION = "compression"; public static final String TAG_DATA_ATTRIBUTE_COMPRESSION_VALUE_GZIP = "gzip"; public static final String TAG_DATA_ATTRIBUTE_COMPRESSION_VALUE_ZLIB = "zlib"; public static final String TAG_OBJECTGROUP = "objectgroup"; public static final String TAG_OBJECTGROUP_ATTRIBUTE_NAME = "name"; public static final String TAG_OBJECTGROUP_ATTRIBUTE_WIDTH = "width"; public static final String TAG_OBJECTGROUP_ATTRIBUTE_HEIGHT = "height"; public static final String TAG_OBJECT = "object"; public static final String TAG_OBJECT_ATTRIBUTE_NAME = "name"; public static final String TAG_OBJECT_ATTRIBUTE_TYPE = "type"; public static final String TAG_OBJECT_ATTRIBUTE_X = "x"; public static final String TAG_OBJECT_ATTRIBUTE_Y = "y"; public static final String TAG_OBJECT_ATTRIBUTE_WIDTH = "width"; public static final String TAG_OBJECT_ATTRIBUTE_HEIGHT = "height"; // =========================================================== // Methods // =========================================================== }
Java
package org.anddev.andengine.entity.layer.tiled.tmx; import org.anddev.andengine.opengl.texture.region.TextureRegion; /** * (c) 2010 Nicolas Gramlich * (c) 2011 Zynga Inc. * * @author Nicolas Gramlich * @since 10:39:48 - 05.08.2010 */ public class TMXTile { // =========================================================== // Constants // =========================================================== // =========================================================== // Fields // =========================================================== int mGlobalTileID; private final int mTileRow; private final int mTileColumn; private final int mTileWidth; private final int mTileHeight; TextureRegion mTextureRegion; // =========================================================== // Constructors // =========================================================== public TMXTile(final int pGlobalTileID, final int pTileColumn, final int pTileRow, final int pTileWidth, final int pTileHeight, final TextureRegion pTextureRegion) { this.mGlobalTileID = pGlobalTileID; this.mTileRow = pTileRow; this.mTileColumn = pTileColumn; this.mTileWidth = pTileWidth; this.mTileHeight = pTileHeight; this.mTextureRegion = pTextureRegion; } // =========================================================== // Getter & Setter // =========================================================== public int getGlobalTileID() { return this.mGlobalTileID; } public int getTileRow() { return this.mTileRow; } public int getTileColumn() { return this.mTileColumn; } public int getTileX() { return this.mTileColumn * this.mTileWidth; } public int getTileY() { return this.mTileRow * this.mTileHeight; } public int getTileWidth() { return this.mTileWidth; } public int getTileHeight() { return this.mTileHeight; } public TextureRegion getTextureRegion() { return this.mTextureRegion; } /** * Note this will also set the {@link TextureRegion} with the associated pGlobalTileID of the {@link TMXTiledMap}. * @param pTMXTiledMap * @param pGlobalTileID */ public void setGlobalTileID(final TMXTiledMap pTMXTiledMap, final int pGlobalTileID) { this.mGlobalTileID = pGlobalTileID; this.mTextureRegion = pTMXTiledMap.getTextureRegionFromGlobalTileID(pGlobalTileID); } /** * You'd probably want to call {@link TMXTile#setGlobalTileID(TMXTiledMap, int)} instead. * @param pTextureRegion */ public void setTextureRegion(final TextureRegion pTextureRegion) { this.mTextureRegion = pTextureRegion; } public TMXProperties<TMXTileProperty> getTMXTileProperties(final TMXTiledMap pTMXTiledMap) { return pTMXTiledMap.getTMXTileProperties(this.mGlobalTileID); } // =========================================================== // Methods for/from SuperClass/Interfaces // =========================================================== // =========================================================== // Methods // =========================================================== // =========================================================== // Inner and Anonymous Classes // =========================================================== }
Java
package org.anddev.andengine.entity.layer.tiled.tmx; import org.xml.sax.Attributes; /** * (c) 2010 Nicolas Gramlich * (c) 2011 Zynga Inc. * * @author Nicolas Gramlich * @since 18:48:41 - 12.10.2010 */ public class TMXTiledMapProperty extends TMXProperty { // =========================================================== // Constants // =========================================================== // =========================================================== // Fields // =========================================================== // =========================================================== // Constructors // =========================================================== public TMXTiledMapProperty(final Attributes pAttributes) { super(pAttributes); } // =========================================================== // Getter & Setter // =========================================================== // =========================================================== // Methods for/from SuperClass/Interfaces // =========================================================== // =========================================================== // Methods // =========================================================== // =========================================================== // Inner and Anonymous Classes // =========================================================== }
Java
package org.anddev.andengine.entity.layer.tiled.tmx; import static org.anddev.andengine.util.constants.Constants.VERTEX_INDEX_X; import static org.anddev.andengine.util.constants.Constants.VERTEX_INDEX_Y; import java.io.ByteArrayInputStream; import java.io.DataInputStream; import java.io.IOException; import java.io.InputStream; import java.util.zip.GZIPInputStream; import javax.microedition.khronos.opengles.GL10; import javax.microedition.khronos.opengles.GL11; import org.anddev.andengine.collision.RectangularShapeCollisionChecker; import org.anddev.andengine.engine.camera.Camera; import org.anddev.andengine.entity.layer.tiled.tmx.TMXLoader.ITMXTilePropertiesListener; import org.anddev.andengine.entity.layer.tiled.tmx.util.constants.TMXConstants; import org.anddev.andengine.entity.shape.RectangularShape; import org.anddev.andengine.opengl.texture.region.TextureRegion; import org.anddev.andengine.opengl.util.GLHelper; import org.anddev.andengine.util.Base64; import org.anddev.andengine.util.Base64InputStream; import org.anddev.andengine.util.MathUtils; import org.anddev.andengine.util.SAXUtils; import org.anddev.andengine.util.StreamUtils; import org.xml.sax.Attributes; /** * (c) 2010 Nicolas Gramlich * (c) 2011 Zynga Inc. * * @author Nicolas Gramlich * @since 20:27:31 - 20.07.2010 */ public class TMXLayer extends RectangularShape implements TMXConstants { // =========================================================== // Constants // =========================================================== // =========================================================== // Fields // =========================================================== private final TMXTiledMap mTMXTiledMap; private final String mName; private final int mTileColumns; private final int mTileRows; private final TMXTile[][] mTMXTiles; private int mTilesAdded; private final int mGlobalTileIDsExpected; private final float[] mCullingVertices = new float[2 * 4]; private final TMXProperties<TMXLayerProperty> mTMXLayerProperties = new TMXProperties<TMXLayerProperty>(); // =========================================================== // Constructors // =========================================================== public TMXLayer(final TMXTiledMap pTMXTiledMap, final Attributes pAttributes) { super(0, 0, 0, 0, null); this.mTMXTiledMap = pTMXTiledMap; this.mName = pAttributes.getValue("", TAG_LAYER_ATTRIBUTE_NAME); this.mTileColumns = SAXUtils.getIntAttributeOrThrow(pAttributes, TAG_LAYER_ATTRIBUTE_WIDTH); this.mTileRows = SAXUtils.getIntAttributeOrThrow(pAttributes, TAG_LAYER_ATTRIBUTE_HEIGHT); this.mTMXTiles = new TMXTile[this.mTileRows][this.mTileColumns]; super.mWidth = pTMXTiledMap.getTileWidth() * this.mTileColumns; final float width = super.mWidth; super.mBaseWidth = width; super.mHeight = pTMXTiledMap.getTileHeight() * this.mTileRows; final float height = super.mHeight; super.mBaseHeight = height; this.mRotationCenterX = width * 0.5f; this.mRotationCenterY = height * 0.5f; this.mScaleCenterX = this.mRotationCenterX; this.mScaleCenterY = this.mRotationCenterY; this.mGlobalTileIDsExpected = this.mTileColumns * this.mTileRows; this.setVisible(SAXUtils.getIntAttribute(pAttributes, TAG_LAYER_ATTRIBUTE_VISIBLE, TAG_LAYER_ATTRIBUTE_VISIBLE_VALUE_DEFAULT) == 1); this.setAlpha(SAXUtils.getFloatAttribute(pAttributes, TAG_LAYER_ATTRIBUTE_OPACITY, TAG_LAYER_ATTRIBUTE_OPACITY_VALUE_DEFAULT)); } // =========================================================== // Getter & Setter // =========================================================== public String getName() { return this.mName; } public int getTileColumns() { return this.mTileColumns; } public int getTileRows() { return this.mTileRows; } public TMXTile[][] getTMXTiles() { return this.mTMXTiles; } public TMXTile getTMXTile(final int pTileColumn, final int pTileRow) throws ArrayIndexOutOfBoundsException { return this.mTMXTiles[pTileRow][pTileColumn]; } /** * @param pX in SceneCoordinates. * @param pY in SceneCoordinates. * @return the {@link TMXTile} located at <code>pX/pY</code>. */ public TMXTile getTMXTileAt(final float pX, final float pY) { final float[] localCoords = this.convertSceneToLocalCoordinates(pX, pY); final TMXTiledMap tmxTiledMap = this.mTMXTiledMap; final int tileColumn = (int)(localCoords[VERTEX_INDEX_X] / tmxTiledMap.getTileWidth()); if(tileColumn < 0 || tileColumn > this.mTileColumns - 1) { return null; } final int tileRow = (int)(localCoords[VERTEX_INDEX_Y] / tmxTiledMap.getTileWidth()); if(tileRow < 0 || tileRow > this.mTileRows - 1) { return null; } return this.mTMXTiles[tileRow][tileColumn]; } public void addTMXLayerProperty(final TMXLayerProperty pTMXLayerProperty) { this.mTMXLayerProperties.add(pTMXLayerProperty); } public TMXProperties<TMXLayerProperty> getTMXLayerProperties() { return this.mTMXLayerProperties; } // =========================================================== // Methods for/from SuperClass/Interfaces // =========================================================== @Override @Deprecated public void setRotation(final float pRotation) { } @Override protected void onUpdateVertexBuffer() { /* Nothing. */ } @Override protected void onInitDraw(final GL10 pGL) { super.onInitDraw(pGL); GLHelper.enableTextures(pGL); GLHelper.enableTexCoordArray(pGL); } @Override protected void onApplyVertices(final GL10 pGL) { if(GLHelper.EXTENSIONS_VERTEXBUFFEROBJECTS) { final GL11 gl11 = (GL11)pGL; this.mTMXTiledMap.getSharedVertexBuffer().selectOnHardware(gl11); GLHelper.vertexZeroPointer(gl11); } else { GLHelper.vertexPointer(pGL, this.mTMXTiledMap.getSharedVertexBuffer().getFloatBuffer()); } } @Override protected void drawVertices(final GL10 pGL, final Camera pCamera) { final TMXTile[][] tmxTiles = this.mTMXTiles; final int tileColumns = this.mTileColumns; final int tileRows = this.mTileRows; final int tileWidth = this.mTMXTiledMap.getTileWidth(); final int tileHeight = this.mTMXTiledMap.getTileHeight(); final float scaledTileWidth = tileWidth * this.mScaleX; final float scaledTileHeight = tileHeight * this.mScaleY; final float[] cullingVertices = this.mCullingVertices; RectangularShapeCollisionChecker.fillVertices(this, cullingVertices); final float layerMinX = cullingVertices[VERTEX_INDEX_X]; final float layerMinY = cullingVertices[VERTEX_INDEX_Y]; final float cameraMinX = pCamera.getMinX(); final float cameraMinY = pCamera.getMinY(); final float cameraWidth = pCamera.getWidth(); final float cameraHeight = pCamera.getHeight(); /* Determine the area that is visible in the camera. */ final float firstColumnRaw = (cameraMinX - layerMinX) / scaledTileWidth; final int firstColumn = MathUtils.bringToBounds(0, tileColumns - 1, (int)Math.floor(firstColumnRaw)); final int lastColumn = MathUtils.bringToBounds(0, tileColumns - 1, (int)Math.ceil(firstColumnRaw + cameraWidth / scaledTileWidth)); final float firstRowRaw = (cameraMinY - layerMinY) / scaledTileHeight; final int firstRow = MathUtils.bringToBounds(0, tileRows - 1, (int)Math.floor(firstRowRaw)); final int lastRow = MathUtils.bringToBounds(0, tileRows - 1, (int)Math.floor(firstRowRaw + cameraHeight / scaledTileHeight)); final int visibleTilesTotalWidth = (lastColumn - firstColumn + 1) * tileWidth; pGL.glTranslatef(firstColumn * tileWidth, firstRow * tileHeight, 0); for(int row = firstRow; row <= lastRow; row++) { final TMXTile[] tmxTileRow = tmxTiles[row]; for(int column = firstColumn; column <= lastColumn; column++) { final TextureRegion textureRegion = tmxTileRow[column].mTextureRegion; if(textureRegion != null) { textureRegion.onApply(pGL); pGL.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0, 4); } pGL.glTranslatef(tileWidth, 0, 0); } /* Translate one row downwards and the back left to the first column. * Just like the 'Carriage Return' + 'New Line' (\r\n) on a typewriter. */ pGL.glTranslatef(-visibleTilesTotalWidth, tileHeight, 0); } pGL.glLoadIdentity(); } @Override protected void onManagedUpdate(final float pSecondsElapsed) { /* Nothing. */ } // =========================================================== // Methods // =========================================================== void initializeTMXTileFromXML(final Attributes pAttributes, final ITMXTilePropertiesListener pTMXTilePropertyListener) { this.addTileByGlobalTileID(SAXUtils.getIntAttributeOrThrow(pAttributes, TAG_TILE_ATTRIBUTE_GID), pTMXTilePropertyListener); } void initializeTMXTilesFromDataString(final String pDataString, final String pDataEncoding, final String pDataCompression, final ITMXTilePropertiesListener pTMXTilePropertyListener) throws IOException, IllegalArgumentException { DataInputStream dataIn = null; try{ InputStream in = new ByteArrayInputStream(pDataString.getBytes("UTF-8")); /* Wrap decoding Streams if necessary. */ if(pDataEncoding != null && pDataEncoding.equals(TAG_DATA_ATTRIBUTE_ENCODING_VALUE_BASE64)) { in = new Base64InputStream(in, Base64.DEFAULT); } if(pDataCompression != null){ if(pDataCompression.equals(TAG_DATA_ATTRIBUTE_COMPRESSION_VALUE_GZIP)) { in = new GZIPInputStream(in); } else { throw new IllegalArgumentException("Supplied compression '" + pDataCompression + "' is not supported yet."); } } dataIn = new DataInputStream(in); while(this.mTilesAdded < this.mGlobalTileIDsExpected) { final int globalTileID = this.readGlobalTileID(dataIn); this.addTileByGlobalTileID(globalTileID, pTMXTilePropertyListener); } } finally { StreamUtils.close(dataIn); } } private void addTileByGlobalTileID(final int pGlobalTileID, final ITMXTilePropertiesListener pTMXTilePropertyListener) { final TMXTiledMap tmxTiledMap = this.mTMXTiledMap; final int tilesHorizontal = this.mTileColumns; final int column = this.mTilesAdded % tilesHorizontal; final int row = this.mTilesAdded / tilesHorizontal; final TMXTile[][] tmxTiles = this.mTMXTiles; final TextureRegion tmxTileTextureRegion; if(pGlobalTileID == 0) { tmxTileTextureRegion = null; } else { tmxTileTextureRegion = tmxTiledMap.getTextureRegionFromGlobalTileID(pGlobalTileID); } final TMXTile tmxTile = new TMXTile(pGlobalTileID, column, row, this.mTMXTiledMap.getTileWidth(), this.mTMXTiledMap.getTileHeight(), tmxTileTextureRegion); tmxTiles[row][column] = tmxTile; if(pGlobalTileID != 0) { /* Notify the ITMXTilePropertiesListener if it exists. */ if(pTMXTilePropertyListener != null) { final TMXProperties<TMXTileProperty> tmxTileProperties = tmxTiledMap.getTMXTileProperties(pGlobalTileID); if(tmxTileProperties != null) { pTMXTilePropertyListener.onTMXTileWithPropertiesCreated(tmxTiledMap, this, tmxTile, tmxTileProperties); } } } this.mTilesAdded++; } private int readGlobalTileID(final DataInputStream pDataIn) throws IOException { final int lowestByte = pDataIn.read(); final int secondLowestByte = pDataIn.read(); final int secondHighestByte = pDataIn.read(); final int highestByte = pDataIn.read(); if(lowestByte < 0 || secondLowestByte < 0 || secondHighestByte < 0 || highestByte < 0) { throw new IllegalArgumentException("Couldn't read global Tile ID."); } return lowestByte | secondLowestByte << 8 |secondHighestByte << 16 | highestByte << 24; } // =========================================================== // Inner and Anonymous Classes // =========================================================== }
Java
package org.anddev.andengine.entity.layer.tiled.tmx; import org.anddev.andengine.entity.layer.tiled.tmx.util.constants.TMXConstants; import org.xml.sax.Attributes; /** * (c) 2010 Nicolas Gramlich * (c) 2011 Zynga Inc. * * @author Nicolas Gramlich * @since 10:14:06 - 27.07.2010 */ public class TMXProperty implements TMXConstants { // =========================================================== // Constants // =========================================================== // =========================================================== // Fields // =========================================================== private final String mName; private final String mValue; // =========================================================== // Constructors // =========================================================== public TMXProperty(final Attributes pAttributes) { this.mName = pAttributes.getValue("", TAG_PROPERTY_ATTRIBUTE_NAME); this.mValue = pAttributes.getValue("", TAG_PROPERTY_ATTRIBUTE_VALUE); } // =========================================================== // Getter & Setter // =========================================================== public String getName() { return this.mName; } public String getValue() { return this.mValue; } // =========================================================== // Methods for/from SuperClass/Interfaces // =========================================================== @Override public String toString() { return this.mName + "='" + this.mValue + "'"; } // =========================================================== // Methods // =========================================================== // =========================================================== // Inner and Anonymous Classes // =========================================================== }
Java
package org.anddev.andengine.entity.layer.tiled.tmx; import java.io.IOException; import java.util.ArrayList; import org.anddev.andengine.entity.layer.tiled.tmx.TMXLoader.ITMXTilePropertiesListener; import org.anddev.andengine.entity.layer.tiled.tmx.util.constants.TMXConstants; import org.anddev.andengine.entity.layer.tiled.tmx.util.exception.TMXParseException; import org.anddev.andengine.entity.layer.tiled.tmx.util.exception.TSXLoadException; import org.anddev.andengine.opengl.texture.TextureManager; import org.anddev.andengine.opengl.texture.TextureOptions; import org.anddev.andengine.util.Debug; import org.anddev.andengine.util.SAXUtils; import org.xml.sax.Attributes; import org.xml.sax.SAXException; import org.xml.sax.helpers.DefaultHandler; import android.content.Context; /** * (c) 2010 Nicolas Gramlich * (c) 2011 Zynga Inc. * * @author Nicolas Gramlich * @since 19:11:29 - 20.07.2010 */ public class TMXParser extends DefaultHandler implements TMXConstants { // =========================================================== // Constants // =========================================================== // =========================================================== // Fields // =========================================================== private final Context mContext; private final TextureManager mTextureManager; private final ITMXTilePropertiesListener mTMXTilePropertyListener; private final TextureOptions mTextureOptions; private TMXTiledMap mTMXTiledMap; private int mLastTileSetTileID; private final StringBuilder mStringBuilder = new StringBuilder(); private String mDataEncoding; private String mDataCompression; private boolean mInMap; private boolean mInTileset; @SuppressWarnings("unused") private boolean mInImage; private boolean mInTile; private boolean mInProperties; @SuppressWarnings("unused") private boolean mInProperty; private boolean mInLayer; private boolean mInData; private boolean mInObjectGroup; private boolean mInObject; // =========================================================== // Constructors // =========================================================== public TMXParser(final Context pContext, final TextureManager pTextureManager, final TextureOptions pTextureOptions, final ITMXTilePropertiesListener pTMXTilePropertyListener) { this.mContext = pContext; this.mTextureManager = pTextureManager; this.mTextureOptions = pTextureOptions; this.mTMXTilePropertyListener = pTMXTilePropertyListener; } // =========================================================== // Getter & Setter // =========================================================== TMXTiledMap getTMXTiledMap() { return this.mTMXTiledMap; } // =========================================================== // Methods for/from SuperClass/Interfaces // =========================================================== @Override public void startElement(final String pUri, final String pLocalName, final String pQualifiedName, final Attributes pAttributes) throws SAXException { if(pLocalName.equals(TAG_MAP)){ this.mInMap = true; this.mTMXTiledMap = new TMXTiledMap(pAttributes); } else if(pLocalName.equals(TAG_TILESET)){ this.mInTileset = true; final TMXTileSet tmxTileSet; final String tsxTileSetSource = pAttributes.getValue("", TAG_TILESET_ATTRIBUTE_SOURCE); if(tsxTileSetSource == null) { tmxTileSet = new TMXTileSet(pAttributes, this.mTextureOptions); } else { try { final int firstGlobalTileID = SAXUtils.getIntAttribute(pAttributes, TAG_TILESET_ATTRIBUTE_FIRSTGID, 1); tmxTileSet = new TSXLoader(this.mContext, this.mTextureManager, this.mTextureOptions).loadFromAsset(this.mContext, firstGlobalTileID, tsxTileSetSource); } catch (final TSXLoadException e) { throw new TMXParseException("Failed to load TMXTileSet from source: " + tsxTileSetSource, e); } } this.mTMXTiledMap.addTMXTileSet(tmxTileSet); } else if(pLocalName.equals(TAG_IMAGE)){ this.mInImage = true; final ArrayList<TMXTileSet> tmxTileSets = this.mTMXTiledMap.getTMXTileSets(); tmxTileSets.get(tmxTileSets.size() - 1).setImageSource(this.mContext, this.mTextureManager, pAttributes); } else if(pLocalName.equals(TAG_TILE)) { this.mInTile = true; if(this.mInTileset) { this.mLastTileSetTileID = SAXUtils.getIntAttributeOrThrow(pAttributes, TAG_TILE_ATTRIBUTE_ID); } else if(this.mInData) { final ArrayList<TMXLayer> tmxLayers = this.mTMXTiledMap.getTMXLayers(); tmxLayers.get(tmxLayers.size() - 1).initializeTMXTileFromXML(pAttributes, this.mTMXTilePropertyListener); } } else if(pLocalName.equals(TAG_PROPERTIES)) { this.mInProperties = true; } else if(this.mInProperties && pLocalName.equals(TAG_PROPERTY)) { this.mInProperty = true; if(this.mInTile) { final ArrayList<TMXTileSet> tmxTileSets = this.mTMXTiledMap.getTMXTileSets(); final TMXTileSet lastTMXTileSet = tmxTileSets.get(tmxTileSets.size() - 1); lastTMXTileSet.addTMXTileProperty(this.mLastTileSetTileID, new TMXTileProperty(pAttributes)); } else if(this.mInLayer) { final ArrayList<TMXLayer> tmxLayers = this.mTMXTiledMap.getTMXLayers(); final TMXLayer lastTMXLayer = tmxLayers.get(tmxLayers.size() - 1); lastTMXLayer.addTMXLayerProperty(new TMXLayerProperty(pAttributes)); } else if(this.mInObject) { final ArrayList<TMXObjectGroup> tmxObjectGroups = this.mTMXTiledMap.getTMXObjectGroups(); final TMXObjectGroup lastTMXObjectGroup = tmxObjectGroups.get(tmxObjectGroups.size() - 1); final ArrayList<TMXObject> tmxObjects = lastTMXObjectGroup.getTMXObjects(); final TMXObject lastTMXObject = tmxObjects.get(tmxObjects.size() - 1); lastTMXObject.addTMXObjectProperty(new TMXObjectProperty(pAttributes)); } else if(this.mInObjectGroup) { final ArrayList<TMXObjectGroup> tmxObjectGroups = this.mTMXTiledMap.getTMXObjectGroups(); final TMXObjectGroup lastTMXObjectGroup = tmxObjectGroups.get(tmxObjectGroups.size() - 1); lastTMXObjectGroup.addTMXObjectGroupProperty(new TMXObjectGroupProperty(pAttributes)); } else if(this.mInMap) { this.mTMXTiledMap.addTMXTiledMapProperty(new TMXTiledMapProperty(pAttributes)); } } else if(pLocalName.equals(TAG_LAYER)){ this.mInLayer = true; this.mTMXTiledMap.addTMXLayer(new TMXLayer(this.mTMXTiledMap, pAttributes)); } else if(pLocalName.equals(TAG_DATA)){ this.mInData = true; this.mDataEncoding = pAttributes.getValue("", TAG_DATA_ATTRIBUTE_ENCODING); this.mDataCompression = pAttributes.getValue("", TAG_DATA_ATTRIBUTE_COMPRESSION); } else if(pLocalName.equals(TAG_OBJECTGROUP)){ this.mInObjectGroup = true; this.mTMXTiledMap.addTMXObjectGroup(new TMXObjectGroup(pAttributes)); } else if(pLocalName.equals(TAG_OBJECT)){ this.mInObject = true; final ArrayList<TMXObjectGroup> tmxObjectGroups = this.mTMXTiledMap.getTMXObjectGroups(); tmxObjectGroups.get(tmxObjectGroups.size() - 1).addTMXObject(new TMXObject(pAttributes)); } else { throw new TMXParseException("Unexpected start tag: '" + pLocalName + "'."); } } @Override public void characters(final char[] pCharacters, final int pStart, final int pLength) throws SAXException { this.mStringBuilder.append(pCharacters, pStart, pLength); } @Override public void endElement(final String pUri, final String pLocalName, final String pQualifiedName) throws SAXException { if(pLocalName.equals(TAG_MAP)){ this.mInMap = false; } else if(pLocalName.equals(TAG_TILESET)){ this.mInTileset = false; } else if(pLocalName.equals(TAG_IMAGE)){ this.mInImage = false; } else if(pLocalName.equals(TAG_TILE)) { this.mInTile = false; } else if(pLocalName.equals(TAG_PROPERTIES)) { this.mInProperties = false; } else if(pLocalName.equals(TAG_PROPERTY)) { this.mInProperty = false; } else if(pLocalName.equals(TAG_LAYER)){ this.mInLayer = false; } else if(pLocalName.equals(TAG_DATA)){ final boolean binarySaved = this.mDataCompression != null && this.mDataEncoding != null; if(binarySaved) { final ArrayList<TMXLayer> tmxLayers = this.mTMXTiledMap.getTMXLayers(); try { tmxLayers.get(tmxLayers.size() - 1).initializeTMXTilesFromDataString(this.mStringBuilder.toString().trim(), this.mDataEncoding, this.mDataCompression, this.mTMXTilePropertyListener); } catch (final IOException e) { Debug.e(e); } this.mDataCompression = null; this.mDataEncoding = null; } this.mInData = false; } else if(pLocalName.equals(TAG_OBJECTGROUP)){ this.mInObjectGroup = false; } else if(pLocalName.equals(TAG_OBJECT)){ this.mInObject = false; } else { throw new TMXParseException("Unexpected end tag: '" + pLocalName + "'."); } /* Reset the StringBuilder. */ this.mStringBuilder.setLength(0); } // =========================================================== // Methods // =========================================================== // =========================================================== // Inner and Anonymous Classes // =========================================================== }
Java
package org.anddev.andengine.entity.layer.tiled.tmx; import org.xml.sax.Attributes; /** * (c) 2010 Nicolas Gramlich * (c) 2011 Zynga Inc. * * @author Nicolas Gramlich * @since 19:48:01 - 12.10.2010 */ public class TMXObjectGroupProperty extends TMXProperty { // =========================================================== // Constants // =========================================================== // =========================================================== // Fields // =========================================================== // =========================================================== // Constructors // =========================================================== public TMXObjectGroupProperty(final Attributes pAttributes) { super(pAttributes); } // =========================================================== // Getter & Setter // =========================================================== // =========================================================== // Methods for/from SuperClass/Interfaces // =========================================================== // =========================================================== // Methods // =========================================================== // =========================================================== // Inner and Anonymous Classes // =========================================================== }
Java
package org.anddev.andengine.entity.layer.tiled.tmx; import org.xml.sax.Attributes; /** * (c) 2010 Nicolas Gramlich * (c) 2011 Zynga Inc. * * @author Nicolas Gramlich * @since 18:48:46 - 12.10.2010 */ public class TMXLayerProperty extends TMXProperty { // =========================================================== // Constants // =========================================================== // =========================================================== // Fields // =========================================================== // =========================================================== // Constructors // =========================================================== public TMXLayerProperty(final Attributes pAttributes) { super(pAttributes); } // =========================================================== // Getter & Setter // =========================================================== // =========================================================== // Methods for/from SuperClass/Interfaces // =========================================================== // =========================================================== // Methods // =========================================================== // =========================================================== // Inner and Anonymous Classes // =========================================================== }
Java
package org.anddev.andengine.entity.layer.tiled.tmx; import java.util.ArrayList; import org.anddev.andengine.entity.layer.tiled.tmx.util.constants.TMXConstants; /** * (c) 2010 Nicolas Gramlich * (c) 2011 Zynga Inc. * * @author Nicolas Gramlich * @since 10:14:06 - 27.07.2010 */ public class TMXProperties<T extends TMXProperty> extends ArrayList<T> implements TMXConstants { // =========================================================== // Constants // =========================================================== private static final long serialVersionUID = 8912773556975105201L; // =========================================================== // Fields // =========================================================== // =========================================================== // Constructors // =========================================================== // =========================================================== // Getter & Setter // =========================================================== public boolean containsTMXProperty(final String pName, final String pValue) { for(int i = this.size() - 1; i >= 0; i--) { final T tmxProperty = this.get(i); if(tmxProperty.getName().equals(pName) && tmxProperty.getValue().equals(pValue)) { return true; } } return false; } // =========================================================== // Methods for/from SuperClass/Interfaces // =========================================================== // =========================================================== // Methods // =========================================================== // =========================================================== // Inner and Anonymous Classes // =========================================================== }
Java
package org.anddev.andengine.entity.layer.tiled.tmx; import org.xml.sax.Attributes; /** * (c) 2010 Nicolas Gramlich * (c) 2011 Zynga Inc. * * @author Nicolas Gramlich * @since 11:19:44 - 29.07.2010 */ public class TMXObjectProperty extends TMXProperty { // =========================================================== // Constants // =========================================================== // =========================================================== // Fields // =========================================================== // =========================================================== // Constructors // =========================================================== public TMXObjectProperty(final Attributes pAttributes) { super(pAttributes); } // =========================================================== // Getter & Setter // =========================================================== // =========================================================== // Methods for/from SuperClass/Interfaces // =========================================================== // =========================================================== // Methods // =========================================================== // =========================================================== // Inner and Anonymous Classes // =========================================================== }
Java
package org.anddev.andengine.entity.layer.tiled.tmx; import org.xml.sax.Attributes; /** * (c) 2010 Nicolas Gramlich * (c) 2011 Zynga Inc. * * @author Nicolas Gramlich * @since 11:20:09 - 29.07.2010 */ public class TMXTileProperty extends TMXProperty { // =========================================================== // Constants // =========================================================== // =========================================================== // Fields // =========================================================== // =========================================================== // Constructors // =========================================================== public TMXTileProperty(final Attributes pAttributes) { super(pAttributes); } // =========================================================== // Getter & Setter // =========================================================== // =========================================================== // Methods for/from SuperClass/Interfaces // =========================================================== // =========================================================== // Methods // =========================================================== // =========================================================== // Inner and Anonymous Classes // =========================================================== }
Java
package org.anddev.andengine.entity.util; import org.anddev.andengine.engine.handler.IUpdateHandler; import org.anddev.andengine.util.Debug; import org.anddev.andengine.util.constants.TimeConstants; /** * (c) 2010 Nicolas Gramlich * (c) 2011 Zynga Inc. * * @author Nicolas Gramlich * @since 19:52:31 - 09.03.2010 */ public class FrameCountCrasher implements IUpdateHandler, TimeConstants { // =========================================================== // Constants // =========================================================== // =========================================================== // Fields // =========================================================== private int mFramesLeft; private final float[] mFrameLengths; // =========================================================== // Constructors // =========================================================== public FrameCountCrasher(final int pFrameCount) { this.mFramesLeft = pFrameCount; this.mFrameLengths = new float[pFrameCount]; } // =========================================================== // Getter & Setter // =========================================================== // =========================================================== // Methods for/from SuperClass/Interfaces // =========================================================== @Override public void onUpdate(final float pSecondsElapsed) { this.mFramesLeft--; final float[] frameLengths = this.mFrameLengths; if(this.mFramesLeft >= 0) { frameLengths[this.mFramesLeft] = pSecondsElapsed; } else { for(int i = frameLengths.length - 1; i >= 0; i--) { Debug.d("Elapsed: " + frameLengths[i]); } throw new RuntimeException(); } } @Override public void reset() { } // =========================================================== // Methods // =========================================================== // =========================================================== // Inner and Anonymous Classes // =========================================================== }
Java
package org.anddev.andengine.entity.util; import org.anddev.andengine.engine.handler.IUpdateHandler; /** * (c) 2010 Nicolas Gramlich * (c) 2011 Zynga Inc. * * @author Nicolas Gramlich * @since 11:00:55 - 22.06.2010 */ public class FrameCounter implements IUpdateHandler { // =========================================================== // Constants // =========================================================== // =========================================================== // Fields // =========================================================== private int mFrames; // =========================================================== // Constructors // =========================================================== // =========================================================== // Getter & Setter // =========================================================== public int getFrames() { return this.mFrames; } // =========================================================== // Methods for/from SuperClass/Interfaces // =========================================================== @Override public void onUpdate(final float pSecondsElapsed) { this.mFrames++; } @Override public void reset() { this.mFrames = 0; } // =========================================================== // Methods // =========================================================== // =========================================================== // Inner and Anonymous Classes // =========================================================== }
Java
package org.anddev.andengine.entity.util; import org.anddev.andengine.util.Debug; /** * (c) 2010 Nicolas Gramlich * (c) 2011 Zynga Inc. * * @author Nicolas Gramlich * @since 19:52:31 - 09.03.2010 */ public class FPSLogger extends AverageFPSCounter { // =========================================================== // Constants // =========================================================== // =========================================================== // Fields // =========================================================== protected float mShortestFrame = Float.MAX_VALUE; protected float mLongestFrame = Float.MIN_VALUE; // =========================================================== // Constructors // =========================================================== public FPSLogger() { super(); } public FPSLogger(final float pAverageDuration) { super(pAverageDuration); } // =========================================================== // Getter & Setter // =========================================================== // =========================================================== // Methods for/from SuperClass/Interfaces // =========================================================== @Override protected void onHandleAverageDurationElapsed(final float pFPS) { this.onLogFPS(); this.mLongestFrame = Float.MIN_VALUE; this.mShortestFrame = Float.MAX_VALUE; } @Override public void onUpdate(final float pSecondsElapsed) { super.onUpdate(pSecondsElapsed); this.mShortestFrame = Math.min(this.mShortestFrame, pSecondsElapsed); this.mLongestFrame = Math.max(this.mLongestFrame, pSecondsElapsed); } @Override public void reset() { super.reset(); this.mShortestFrame = Float.MAX_VALUE; this.mLongestFrame = Float.MIN_VALUE; } // =========================================================== // Methods // =========================================================== protected void onLogFPS() { Debug.d(String.format("FPS: %.2f (MIN: %.0f ms | MAX: %.0f ms)", this.mFrames / this.mSecondsElapsed, this.mShortestFrame * MILLISECONDSPERSECOND, this.mLongestFrame * MILLISECONDSPERSECOND)); } // =========================================================== // Inner and Anonymous Classes // =========================================================== }
Java
package org.anddev.andengine.entity.util; import org.anddev.andengine.util.constants.TimeConstants; /** * (c) 2010 Nicolas Gramlich * (c) 2011 Zynga Inc. * * @author Nicolas Gramlich * @since 19:52:31 - 09.03.2010 */ public abstract class AverageFPSCounter extends FPSCounter implements TimeConstants { // =========================================================== // Constants // =========================================================== private static final float AVERAGE_DURATION_DEFAULT = 5; // =========================================================== // Fields // =========================================================== protected final float mAverageDuration; // =========================================================== // Constructors // =========================================================== public AverageFPSCounter() { this(AVERAGE_DURATION_DEFAULT); } public AverageFPSCounter(final float pAverageDuration) { this.mAverageDuration = pAverageDuration; } // =========================================================== // Getter & Setter // =========================================================== // =========================================================== // Methods for/from SuperClass/Interfaces // =========================================================== protected abstract void onHandleAverageDurationElapsed(final float pFPS); @Override public void onUpdate(final float pSecondsElapsed) { super.onUpdate(pSecondsElapsed); if(this.mSecondsElapsed > this.mAverageDuration){ this.onHandleAverageDurationElapsed(this.getFPS()); this.mSecondsElapsed -= this.mAverageDuration; this.mFrames = 0; } } // =========================================================== // Methods // =========================================================== // =========================================================== // Inner and Anonymous Classes // =========================================================== }
Java
package org.anddev.andengine.entity.util; import java.io.FileNotFoundException; import java.io.FileOutputStream; import javax.microedition.khronos.opengles.GL10; import org.anddev.andengine.engine.camera.Camera; import org.anddev.andengine.entity.Entity; import org.anddev.andengine.entity.util.ScreenGrabber.IScreenGrabberCallback; import org.anddev.andengine.util.Debug; import org.anddev.andengine.util.StreamUtils; import android.graphics.Bitmap; import android.graphics.Bitmap.CompressFormat; /** * (c) 2010 Nicolas Gramlich * (c) 2011 Zynga Inc. * * @author Nicolas Gramlich * @since 15:11:50 - 15.03.2010 */ public class ScreenCapture extends Entity implements IScreenGrabberCallback { // =========================================================== // Constants // =========================================================== // =========================================================== // Fields // =========================================================== private String mFilePath; private final ScreenGrabber mScreenGrabber = new ScreenGrabber(); private IScreenCaptureCallback mScreenCaptureCallback; // =========================================================== // Constructors // =========================================================== // =========================================================== // Getter & Setter // =========================================================== // =========================================================== // Methods for/from SuperClass/Interfaces // =========================================================== @Override protected void onManagedDraw(final GL10 pGL, final Camera pCamera) { this.mScreenGrabber.onManagedDraw(pGL, pCamera); } @Override protected void onManagedUpdate(final float pSecondsElapsed) { /* Nothing */ } @Override public void reset() { /* Nothing */ } @Override public void onScreenGrabbed(final Bitmap pBitmap) { try { ScreenCapture.saveCapture(pBitmap, this.mFilePath); this.mScreenCaptureCallback.onScreenCaptured(this.mFilePath); } catch (final FileNotFoundException e) { this.mScreenCaptureCallback.onScreenCaptureFailed(this.mFilePath, e); } } @Override public void onScreenGrabFailed(final Exception pException) { this.mScreenCaptureCallback.onScreenCaptureFailed(this.mFilePath, pException); } // =========================================================== // Methods // =========================================================== public void capture(final int pCaptureWidth, final int pCaptureHeight, final String pFilePath, final IScreenCaptureCallback pScreenCaptureCallback) { this.capture(0, 0, pCaptureWidth, pCaptureHeight, pFilePath, pScreenCaptureCallback); } public void capture(final int pCaptureX, final int pCaptureY, final int pCaptureWidth, final int pCaptureHeight, final String pFilePath, final IScreenCaptureCallback pScreencaptureCallback) { this.mFilePath = pFilePath; this.mScreenCaptureCallback = pScreencaptureCallback; this.mScreenGrabber.grab(pCaptureX, pCaptureY, pCaptureWidth, pCaptureHeight, this); } private static void saveCapture(final Bitmap pBitmap, final String pFilePath) throws FileNotFoundException { FileOutputStream fos = null; try { fos = new FileOutputStream(pFilePath); pBitmap.compress(CompressFormat.PNG, 100, fos); } catch (final FileNotFoundException e) { StreamUtils.flushCloseStream(fos); Debug.e("Error saving file to: " + pFilePath, e); throw e; } } // =========================================================== // Inner and Anonymous Classes // =========================================================== public static interface IScreenCaptureCallback { // =========================================================== // Constants // =========================================================== // =========================================================== // Methods // =========================================================== public void onScreenCaptured(final String pFilePath); public void onScreenCaptureFailed(final String pFilePath, final Exception pException); } }
Java
package org.anddev.andengine.entity.util; import org.anddev.andengine.engine.handler.IUpdateHandler; /** * (c) 2010 Nicolas Gramlich * (c) 2011 Zynga Inc. * * @author Nicolas Gramlich * @since 19:52:31 - 09.03.2010 */ public class FPSCounter implements IUpdateHandler { // =========================================================== // Constants // =========================================================== // =========================================================== // Fields // =========================================================== protected float mSecondsElapsed; protected int mFrames; // =========================================================== // Constructors // =========================================================== // =========================================================== // Getter & Setter // =========================================================== public float getFPS() { return this.mFrames / this.mSecondsElapsed; } // =========================================================== // Methods for/from SuperClass/Interfaces // =========================================================== @Override public void onUpdate(final float pSecondsElapsed) { this.mFrames++; this.mSecondsElapsed += pSecondsElapsed; } @Override public void reset() { this.mFrames = 0; this.mSecondsElapsed = 0; } // =========================================================== // Methods // =========================================================== // =========================================================== // Inner and Anonymous Classes // =========================================================== }
Java
package org.anddev.andengine.entity.util; import java.nio.IntBuffer; import javax.microedition.khronos.opengles.GL10; import org.anddev.andengine.engine.camera.Camera; import org.anddev.andengine.entity.Entity; import android.graphics.Bitmap; import android.graphics.Bitmap.Config; /** * (c) 2010 Nicolas Gramlich * (c) 2011 Zynga Inc. * * @author Nicolas Gramlich * @since 15:27:22 - 10.01.2011 */ public class ScreenGrabber extends Entity { // =========================================================== // Constants // =========================================================== // =========================================================== // Fields // =========================================================== private int mGrabX; private int mGrabY; private int mGrabWidth; private int mGrabHeight; private boolean mScreenGrabPending = false; private IScreenGrabberCallback mScreenGrabCallback; // =========================================================== // Constructors // =========================================================== // =========================================================== // Getter & Setter // =========================================================== // =========================================================== // Methods for/from SuperClass/Interfaces // =========================================================== @Override protected void onManagedDraw(final GL10 pGL, final Camera pCamera) { if(this.mScreenGrabPending) { try { final Bitmap screenGrab = ScreenGrabber.grab(this.mGrabX, this.mGrabY, this.mGrabWidth, this.mGrabHeight, pGL); this.mScreenGrabCallback.onScreenGrabbed(screenGrab); } catch (final Exception e) { this.mScreenGrabCallback.onScreenGrabFailed(e); } this.mScreenGrabPending = false; } } @Override protected void onManagedUpdate(final float pSecondsElapsed) { /* Nothing */ } @Override public void reset() { /* Nothing */ } // =========================================================== // Methods // =========================================================== public void grab(final int pGrabWidth, final int pGrabHeight, final IScreenGrabberCallback pScreenGrabCallback) { this.grab(0, 0, pGrabWidth, pGrabHeight, pScreenGrabCallback); } public void grab(final int pGrabX, final int pGrabY, final int pGrabWidth, final int pGrabHeight, final IScreenGrabberCallback pScreenGrabCallback) { this.mGrabX = pGrabX; this.mGrabY = pGrabY; this.mGrabWidth = pGrabWidth; this.mGrabHeight = pGrabHeight; this.mScreenGrabCallback = pScreenGrabCallback; this.mScreenGrabPending = true; } private static Bitmap grab(final int pGrabX, final int pGrabY, final int pGrabWidth, final int pGrabHeight, final GL10 pGL) { final int[] source = new int[pGrabWidth * (pGrabY + pGrabHeight)]; final IntBuffer sourceBuffer = IntBuffer.wrap(source); sourceBuffer.position(0); // TODO Check availability of OpenGL and GL10.GL_RGBA combinations that require less conversion operations. // Note: There is (said to be) a bug with glReadPixels when 'y != 0', so we simply read starting from 'y == 0'. pGL.glReadPixels(pGrabX, 0, pGrabWidth, pGrabY + pGrabHeight, GL10.GL_RGBA, GL10.GL_UNSIGNED_BYTE, sourceBuffer); final int[] pixels = new int[pGrabWidth * pGrabHeight]; // Convert from RGBA_8888 (Which is actually ABGR as the whole buffer seems to be inverted) --> ARGB_8888 for (int y = 0; y < pGrabHeight; y++) { for (int x = 0; x < pGrabWidth; x++) { final int pixel = source[x + ((pGrabY + y) * pGrabWidth)]; final int blue = (pixel & 0x00FF0000) >> 16; final int red = (pixel & 0x000000FF) << 16; final int greenAlpha = pixel & 0xFF00FF00; pixels[x + ((pGrabHeight - y - 1) * pGrabWidth)] = greenAlpha | red | blue; } } return Bitmap.createBitmap(pixels, pGrabWidth, pGrabHeight, Config.ARGB_8888); } // =========================================================== // Inner and Anonymous Classes // =========================================================== public static interface IScreenGrabberCallback { // =========================================================== // Constants // =========================================================== // =========================================================== // Methods // =========================================================== public void onScreenGrabbed(final Bitmap pBitmap); public void onScreenGrabFailed(final Exception pException); } }
Java
package org.anddev.andengine.entity.scene; import javax.microedition.khronos.opengles.GL10; import org.anddev.andengine.engine.camera.Camera; import org.anddev.andengine.entity.shape.Shape; import org.anddev.andengine.input.touch.TouchEvent; /** * (c) 2010 Nicolas Gramlich * (c) 2011 Zynga Inc. * * @author Nicolas Gramlich * @since 15:35:53 - 29.03.2010 */ public class CameraScene extends Scene { // =========================================================== // Constants // =========================================================== // =========================================================== // Fields // =========================================================== protected Camera mCamera; // =========================================================== // Constructors // =========================================================== /** * {@link CameraScene#setCamera(Camera)} needs to be called manually. Otherwise nothing will be drawn. */ public CameraScene() { this(null); } public CameraScene(final Camera pCamera) { this.mCamera = pCamera; } // =========================================================== // Getter & Setter // =========================================================== public Camera getCamera() { return this.mCamera; } public void setCamera(final Camera pCamera) { this.mCamera = pCamera; } // =========================================================== // Methods for/from SuperClass/Interfaces // =========================================================== @Override public boolean onSceneTouchEvent(final TouchEvent pSceneTouchEvent) { if(this.mCamera == null) { return false; } else { this.mCamera.convertSceneToCameraSceneTouchEvent(pSceneTouchEvent); final boolean handled = super.onSceneTouchEvent(pSceneTouchEvent); if(handled) { return true; } else { this.mCamera.convertCameraSceneToSceneTouchEvent(pSceneTouchEvent); return false; } } } @Override protected boolean onChildSceneTouchEvent(final TouchEvent pSceneTouchEvent) { final boolean childIsCameraScene = this.mChildScene instanceof CameraScene; if(childIsCameraScene) { this.mCamera.convertCameraSceneToSceneTouchEvent(pSceneTouchEvent); final boolean result = super.onChildSceneTouchEvent(pSceneTouchEvent); this.mCamera.convertSceneToCameraSceneTouchEvent(pSceneTouchEvent); return result; } else { return super.onChildSceneTouchEvent(pSceneTouchEvent); } } @Override protected void onManagedDraw(final GL10 pGL, final Camera pCamera) { if(this.mCamera != null) { pGL.glMatrixMode(GL10.GL_PROJECTION); this.mCamera.onApplyCameraSceneMatrix(pGL); { pGL.glMatrixMode(GL10.GL_MODELVIEW); pGL.glPushMatrix(); pGL.glLoadIdentity(); super.onManagedDraw(pGL, pCamera); pGL.glPopMatrix(); } pGL.glMatrixMode(GL10.GL_PROJECTION); } } // =========================================================== // Methods // =========================================================== public void centerShapeInCamera(final Shape pShape) { final Camera camera = this.mCamera; pShape.setPosition((camera.getWidth() - pShape.getWidth()) * 0.5f, (camera.getHeight() - pShape.getHeight()) * 0.5f); } public void centerShapeInCameraHorizontally(final Shape pShape) { pShape.setPosition((this.mCamera.getWidth() - pShape.getWidth()) * 0.5f, pShape.getY()); } public void centerShapeInCameraVertically(final Shape pShape) { pShape.setPosition(pShape.getX(), (this.mCamera.getHeight() - pShape.getHeight()) * 0.5f); } // =========================================================== // Inner and Anonymous Classes // =========================================================== }
Java
package org.anddev.andengine.entity.scene; import java.util.ArrayList; import javax.microedition.khronos.opengles.GL10; import org.anddev.andengine.engine.camera.Camera; import org.anddev.andengine.engine.handler.runnable.RunnableHandler; import org.anddev.andengine.entity.Entity; import org.anddev.andengine.entity.IEntity; import org.anddev.andengine.entity.scene.Scene.ITouchArea.ITouchAreaMatcher; import org.anddev.andengine.entity.scene.background.ColorBackground; import org.anddev.andengine.entity.scene.background.IBackground; import org.anddev.andengine.entity.shape.Shape; import org.anddev.andengine.input.touch.TouchEvent; import org.anddev.andengine.opengl.util.GLHelper; import org.anddev.andengine.util.IMatcher; import org.anddev.andengine.util.SmartList; import org.anddev.andengine.util.constants.Constants; import android.util.SparseArray; /** * (c) 2010 Nicolas Gramlich * (c) 2011 Zynga Inc. * * @author Nicolas Gramlich * @since 12:47:39 - 08.03.2010 */ public class Scene extends Entity { // =========================================================== // Constants // =========================================================== private static final int TOUCHAREAS_CAPACITY_DEFAULT = 4; // =========================================================== // Fields // =========================================================== private float mSecondsElapsedTotal; protected Scene mParentScene; protected Scene mChildScene; private boolean mChildSceneModalDraw; private boolean mChildSceneModalUpdate; private boolean mChildSceneModalTouch; protected SmartList<ITouchArea> mTouchAreas = new SmartList<ITouchArea>(TOUCHAREAS_CAPACITY_DEFAULT); private final RunnableHandler mRunnableHandler = new RunnableHandler(); private IOnSceneTouchListener mOnSceneTouchListener; private IOnAreaTouchListener mOnAreaTouchListener; private IBackground mBackground = new ColorBackground(0, 0, 0); // Black private boolean mBackgroundEnabled = true; private boolean mOnAreaTouchTraversalBackToFront = true; private boolean mTouchAreaBindingEnabled = false; private final SparseArray<ITouchArea> mTouchAreaBindings = new SparseArray<ITouchArea>(); private boolean mOnSceneTouchListenerBindingEnabled = false; private final SparseArray<IOnSceneTouchListener> mOnSceneTouchListenerBindings = new SparseArray<IOnSceneTouchListener>(); // =========================================================== // Constructors // =========================================================== public Scene() { } @Deprecated public Scene(final int pChildCount) { for(int i = 0; i < pChildCount; i++) { this.attachChild(new Entity()); } } // =========================================================== // Getter & Setter // =========================================================== public float getSecondsElapsedTotal() { return this.mSecondsElapsedTotal; } public IBackground getBackground() { return this.mBackground; } public void setBackground(final IBackground pBackground) { this.mBackground = pBackground; } public boolean isBackgroundEnabled() { return this.mBackgroundEnabled; } public void setBackgroundEnabled(final boolean pEnabled) { this.mBackgroundEnabled = pEnabled; } public void setOnSceneTouchListener(final IOnSceneTouchListener pOnSceneTouchListener) { this.mOnSceneTouchListener = pOnSceneTouchListener; } public IOnSceneTouchListener getOnSceneTouchListener() { return this.mOnSceneTouchListener; } public boolean hasOnSceneTouchListener() { return this.mOnSceneTouchListener != null; } public void setOnAreaTouchListener(final IOnAreaTouchListener pOnAreaTouchListener) { this.mOnAreaTouchListener = pOnAreaTouchListener; } public IOnAreaTouchListener getOnAreaTouchListener() { return this.mOnAreaTouchListener; } public boolean hasOnAreaTouchListener() { return this.mOnAreaTouchListener != null; } private void setParentScene(final Scene pParentScene) { this.mParentScene = pParentScene; } public boolean hasChildScene() { return this.mChildScene != null; } public Scene getChildScene() { return this.mChildScene; } public void setChildSceneModal(final Scene pChildScene) { this.setChildScene(pChildScene, true, true, true); } public void setChildScene(final Scene pChildScene) { this.setChildScene(pChildScene, false, false, false); } public void setChildScene(final Scene pChildScene, final boolean pModalDraw, final boolean pModalUpdate, final boolean pModalTouch) { pChildScene.setParentScene(this); this.mChildScene = pChildScene; this.mChildSceneModalDraw = pModalDraw; this.mChildSceneModalUpdate = pModalUpdate; this.mChildSceneModalTouch = pModalTouch; } public void clearChildScene() { this.mChildScene = null; } public void setOnAreaTouchTraversalBackToFront() { this.mOnAreaTouchTraversalBackToFront = true; } public void setOnAreaTouchTraversalFrontToBack() { this.mOnAreaTouchTraversalBackToFront = false; } public boolean isTouchAreaBindingEnabled() { return this.mTouchAreaBindingEnabled; } /** * Enable or disable the binding of TouchAreas to PointerIDs (fingers). * When enabled: TouchAreas get bound to a PointerID (finger) when returning true in * {@link Shape#onAreaTouched(TouchEvent, float, float)} or * {@link IOnAreaTouchListener#onAreaTouched(TouchEvent, ITouchArea, float, float)} * with {@link TouchEvent#ACTION_DOWN}, they will receive all subsequent {@link TouchEvent}s * that are made with the same PointerID (finger) * <b>even if the {@link TouchEvent} is outside of the actual {@link ITouchArea}</b>! * * @param pTouchAreaBindingEnabled */ public void setTouchAreaBindingEnabled(final boolean pTouchAreaBindingEnabled) { if(this.mTouchAreaBindingEnabled && !pTouchAreaBindingEnabled) { this.mTouchAreaBindings.clear(); } this.mTouchAreaBindingEnabled = pTouchAreaBindingEnabled; } public boolean isOnSceneTouchListenerBindingEnabled() { return this.mOnSceneTouchListenerBindingEnabled; } /** * Enable or disable the binding of TouchAreas to PointerIDs (fingers). * When enabled: The OnSceneTouchListener gets bound to a PointerID (finger) when returning true in * {@link Shape#onAreaTouched(TouchEvent, float, float)} or * {@link IOnAreaTouchListener#onAreaTouched(TouchEvent, ITouchArea, float, float)} * with {@link TouchEvent#ACTION_DOWN}, it will receive all subsequent {@link TouchEvent}s * that are made with the same PointerID (finger) * <b>even if the {@link TouchEvent} is would belong to an overlaying {@link ITouchArea}</b>! * * @param pOnSceneTouchListenerBindingEnabled */ public void setOnSceneTouchListenerBindingEnabled(final boolean pOnSceneTouchListenerBindingEnabled) { if(this.mOnSceneTouchListenerBindingEnabled && !pOnSceneTouchListenerBindingEnabled) { this.mOnSceneTouchListenerBindings.clear(); } this.mOnSceneTouchListenerBindingEnabled = pOnSceneTouchListenerBindingEnabled; } // =========================================================== // Methods for/from SuperClass/Interfaces // =========================================================== @Override protected void onManagedDraw(final GL10 pGL, final Camera pCamera) { final Scene childScene = this.mChildScene; if(childScene == null || !this.mChildSceneModalDraw) { if(this.mBackgroundEnabled) { pCamera.onApplySceneBackgroundMatrix(pGL); GLHelper.setModelViewIdentityMatrix(pGL); this.mBackground.onDraw(pGL, pCamera); } pCamera.onApplySceneMatrix(pGL); GLHelper.setModelViewIdentityMatrix(pGL); super.onManagedDraw(pGL, pCamera); } if(childScene != null) { childScene.onDraw(pGL, pCamera); } } @Override protected void onManagedUpdate(final float pSecondsElapsed) { this.mSecondsElapsedTotal += pSecondsElapsed; this.mRunnableHandler.onUpdate(pSecondsElapsed); final Scene childScene = this.mChildScene; if(childScene == null || !this.mChildSceneModalUpdate) { this.mBackground.onUpdate(pSecondsElapsed); super.onManagedUpdate(pSecondsElapsed); } if(childScene != null) { childScene.onUpdate(pSecondsElapsed); } } public boolean onSceneTouchEvent(final TouchEvent pSceneTouchEvent) { final int action = pSceneTouchEvent.getAction(); final boolean isActionDown = pSceneTouchEvent.isActionDown(); if(!isActionDown) { if(this.mOnSceneTouchListenerBindingEnabled) { final IOnSceneTouchListener boundOnSceneTouchListener = this.mOnSceneTouchListenerBindings.get(pSceneTouchEvent.getPointerID()); if (boundOnSceneTouchListener != null) { /* Check if boundTouchArea needs to be removed. */ switch(action) { case TouchEvent.ACTION_UP: case TouchEvent.ACTION_CANCEL: this.mOnSceneTouchListenerBindings.remove(pSceneTouchEvent.getPointerID()); } final Boolean handled = this.mOnSceneTouchListener.onSceneTouchEvent(this, pSceneTouchEvent); if(handled != null && handled) { return true; } } } if(this.mTouchAreaBindingEnabled) { final SparseArray<ITouchArea> touchAreaBindings = this.mTouchAreaBindings; final ITouchArea boundTouchArea = touchAreaBindings.get(pSceneTouchEvent.getPointerID()); /* In the case a ITouchArea has been bound to this PointerID, * we'll pass this this TouchEvent to the same ITouchArea. */ if(boundTouchArea != null) { final float sceneTouchEventX = pSceneTouchEvent.getX(); final float sceneTouchEventY = pSceneTouchEvent.getY(); /* Check if boundTouchArea needs to be removed. */ switch(action) { case TouchEvent.ACTION_UP: case TouchEvent.ACTION_CANCEL: touchAreaBindings.remove(pSceneTouchEvent.getPointerID()); } final Boolean handled = this.onAreaTouchEvent(pSceneTouchEvent, sceneTouchEventX, sceneTouchEventY, boundTouchArea); if(handled != null && handled) { return true; } } } } final Scene childScene = this.mChildScene; if(childScene != null) { final boolean handledByChild = this.onChildSceneTouchEvent(pSceneTouchEvent); if(handledByChild) { return true; } else if(this.mChildSceneModalTouch) { return false; } } final float sceneTouchEventX = pSceneTouchEvent.getX(); final float sceneTouchEventY = pSceneTouchEvent.getY(); final ArrayList<ITouchArea> touchAreas = this.mTouchAreas; if(touchAreas != null) { final int touchAreaCount = touchAreas.size(); if(touchAreaCount > 0) { if(this.mOnAreaTouchTraversalBackToFront) { /* Back to Front. */ for(int i = 0; i < touchAreaCount; i++) { final ITouchArea touchArea = touchAreas.get(i); if(touchArea.contains(sceneTouchEventX, sceneTouchEventY)) { final Boolean handled = this.onAreaTouchEvent(pSceneTouchEvent, sceneTouchEventX, sceneTouchEventY, touchArea); if(handled != null && handled) { /* If binding of ITouchAreas is enabled and this is an ACTION_DOWN event, * bind this ITouchArea to the PointerID. */ if(this.mTouchAreaBindingEnabled && isActionDown) { this.mTouchAreaBindings.put(pSceneTouchEvent.getPointerID(), touchArea); } return true; } } } } else { /* Front to back. */ for(int i = touchAreaCount - 1; i >= 0; i--) { final ITouchArea touchArea = touchAreas.get(i); if(touchArea.contains(sceneTouchEventX, sceneTouchEventY)) { final Boolean handled = this.onAreaTouchEvent(pSceneTouchEvent, sceneTouchEventX, sceneTouchEventY, touchArea); if(handled != null && handled) { /* If binding of ITouchAreas is enabled and this is an ACTION_DOWN event, * bind this ITouchArea to the PointerID. */ if(this.mTouchAreaBindingEnabled && isActionDown) { this.mTouchAreaBindings.put(pSceneTouchEvent.getPointerID(), touchArea); } return true; } } } } } } /* If no area was touched, the Scene itself was touched as a fallback. */ if(this.mOnSceneTouchListener != null){ final Boolean handled = this.mOnSceneTouchListener.onSceneTouchEvent(this, pSceneTouchEvent); if(handled != null && handled) { /* If binding of ITouchAreas is enabled and this is an ACTION_DOWN event, * bind the active OnSceneTouchListener to the PointerID. */ if(this.mOnSceneTouchListenerBindingEnabled && isActionDown) { this.mOnSceneTouchListenerBindings.put(pSceneTouchEvent.getPointerID(), this.mOnSceneTouchListener); } return true; } else { return false; } } else { return false; } } private Boolean onAreaTouchEvent(final TouchEvent pSceneTouchEvent, final float sceneTouchEventX, final float sceneTouchEventY, final ITouchArea touchArea) { final float[] touchAreaLocalCoordinates = touchArea.convertSceneToLocalCoordinates(sceneTouchEventX, sceneTouchEventY); final float touchAreaLocalX = touchAreaLocalCoordinates[Constants.VERTEX_INDEX_X]; final float touchAreaLocalY = touchAreaLocalCoordinates[Constants.VERTEX_INDEX_Y]; final boolean handledSelf = touchArea.onAreaTouched(pSceneTouchEvent, touchAreaLocalX, touchAreaLocalY); if(handledSelf) { return Boolean.TRUE; } else if(this.mOnAreaTouchListener != null) { return this.mOnAreaTouchListener.onAreaTouched(pSceneTouchEvent, touchArea, touchAreaLocalX, touchAreaLocalY); } else { return null; } } protected boolean onChildSceneTouchEvent(final TouchEvent pSceneTouchEvent) { return this.mChildScene.onSceneTouchEvent(pSceneTouchEvent); } @Override public void reset() { super.reset(); this.clearChildScene(); } @Override public void setParent(final IEntity pEntity) { // super.setParent(pEntity); } // =========================================================== // Methods // =========================================================== public void postRunnable(final Runnable pRunnable) { this.mRunnableHandler.postRunnable(pRunnable); } public void registerTouchArea(final ITouchArea pTouchArea) { this.mTouchAreas.add(pTouchArea); } public boolean unregisterTouchArea(final ITouchArea pTouchArea) { return this.mTouchAreas.remove(pTouchArea); } public boolean unregisterTouchAreas(final ITouchAreaMatcher pTouchAreaMatcher) { return this.mTouchAreas.removeAll(pTouchAreaMatcher); } public void clearTouchAreas() { this.mTouchAreas.clear(); } public ArrayList<ITouchArea> getTouchAreas() { return this.mTouchAreas; } public void back() { this.clearChildScene(); if(this.mParentScene != null) { this.mParentScene.clearChildScene(); this.mParentScene = null; } } // =========================================================== // Inner and Anonymous Classes // =========================================================== public static interface ITouchArea { // =========================================================== // Final Fields // =========================================================== // =========================================================== // Methods // =========================================================== public boolean contains(final float pX, final float pY); public float[] convertSceneToLocalCoordinates(final float pX, final float pY); public float[] convertLocalToSceneCoordinates(final float pX, final float pY); /** * This method only fires if this {@link ITouchArea} is registered to the {@link Scene} via {@link Scene#registerTouchArea(ITouchArea)}. * @param pSceneTouchEvent * @return <code>true</code> if the event was handled (that means {@link IOnAreaTouchListener} of the {@link Scene} will not be fired!), otherwise <code>false</code>. */ public boolean onAreaTouched(final TouchEvent pSceneTouchEvent, final float pTouchAreaLocalX, final float pTouchAreaLocalY); // =========================================================== // Inner and Anonymous Classes // =========================================================== public interface ITouchAreaMatcher extends IMatcher<ITouchArea> { // =========================================================== // Constants // =========================================================== // =========================================================== // Methods // =========================================================== } } /** * An interface for a callback to be invoked when a {@link TouchEvent} is * dispatched to an {@link ITouchArea} area. The callback will be invoked * before the {@link TouchEvent} is passed to the {@link ITouchArea}. */ public static interface IOnAreaTouchListener { // =========================================================== // Constants // =========================================================== // =========================================================== // Methods // =========================================================== /** * Called when a {@link TouchEvent} is dispatched to an {@link ITouchArea}. This allows * listeners to get a chance to respond before the target {@link ITouchArea#onAreaTouched(TouchEvent, float, float)} is called. * * @param pTouchArea The {@link ITouchArea} that the {@link TouchEvent} has been dispatched to. * @param pSceneTouchEvent The {@link TouchEvent} object containing full information about the event. * @param pTouchAreaLocalX the x coordinate within the area touched. * @param pTouchAreaLocalY the y coordinate within the area touched. * * @return <code>true</code> if this {@link IOnAreaTouchListener} has consumed the {@link TouchEvent}, <code>false</code> otherwise. */ public boolean onAreaTouched(final TouchEvent pSceneTouchEvent, final ITouchArea pTouchArea, final float pTouchAreaLocalX, final float pTouchAreaLocalY); } /** * An interface for a callback to be invoked when a {@link TouchEvent} is * dispatched to a {@link Scene}. The callback will be invoked * after all {@link ITouchArea}s have been checked and none consumed the {@link TouchEvent}. */ public static interface IOnSceneTouchListener { // =========================================================== // Final Fields // =========================================================== // =========================================================== // Methods // =========================================================== /** * Called when a {@link TouchEvent} is dispatched to a {@link Scene}. * * @param pScene The {@link Scene} that the {@link TouchEvent} has been dispatched to. * @param pSceneTouchEvent The {@link TouchEvent} object containing full information about the event. * * @return <code>true</code> if this {@link IOnSceneTouchListener} has consumed the {@link TouchEvent}, <code>false</code> otherwise. */ public boolean onSceneTouchEvent(final Scene pScene, final TouchEvent pSceneTouchEvent); } }
Java
package org.anddev.andengine.entity.scene.popup; import org.anddev.andengine.engine.camera.Camera; import org.anddev.andengine.entity.modifier.IEntityModifier; import org.anddev.andengine.entity.scene.Scene; import org.anddev.andengine.entity.text.Text; import org.anddev.andengine.opengl.font.Font; import org.anddev.andengine.util.HorizontalAlign; /** * (c) 2010 Nicolas Gramlich * (c) 2011 Zynga Inc. * * @author Nicolas Gramlich * @since 17:19:30 - 03.08.2010 */ public class TextPopupScene extends PopupScene { // =========================================================== // Constants // =========================================================== // =========================================================== // Fields // =========================================================== private final Text mText; // =========================================================== // Constructors // =========================================================== public TextPopupScene(final Camera pCamera, final Scene pParentScene, final Font pFont, final String pText, final float pDurationSeconds) { this(pCamera, pParentScene, pFont, pText, pDurationSeconds, null, null); } public TextPopupScene(final Camera pCamera, final Scene pParentScene, final Font pFont, final String pText, final float pDurationSeconds, final IEntityModifier pShapeModifier) { this(pCamera, pParentScene, pFont, pText, pDurationSeconds, pShapeModifier, null); } public TextPopupScene(final Camera pCamera, final Scene pParentScene, final Font pFont, final String pText, final float pDurationSeconds, final Runnable pRunnable) { this(pCamera, pParentScene, pFont, pText, pDurationSeconds, null, pRunnable); } public TextPopupScene(final Camera pCamera, final Scene pParentScene, final Font pFont, final String pText, final float pDurationSeconds, final IEntityModifier pShapeModifier, final Runnable pRunnable) { super(pCamera, pParentScene, pDurationSeconds, pRunnable); this.mText = new Text(0, 0, pFont, pText, HorizontalAlign.CENTER); this.centerShapeInCamera(this.mText); if(pShapeModifier != null) { this.mText.registerEntityModifier(pShapeModifier); } this.attachChild(this.mText); } // =========================================================== // Getter & Setter // =========================================================== public Text getText() { return this.mText; } // =========================================================== // Methods for/from SuperClass/Interfaces // =========================================================== // =========================================================== // Methods // =========================================================== // =========================================================== // Inner and Anonymous Classes // =========================================================== }
Java
package org.anddev.andengine.entity.scene.popup; import org.anddev.andengine.engine.camera.Camera; import org.anddev.andengine.engine.handler.timer.ITimerCallback; import org.anddev.andengine.engine.handler.timer.TimerHandler; import org.anddev.andengine.entity.scene.CameraScene; import org.anddev.andengine.entity.scene.Scene; /** * (c) 2010 Nicolas Gramlich * (c) 2011 Zynga Inc. * * @author Nicolas Gramlich * @since 16:36:51 - 03.08.2010 */ public class PopupScene extends CameraScene { // =========================================================== // Constants // =========================================================== // =========================================================== // Fields // =========================================================== // =========================================================== // Constructors // =========================================================== public PopupScene(final Camera pCamera, final Scene pParentScene, final float pDurationSeconds) { this(pCamera, pParentScene, pDurationSeconds, null); } public PopupScene(final Camera pCamera, final Scene pParentScene, final float pDurationSeconds, final Runnable pRunnable) { super(pCamera); this.setBackgroundEnabled(false); pParentScene.setChildScene(this, false, true, true); this.registerUpdateHandler(new TimerHandler(pDurationSeconds, new ITimerCallback() { @Override public void onTimePassed(final TimerHandler pTimerHandler) { PopupScene.this.unregisterUpdateHandler(pTimerHandler); pParentScene.clearChildScene(); if(pRunnable != null) { pRunnable.run(); } } })); } // =========================================================== // Getter & Setter // =========================================================== // =========================================================== // Methods for/from SuperClass/Interfaces // =========================================================== // =========================================================== // Methods // =========================================================== // =========================================================== // Inner and Anonymous Classes // =========================================================== }
Java
package org.anddev.andengine.entity.scene.menu; import java.util.ArrayList; import org.anddev.andengine.engine.camera.Camera; import org.anddev.andengine.entity.scene.CameraScene; import org.anddev.andengine.entity.scene.Scene; import org.anddev.andengine.entity.scene.Scene.IOnAreaTouchListener; import org.anddev.andengine.entity.scene.Scene.IOnSceneTouchListener; import org.anddev.andengine.entity.scene.menu.animator.IMenuAnimator; import org.anddev.andengine.entity.scene.menu.item.IMenuItem; import org.anddev.andengine.input.touch.TouchEvent; import android.view.MotionEvent; /** * (c) 2010 Nicolas Gramlich * (c) 2011 Zynga Inc. * * @author Nicolas Gramlich * @since 20:06:51 - 01.04.2010 */ public class MenuScene extends CameraScene implements IOnAreaTouchListener, IOnSceneTouchListener { // =========================================================== // Constants // =========================================================== // =========================================================== // Fields // =========================================================== private final ArrayList<IMenuItem> mMenuItems = new ArrayList<IMenuItem>(); private IOnMenuItemClickListener mOnMenuItemClickListener; private IMenuAnimator mMenuAnimator = IMenuAnimator.DEFAULT; private IMenuItem mSelectedMenuItem; // =========================================================== // Constructors // =========================================================== public MenuScene() { this(null, null); } public MenuScene(final IOnMenuItemClickListener pOnMenuItemClickListener) { this(null, pOnMenuItemClickListener); } public MenuScene(final Camera pCamera) { this(pCamera, null); } public MenuScene(final Camera pCamera, final IOnMenuItemClickListener pOnMenuItemClickListener) { super(pCamera); this.mOnMenuItemClickListener = pOnMenuItemClickListener; this.setOnSceneTouchListener(this); this.setOnAreaTouchListener(this); } // =========================================================== // Getter & Setter // =========================================================== public IOnMenuItemClickListener getOnMenuItemClickListener() { return this.mOnMenuItemClickListener; } public void setOnMenuItemClickListener(final IOnMenuItemClickListener pOnMenuItemClickListener) { this.mOnMenuItemClickListener = pOnMenuItemClickListener; } public int getMenuItemCount() { return this.mMenuItems.size(); } public void addMenuItem(final IMenuItem pMenuItem) { this.mMenuItems.add(pMenuItem); this.attachChild(pMenuItem); this.registerTouchArea(pMenuItem); } @Override public MenuScene getChildScene() { return (MenuScene)super.getChildScene(); } @Override public void setChildScene(final Scene pChildScene, final boolean pModalDraw, final boolean pModalUpdate, final boolean pModalTouch) throws IllegalArgumentException { if(pChildScene instanceof MenuScene) { super.setChildScene(pChildScene, pModalDraw, pModalUpdate, pModalTouch); } else { throw new IllegalArgumentException("MenuScene accepts only MenuScenes as a ChildScene."); } } @Override public void clearChildScene() { if(this.getChildScene() != null) { this.getChildScene().reset(); super.clearChildScene(); } } public void setMenuAnimator(final IMenuAnimator pMenuAnimator) { this.mMenuAnimator = pMenuAnimator; } // =========================================================== // Methods for/from SuperClass/Interfaces // =========================================================== @Override public boolean onAreaTouched(final TouchEvent pSceneTouchEvent, final ITouchArea pTouchArea, final float pTouchAreaLocalX, final float pTouchAreaLocalY) { final IMenuItem menuItem = ((IMenuItem)pTouchArea); switch(pSceneTouchEvent.getAction()) { case MotionEvent.ACTION_DOWN: case MotionEvent.ACTION_MOVE: if(this.mSelectedMenuItem != null && this.mSelectedMenuItem != menuItem) { this.mSelectedMenuItem.onUnselected(); } this.mSelectedMenuItem = menuItem; this.mSelectedMenuItem.onSelected(); break; case MotionEvent.ACTION_UP: if(this.mOnMenuItemClickListener != null) { final boolean handled = this.mOnMenuItemClickListener.onMenuItemClicked(this, menuItem, pTouchAreaLocalX, pTouchAreaLocalY); menuItem.onUnselected(); this.mSelectedMenuItem = null; return handled; } break; case MotionEvent.ACTION_CANCEL: menuItem.onUnselected(); this.mSelectedMenuItem = null; break; } return true; } @Override public boolean onSceneTouchEvent(final Scene pScene, final TouchEvent pSceneTouchEvent) { if(this.mSelectedMenuItem != null) { this.mSelectedMenuItem.onUnselected(); this.mSelectedMenuItem = null; } return false; } @Override public void back() { super.back(); this.reset(); } @Override public void reset() { super.reset(); final ArrayList<IMenuItem> menuItems = this.mMenuItems; for(int i = menuItems.size() - 1; i >= 0; i--) { menuItems.get(i).reset(); } this.prepareAnimations(); } // =========================================================== // Methods // =========================================================== public void closeMenuScene() { this.back(); } public void buildAnimations() { this.prepareAnimations(); final float cameraWidthRaw = this.mCamera.getWidthRaw(); final float cameraHeightRaw = this.mCamera.getHeightRaw(); this.mMenuAnimator.buildAnimations(this.mMenuItems, cameraWidthRaw, cameraHeightRaw); } public void prepareAnimations() { final float cameraWidthRaw = this.mCamera.getWidthRaw(); final float cameraHeightRaw = this.mCamera.getHeightRaw(); this.mMenuAnimator.prepareAnimations(this.mMenuItems, cameraWidthRaw, cameraHeightRaw); } // =========================================================== // Inner and Anonymous Classes // =========================================================== public static interface IOnMenuItemClickListener { // =========================================================== // Final Fields // =========================================================== // =========================================================== // Methods // =========================================================== public boolean onMenuItemClicked(final MenuScene pMenuScene, final IMenuItem pMenuItem, final float pMenuItemLocalX, final float pMenuItemLocalY); } }
Java
package org.anddev.andengine.entity.scene.menu.animator; import java.util.ArrayList; import org.anddev.andengine.entity.modifier.MoveModifier; import org.anddev.andengine.entity.scene.menu.item.IMenuItem; import org.anddev.andengine.util.HorizontalAlign; import org.anddev.andengine.util.modifier.ease.IEaseFunction; /** * (c) 2010 Nicolas Gramlich * (c) 2011 Zynga Inc. * * @author Nicolas Gramlich * @since 11:04:35 - 02.04.2010 */ public class SlideMenuAnimator extends BaseMenuAnimator { // =========================================================== // Constants // =========================================================== // =========================================================== // Fields // =========================================================== // =========================================================== // Constructors // =========================================================== public SlideMenuAnimator(){ super(); } public SlideMenuAnimator(final IEaseFunction pEaseFunction) { super(pEaseFunction); } public SlideMenuAnimator(final HorizontalAlign pHorizontalAlign) { super(pHorizontalAlign); } public SlideMenuAnimator(final HorizontalAlign pHorizontalAlign, final IEaseFunction pEaseFunction) { super(pHorizontalAlign, pEaseFunction); } public SlideMenuAnimator(final float pMenuItemSpacing) { super(pMenuItemSpacing); } public SlideMenuAnimator(final float pMenuItemSpacing, final IEaseFunction pEaseFunction) { super(pMenuItemSpacing, pEaseFunction); } public SlideMenuAnimator(final HorizontalAlign pHorizontalAlign, final float pMenuItemSpacing) { super(pHorizontalAlign, pMenuItemSpacing); } public SlideMenuAnimator(final HorizontalAlign pHorizontalAlign, final float pMenuItemSpacing, final IEaseFunction pEaseFunction) { super(pHorizontalAlign, pMenuItemSpacing, pEaseFunction); } // =========================================================== // Getter & Setter // =========================================================== // =========================================================== // Methods for/from SuperClass/Interfaces // =========================================================== @Override public void buildAnimations(final ArrayList<IMenuItem> pMenuItems, final float pCameraWidth, final float pCameraHeight) { final IEaseFunction easeFunction = this.mEaseFunction; final float maximumWidth = this.getMaximumWidth(pMenuItems); final float overallHeight = this.getOverallHeight(pMenuItems); final float baseX = (pCameraWidth - maximumWidth) * 0.5f; final float baseY = (pCameraHeight - overallHeight) * 0.5f; float offsetY = 0; final int menuItemCount = pMenuItems.size(); for(int i = 0; i < menuItemCount; i++) { final IMenuItem menuItem = pMenuItems.get(i); final float offsetX; switch(this.mHorizontalAlign) { case LEFT: offsetX = 0; break; case RIGHT: offsetX = maximumWidth - menuItem.getWidthScaled(); break; case CENTER: default: offsetX = (maximumWidth - menuItem.getWidthScaled()) * 0.5f; break; } final MoveModifier moveModifier = new MoveModifier(DURATION, -maximumWidth, baseX + offsetX, baseY + offsetY, baseY + offsetY, easeFunction); moveModifier.setRemoveWhenFinished(false); menuItem.registerEntityModifier(moveModifier); offsetY += menuItem.getHeight() + this.mMenuItemSpacing; } } @Override public void prepareAnimations(final ArrayList<IMenuItem> pMenuItems, final float pCameraWidth, final float pCameraHeight) { final float maximumWidth = this.getMaximumWidth(pMenuItems); final float overallHeight = this.getOverallHeight(pMenuItems); final float baseY = (pCameraHeight - overallHeight) * 0.5f; final float menuItemSpacing = this.mMenuItemSpacing; float offsetY = 0; final int menuItemCount = pMenuItems.size(); for(int i = 0; i < menuItemCount; i++) { final IMenuItem menuItem = pMenuItems.get(i); menuItem.setPosition(-maximumWidth, baseY + offsetY); offsetY += menuItem.getHeight() + menuItemSpacing; } } // =========================================================== // Methods // =========================================================== // =========================================================== // Inner and Anonymous Classes // =========================================================== }
Java
package org.anddev.andengine.entity.scene.menu.animator; import java.util.ArrayList; import org.anddev.andengine.entity.scene.menu.item.IMenuItem; import org.anddev.andengine.util.HorizontalAlign; import org.anddev.andengine.util.modifier.ease.IEaseFunction; /** * (c) 2010 Nicolas Gramlich * (c) 2011 Zynga Inc. * * @author Nicolas Gramlich * @since 11:17:32 - 02.04.2010 */ public abstract class BaseMenuAnimator implements IMenuAnimator { // =========================================================== // Constants // =========================================================== protected static final float DURATION = 1.0f; private static final float MENUITEMSPACING_DEFAULT = 1.0f; private static final HorizontalAlign HORIZONTALALIGN_DEFAULT = HorizontalAlign.CENTER; // =========================================================== // Fields // =========================================================== protected final float mMenuItemSpacing; protected final HorizontalAlign mHorizontalAlign; protected final IEaseFunction mEaseFunction; // =========================================================== // Constructors // =========================================================== public BaseMenuAnimator() { this(MENUITEMSPACING_DEFAULT); } public BaseMenuAnimator(final IEaseFunction pEaseFunction) { this(MENUITEMSPACING_DEFAULT, pEaseFunction); } public BaseMenuAnimator(final float pMenuItemSpacing) { this(HORIZONTALALIGN_DEFAULT, pMenuItemSpacing); } public BaseMenuAnimator(final float pMenuItemSpacing, final IEaseFunction pEaseFunction) { this(HORIZONTALALIGN_DEFAULT, pMenuItemSpacing, pEaseFunction); } public BaseMenuAnimator(final HorizontalAlign pHorizontalAlign) { this(pHorizontalAlign, MENUITEMSPACING_DEFAULT); } public BaseMenuAnimator(final HorizontalAlign pHorizontalAlign, final IEaseFunction pEaseFunction) { this(pHorizontalAlign, MENUITEMSPACING_DEFAULT, pEaseFunction); } public BaseMenuAnimator(final HorizontalAlign pHorizontalAlign, final float pMenuItemSpacing) { this(pHorizontalAlign, pMenuItemSpacing, IEaseFunction.DEFAULT); } public BaseMenuAnimator(final HorizontalAlign pHorizontalAlign, final float pMenuItemSpacing, final IEaseFunction pEaseFunction) { this.mHorizontalAlign = pHorizontalAlign; this.mMenuItemSpacing = pMenuItemSpacing; this.mEaseFunction = pEaseFunction; } // =========================================================== // Getter & Setter // =========================================================== protected float getMaximumWidth(final ArrayList<IMenuItem> pMenuItems) { float maximumWidth = Float.MIN_VALUE; for(int i = pMenuItems.size() - 1; i >= 0; i--) { final IMenuItem menuItem = pMenuItems.get(i); maximumWidth = Math.max(maximumWidth, menuItem.getWidthScaled()); } return maximumWidth; } protected float getOverallHeight(final ArrayList<IMenuItem> pMenuItems) { float overallHeight = 0; for(int i = pMenuItems.size() - 1; i >= 0; i--) { final IMenuItem menuItem = pMenuItems.get(i); overallHeight += menuItem.getHeight(); } overallHeight += (pMenuItems.size() - 1) * this.mMenuItemSpacing; return overallHeight; } // =========================================================== // Methods for/from SuperClass/Interfaces // =========================================================== // =========================================================== // Methods // =========================================================== // =========================================================== // Inner and Anonymous Classes // =========================================================== }
Java
package org.anddev.andengine.entity.scene.menu.animator; import java.util.ArrayList; import org.anddev.andengine.entity.modifier.AlphaModifier; import org.anddev.andengine.entity.scene.menu.item.IMenuItem; import org.anddev.andengine.util.HorizontalAlign; import org.anddev.andengine.util.modifier.ease.IEaseFunction; /** * (c) 2010 Nicolas Gramlich * (c) 2011 Zynga Inc. * * @author Nicolas Gramlich * @since 11:04:35 - 02.04.2010 */ public class AlphaMenuAnimator extends BaseMenuAnimator { // =========================================================== // Constants // =========================================================== private static final float ALPHA_FROM = 0.0f; private static final float ALPHA_TO = 1.0f; // =========================================================== // Fields // =========================================================== // =========================================================== // Constructors // =========================================================== public AlphaMenuAnimator(){ super(); } public AlphaMenuAnimator(final IEaseFunction pEaseFunction) { super(pEaseFunction); } public AlphaMenuAnimator(final HorizontalAlign pHorizontalAlign) { super(pHorizontalAlign); } public AlphaMenuAnimator(final HorizontalAlign pHorizontalAlign, final IEaseFunction pEaseFunction) { super(pHorizontalAlign, pEaseFunction); } public AlphaMenuAnimator(final float pMenuItemSpacing) { super(pMenuItemSpacing); } public AlphaMenuAnimator(final float pMenuItemSpacing, final IEaseFunction pEaseFunction) { super(pMenuItemSpacing, pEaseFunction); } public AlphaMenuAnimator(final HorizontalAlign pHorizontalAlign, final float pMenuItemSpacing) { super(pHorizontalAlign, pMenuItemSpacing); } public AlphaMenuAnimator(final HorizontalAlign pHorizontalAlign, final float pMenuItemSpacing, final IEaseFunction pEaseFunction) { super(pHorizontalAlign, pMenuItemSpacing, pEaseFunction); } // =========================================================== // Getter & Setter // =========================================================== // =========================================================== // Methods for/from SuperClass/Interfaces // =========================================================== @Override public void buildAnimations(final ArrayList<IMenuItem> pMenuItems, final float pCameraWidth, final float pCameraHeight) { final IEaseFunction easeFunction = this.mEaseFunction; final int menuItemCount = pMenuItems.size(); for(int i = menuItemCount - 1; i >= 0; i--) { final AlphaModifier alphaModifier = new AlphaModifier(DURATION, ALPHA_FROM, ALPHA_TO, easeFunction); alphaModifier.setRemoveWhenFinished(false); pMenuItems.get(i).registerEntityModifier(alphaModifier); } } @Override public void prepareAnimations(final ArrayList<IMenuItem> pMenuItems, final float pCameraWidth, final float pCameraHeight) { final float maximumWidth = this.getMaximumWidth(pMenuItems); final float overallHeight = this.getOverallHeight(pMenuItems); final float baseX = (pCameraWidth - maximumWidth) * 0.5f; final float baseY = (pCameraHeight - overallHeight) * 0.5f; final float menuItemSpacing = this.mMenuItemSpacing; float offsetY = 0; final int menuItemCount = pMenuItems.size(); for(int i = 0; i < menuItemCount; i++) { final IMenuItem menuItem = pMenuItems.get(i); final float offsetX; switch(this.mHorizontalAlign) { case LEFT: offsetX = 0; break; case RIGHT: offsetX = maximumWidth - menuItem.getWidthScaled(); break; case CENTER: default: offsetX = (maximumWidth - menuItem.getWidthScaled()) * 0.5f; break; } menuItem.setPosition(baseX + offsetX , baseY + offsetY); menuItem.setAlpha(ALPHA_FROM); offsetY += menuItem.getHeight() + menuItemSpacing; } } // =========================================================== // Methods // =========================================================== // =========================================================== // Inner and Anonymous Classes // =========================================================== }
Java
package org.anddev.andengine.entity.scene.menu.animator; import java.util.ArrayList; import org.anddev.andengine.entity.scene.menu.item.IMenuItem; /** * (c) 2010 Nicolas Gramlich * (c) 2011 Zynga Inc. * * @author Nicolas Gramlich * @since 10:50:36 - 02.04.2010 */ public interface IMenuAnimator { // =========================================================== // Constants // =========================================================== public static final IMenuAnimator DEFAULT = new AlphaMenuAnimator(); // =========================================================== // Methods // =========================================================== public void prepareAnimations(final ArrayList<IMenuItem> pMenuItems, final float pCameraWidth, final float pCameraHeight); public void buildAnimations(final ArrayList<IMenuItem> pMenuItems, final float pCameraWidth, final float pCameraHeight); }
Java
package org.anddev.andengine.entity.scene.menu.animator; import java.util.ArrayList; import org.anddev.andengine.entity.scene.menu.item.IMenuItem; import org.anddev.andengine.util.HorizontalAlign; /** * (c) 2010 Nicolas Gramlich * (c) 2011 Zynga Inc. * * @author Nicolas Gramlich * @since 10:46:34 - 14.05.2010 */ public class DirectMenuAnimator extends BaseMenuAnimator { // =========================================================== // Constants // =========================================================== // =========================================================== // Fields // =========================================================== // =========================================================== // Constructors // =========================================================== public DirectMenuAnimator(){ super(); } public DirectMenuAnimator(final HorizontalAlign pHorizontalAlign) { super(pHorizontalAlign); } public DirectMenuAnimator(final float pMenuItemSpacing) { super(pMenuItemSpacing); } public DirectMenuAnimator(final HorizontalAlign pHorizontalAlign, final float pMenuItemSpacing) { super(pHorizontalAlign, pMenuItemSpacing); } // =========================================================== // Getter & Setter // =========================================================== // =========================================================== // Methods for/from SuperClass/Interfaces // =========================================================== @Override public void buildAnimations(final ArrayList<IMenuItem> pMenuItems, final float pCameraWidth, final float pCameraHeight) { } @Override public void prepareAnimations(final ArrayList<IMenuItem> pMenuItems, final float pCameraWidth, final float pCameraHeight) { final float maximumWidth = this.getMaximumWidth(pMenuItems); final float overallHeight = this.getOverallHeight(pMenuItems); final float baseX = (pCameraWidth - maximumWidth) * 0.5f; final float baseY = (pCameraHeight - overallHeight) * 0.5f; final float menuItemSpacing = this.mMenuItemSpacing; float offsetY = 0; final int menuItemCount = pMenuItems.size(); for(int i = 0; i < menuItemCount; i++) { final IMenuItem menuItem = pMenuItems.get(i); final float offsetX; switch(this.mHorizontalAlign) { case LEFT: offsetX = 0; break; case RIGHT: offsetX = maximumWidth - menuItem.getWidthScaled(); break; case CENTER: default: offsetX = (maximumWidth - menuItem.getWidthScaled()) * 0.5f; break; } menuItem.setPosition(baseX + offsetX , baseY + offsetY); offsetY += menuItem.getHeight() + menuItemSpacing; } } // =========================================================== // Methods // =========================================================== // =========================================================== // Inner and Anonymous Classes // =========================================================== }
Java
package org.anddev.andengine.entity.scene.menu.item; import org.anddev.andengine.entity.text.Text; import org.anddev.andengine.opengl.font.Font; /** * (c) 2010 Nicolas Gramlich * (c) 2011 Zynga Inc. * * @author Nicolas Gramlich * @since 20:15:20 - 01.04.2010 */ public class TextMenuItem extends Text implements IMenuItem{ // =========================================================== // Constants // =========================================================== // =========================================================== // Fields // =========================================================== private final int mID; // =========================================================== // Constructors // =========================================================== public TextMenuItem(final int pID, final Font pFont, final String pText) { super(0, 0, pFont, pText); this.mID = pID; } // =========================================================== // Getter & Setter // =========================================================== @Override public int getID() { return this.mID; } // =========================================================== // Getter & Setter // =========================================================== // =========================================================== // Methods for/from SuperClass/Interfaces // =========================================================== @Override public void onSelected() { /* Nothing. */ } @Override public void onUnselected() { /* Nothing. */ } // =========================================================== // Methods // =========================================================== // =========================================================== // Inner and Anonymous Classes // =========================================================== }
Java
package org.anddev.andengine.entity.scene.menu.item; import org.anddev.andengine.entity.sprite.AnimatedSprite; import org.anddev.andengine.opengl.texture.region.TiledTextureRegion; /** * (c) 2010 Nicolas Gramlich * (c) 2011 Zynga Inc. * * @author Nicolas Gramlich * @since 15:44:39 - 07.07.2010 */ public class AnimatedSpriteMenuItem extends AnimatedSprite implements IMenuItem { // =========================================================== // Constants // =========================================================== // =========================================================== // Fields // =========================================================== private final int mID; // =========================================================== // Constructors // =========================================================== public AnimatedSpriteMenuItem(final int pID, final TiledTextureRegion pTiledTextureRegion) { super(0, 0, pTiledTextureRegion); this.mID = pID; } // =========================================================== // Getter & Setter // =========================================================== @Override public int getID() { return this.mID; } // =========================================================== // Getter & Setter // =========================================================== // =========================================================== // Methods for/from SuperClass/Interfaces // =========================================================== @Override public void onSelected() { /* Nothing. */ } @Override public void onUnselected() { /* Nothing. */ } // =========================================================== // Methods // =========================================================== // =========================================================== // Inner and Anonymous Classes // =========================================================== }
Java
package org.anddev.andengine.entity.scene.menu.item; import org.anddev.andengine.entity.sprite.Sprite; import org.anddev.andengine.opengl.texture.region.TextureRegion; /** * (c) 2010 Nicolas Gramlich * (c) 2011 Zynga Inc. * * @author Nicolas Gramlich * @since 20:15:20 - 01.04.2010 */ public class SpriteMenuItem extends Sprite implements IMenuItem { // =========================================================== // Constants // =========================================================== // =========================================================== // Fields // =========================================================== private final int mID; // =========================================================== // Constructors // =========================================================== public SpriteMenuItem(final int pID, final TextureRegion pTextureRegion) { super(0, 0, pTextureRegion); this.mID = pID; } // =========================================================== // Getter & Setter // =========================================================== @Override public int getID() { return this.mID; } // =========================================================== // Getter & Setter // =========================================================== // =========================================================== // Methods for/from SuperClass/Interfaces // =========================================================== @Override public void onSelected() { /* Nothing. */ } @Override public void onUnselected() { /* Nothing. */ } // =========================================================== // Methods // =========================================================== // =========================================================== // Inner and Anonymous Classes // =========================================================== }
Java
package org.anddev.andengine.entity.scene.menu.item; import org.anddev.andengine.entity.shape.IShape; /** * (c) 2010 Nicolas Gramlich * (c) 2011 Zynga Inc. * * @author Nicolas Gramlich * @since 13:27:16 - 07.07.2010 */ public interface IMenuItem extends IShape { // =========================================================== // Final Fields // =========================================================== // =========================================================== // Methods // =========================================================== public int getID(); public abstract void onSelected(); public abstract void onUnselected(); }
Java
package org.anddev.andengine.entity.scene.menu.item.decorator; import java.util.Comparator; import javax.microedition.khronos.opengles.GL10; import org.anddev.andengine.engine.camera.Camera; import org.anddev.andengine.engine.handler.IUpdateHandler; import org.anddev.andengine.entity.IEntity; import org.anddev.andengine.entity.modifier.IEntityModifier; import org.anddev.andengine.entity.modifier.IEntityModifier.IEntityModifierMatcher; import org.anddev.andengine.entity.scene.menu.item.IMenuItem; import org.anddev.andengine.entity.shape.IShape; import org.anddev.andengine.input.touch.TouchEvent; import org.anddev.andengine.util.Transformation; /** * (c) 2010 Nicolas Gramlich * (c) 2011 Zynga Inc. * * @author Nicolas Gramlich * @since 15:05:44 - 18.11.2010 */ public abstract class BaseMenuItemDecorator implements IMenuItem { // =========================================================== // Constants // =========================================================== // =========================================================== // Fields // =========================================================== private final IMenuItem mMenuItem; // =========================================================== // Constructors // =========================================================== public BaseMenuItemDecorator(final IMenuItem pMenuItem) { this.mMenuItem = pMenuItem; } // =========================================================== // Getter & Setter // =========================================================== // =========================================================== // Methods for/from SuperClass/Interfaces // =========================================================== protected abstract void onMenuItemSelected(final IMenuItem pMenuItem); protected abstract void onMenuItemUnselected(final IMenuItem pMenuItem); protected abstract void onMenuItemReset(final IMenuItem pMenuItem); @Override public int getID() { return this.mMenuItem.getID(); } @Override public final void onSelected() { this.mMenuItem.onSelected(); this.onMenuItemSelected(this.mMenuItem); } @Override public final void onUnselected() { this.mMenuItem.onUnselected(); this.onMenuItemUnselected(this.mMenuItem); } @Override public float getX() { return this.mMenuItem.getX(); } @Override public float getY() { return this.mMenuItem.getY(); } @Override public void setPosition(final IEntity pOtherEntity) { this.mMenuItem.setPosition(pOtherEntity); } @Override public void setPosition(final float pX, final float pY) { this.mMenuItem.setPosition(pX, pY); } @Override public float getBaseWidth() { return this.mMenuItem.getBaseWidth(); } @Override public float getBaseHeight() { return this.mMenuItem.getBaseHeight(); } @Override public float getWidth() { return this.mMenuItem.getWidth(); } @Override public float getWidthScaled() { return this.mMenuItem.getWidthScaled(); } @Override public float getHeight() { return this.mMenuItem.getHeight(); } @Override public float getHeightScaled() { return this.mMenuItem.getHeightScaled(); } @Override public float getInitialX() { return this.mMenuItem.getInitialX(); } @Override public float getInitialY() { return this.mMenuItem.getInitialY(); } @Override public float getRed() { return this.mMenuItem.getRed(); } @Override public float getGreen() { return this.mMenuItem.getGreen(); } @Override public float getBlue() { return this.mMenuItem.getBlue(); } @Override public float getAlpha() { return this.mMenuItem.getAlpha(); } @Override public void setAlpha(final float pAlpha) { this.mMenuItem.setAlpha(pAlpha); } @Override public void setColor(final float pRed, final float pGreen, final float pBlue) { this.mMenuItem.setColor(pRed, pGreen, pBlue); } @Override public void setColor(final float pRed, final float pGreen, final float pBlue, final float pAlpha) { this.mMenuItem.setColor(pRed, pGreen, pBlue, pAlpha); } @Override public boolean isRotated() { return this.mMenuItem.isRotated(); } @Override public float getRotation() { return this.mMenuItem.getRotation(); } @Override public void setRotation(final float pRotation) { this.mMenuItem.setRotation(pRotation); } @Override public float getRotationCenterX() { return this.mMenuItem.getRotationCenterX(); } @Override public float getRotationCenterY() { return this.mMenuItem.getRotationCenterY(); } @Override public void setRotationCenterX(final float pRotationCenterX) { this.mMenuItem.setRotationCenterX(pRotationCenterX); } @Override public void setRotationCenterY(final float pRotationCenterY) { this.mMenuItem.setRotationCenterY(pRotationCenterY); } @Override public void setRotationCenter(final float pRotationCenterX, final float pRotationCenterY) { this.mMenuItem.setRotationCenter(pRotationCenterX, pRotationCenterY); } @Override public boolean isScaled() { return this.mMenuItem.isScaled(); } @Override public float getScaleX() { return this.mMenuItem.getScaleX(); } @Override public float getScaleY() { return this.mMenuItem.getScaleY(); } @Override public void setScale(final float pScale) { this.mMenuItem.setScale(pScale); } @Override public void setScale(final float pScaleX, final float pScaleY) { this.mMenuItem.setScale(pScaleX, pScaleY); } @Override public void setScaleX(final float pScaleX) { this.mMenuItem.setScaleX(pScaleX); } @Override public void setScaleY(final float pScaleY) { this.mMenuItem.setScaleY(pScaleY); } @Override public float getScaleCenterX() { return this.mMenuItem.getScaleCenterX(); } @Override public float getScaleCenterY() { return this.mMenuItem.getScaleCenterY(); } @Override public void setScaleCenterX(final float pScaleCenterX) { this.mMenuItem.setScaleCenterX(pScaleCenterX); } @Override public void setScaleCenterY(final float pScaleCenterY) { this.mMenuItem.setScaleCenterY(pScaleCenterY); } @Override public void setScaleCenter(final float pScaleCenterX, final float pScaleCenterY) { this.mMenuItem.setScaleCenter(pScaleCenterX, pScaleCenterY); } @Override public boolean collidesWith(final IShape pOtherShape) { return this.mMenuItem.collidesWith(pOtherShape); } @Override public float[] getSceneCenterCoordinates() { return this.mMenuItem.getSceneCenterCoordinates(); } @Override public boolean isCullingEnabled() { return this.mMenuItem.isCullingEnabled(); } @Override public void registerEntityModifier(final IEntityModifier pEntityModifier) { this.mMenuItem.registerEntityModifier(pEntityModifier); } @Override public boolean unregisterEntityModifier(final IEntityModifier pEntityModifier) { return this.mMenuItem.unregisterEntityModifier(pEntityModifier); } @Override public boolean unregisterEntityModifiers(final IEntityModifierMatcher pEntityModifierMatcher) { return this.mMenuItem.unregisterEntityModifiers(pEntityModifierMatcher); } @Override public void clearEntityModifiers() { this.mMenuItem.clearEntityModifiers(); } @Override public void setInitialPosition() { this.mMenuItem.setInitialPosition(); } @Override public void setBlendFunction(final int pSourceBlendFunction, final int pDestinationBlendFunction) { this.mMenuItem.setBlendFunction(pSourceBlendFunction, pDestinationBlendFunction); } @Override public void setCullingEnabled(final boolean pCullingEnabled) { this.mMenuItem.setCullingEnabled(pCullingEnabled); } @Override public int getZIndex() { return this.mMenuItem.getZIndex(); } @Override public void setZIndex(final int pZIndex) { this.mMenuItem.setZIndex(pZIndex); } @Override public void onDraw(final GL10 pGL, final Camera pCamera) { this.mMenuItem.onDraw(pGL, pCamera); } @Override public void onUpdate(final float pSecondsElapsed) { this.mMenuItem.onUpdate(pSecondsElapsed); } @Override public void reset() { this.mMenuItem.reset(); this.onMenuItemReset(this.mMenuItem); } @Override public boolean contains(final float pX, final float pY) { return this.mMenuItem.contains(pX, pY); } @Override public float[] convertLocalToSceneCoordinates(final float pX, final float pY) { return this.mMenuItem.convertLocalToSceneCoordinates(pX, pY); } @Override public float[] convertLocalToSceneCoordinates(final float pX, final float pY, final float[] pReuse) { return this.mMenuItem.convertLocalToSceneCoordinates(pX, pY, pReuse); } @Override public float[] convertLocalToSceneCoordinates(final float[] pCoordinates) { return this.mMenuItem.convertLocalToSceneCoordinates(pCoordinates); } @Override public float[] convertLocalToSceneCoordinates(final float[] pCoordinates, final float[] pReuse) { return this.mMenuItem.convertLocalToSceneCoordinates(pCoordinates, pReuse); } @Override public float[] convertSceneToLocalCoordinates(final float pX, final float pY) { return this.mMenuItem.convertSceneToLocalCoordinates(pX, pY); } @Override public float[] convertSceneToLocalCoordinates(final float pX, final float pY, final float[] pReuse) { return this.mMenuItem.convertSceneToLocalCoordinates(pX, pY, pReuse); } @Override public float[] convertSceneToLocalCoordinates(final float[] pCoordinates) { return this.mMenuItem.convertSceneToLocalCoordinates(pCoordinates); } @Override public float[] convertSceneToLocalCoordinates(final float[] pCoordinates, final float[] pReuse) { return this.mMenuItem.convertSceneToLocalCoordinates(pCoordinates, pReuse); } @Override public boolean onAreaTouched(final TouchEvent pSceneTouchEvent, final float pTouchAreaLocalX, final float pTouchAreaLocalY) { return this.mMenuItem.onAreaTouched(pSceneTouchEvent, pTouchAreaLocalX, pTouchAreaLocalY); } @Override public int getChildCount() { return this.mMenuItem.getChildCount(); } @Override public void attachChild(final IEntity pEntity) { this.mMenuItem.attachChild(pEntity); } @Override public boolean attachChild(final IEntity pEntity, final int pIndex) { return this.mMenuItem.attachChild(pEntity, pIndex); } @Override public IEntity getFirstChild() { return this.mMenuItem.getFirstChild(); } @Override public IEntity getLastChild() { return this.mMenuItem.getLastChild(); } @Override public IEntity getChild(final int pIndex) { return this.mMenuItem.getChild(pIndex); } @Override public int getChildIndex(final IEntity pEntity) { return this.mMenuItem.getChildIndex(pEntity); } @Override public boolean setChildIndex(final IEntity pEntity, final int pIndex) { return this.mMenuItem.setChildIndex(pEntity, pIndex); } @Override public IEntity findChild(final IEntityMatcher pEntityMatcher) { return this.mMenuItem.findChild(pEntityMatcher); } @Override public boolean swapChildren(final IEntity pEntityA, final IEntity pEntityB) { return this.mMenuItem.swapChildren(pEntityA, pEntityB); } @Override public boolean swapChildren(final int pIndexA, final int pIndexB) { return this.mMenuItem.swapChildren(pIndexA, pIndexB); } @Override public void sortChildren() { this.mMenuItem.sortChildren(); } @Override public void sortChildren(final Comparator<IEntity> pEntityComparator) { this.mMenuItem.sortChildren(pEntityComparator); } @Override public boolean detachSelf() { return this.mMenuItem.detachSelf(); } @Override public boolean detachChild(final IEntity pEntity) { return this.mMenuItem.detachChild(pEntity); } @Override public IEntity detachChild(final IEntityMatcher pEntityMatcher) { return this.mMenuItem.detachChild(pEntityMatcher); } @Override public boolean detachChildren(final IEntityMatcher pEntityMatcher) { return this.mMenuItem.detachChildren(pEntityMatcher); } @Override public void detachChildren() { this.mMenuItem.detachChildren(); } @Override public void callOnChildren(final IEntityCallable pEntityCallable) { this.callOnChildren(pEntityCallable); } @Override public void callOnChildren(final IEntityMatcher pEntityMatcher, final IEntityCallable pEntityCallable) { this.mMenuItem.callOnChildren(pEntityMatcher, pEntityCallable); } @Override public Transformation getLocalToSceneTransformation() { return this.mMenuItem.getLocalToSceneTransformation(); } @Override public Transformation getSceneToLocalTransformation() { return this.mMenuItem.getSceneToLocalTransformation(); } @Override public boolean hasParent() { return this.mMenuItem.hasParent(); } @Override public IEntity getParent() { return this.mMenuItem.getParent(); } @Override public void setParent(final IEntity pEntity) { this.mMenuItem.setParent(pEntity); } @Override public boolean isVisible() { return this.mMenuItem.isVisible(); } @Override public void setVisible(final boolean pVisible) { this.mMenuItem.setVisible(pVisible); } @Override public boolean isChildrenVisible() { return this.mMenuItem.isChildrenVisible(); } @Override public void setChildrenVisible(final boolean pChildrenVisible) { this.mMenuItem.setChildrenVisible(pChildrenVisible); } @Override public boolean isIgnoreUpdate() { return this.mMenuItem.isIgnoreUpdate(); } @Override public void setIgnoreUpdate(final boolean pIgnoreUpdate) { this.mMenuItem.setIgnoreUpdate(pIgnoreUpdate); } @Override public boolean isChildrenIgnoreUpdate() { return this.mMenuItem.isChildrenIgnoreUpdate(); } @Override public void setChildrenIgnoreUpdate(final boolean pChildrenIgnoreUpdate) { this.mMenuItem.setChildrenIgnoreUpdate(pChildrenIgnoreUpdate); } @Override public void setUserData(final Object pUserData) { this.mMenuItem.setUserData(pUserData); } @Override public Object getUserData() { return this.mMenuItem.getUserData(); } @Override public void onAttached() { this.mMenuItem.onAttached(); } @Override public void onDetached() { this.mMenuItem.onDetached(); } @Override public void registerUpdateHandler(final IUpdateHandler pUpdateHandler) { this.mMenuItem.registerUpdateHandler(pUpdateHandler); } @Override public boolean unregisterUpdateHandler(final IUpdateHandler pUpdateHandler) { return this.mMenuItem.unregisterUpdateHandler(pUpdateHandler); } @Override public void clearUpdateHandlers() { this.mMenuItem.clearUpdateHandlers(); } @Override public boolean unregisterUpdateHandlers(final IUpdateHandlerMatcher pUpdateHandlerMatcher) { return this.mMenuItem.unregisterUpdateHandlers(pUpdateHandlerMatcher); } // =========================================================== // Methods // =========================================================== // =========================================================== // Inner and Anonymous Classes // =========================================================== }
Java
package org.anddev.andengine.entity.scene.menu.item.decorator; import org.anddev.andengine.entity.scene.menu.item.IMenuItem; /** * (c) 2010 Nicolas Gramlich * (c) 2011 Zynga Inc. * * @author Nicolas Gramlich * @since 15:04:29 - 18.11.2010 */ public class ScaleMenuItemDecorator extends BaseMenuItemDecorator { // =========================================================== // Constants // =========================================================== // =========================================================== // Fields // =========================================================== private final float mSelectedScale; private final float mUnselectedScale; // =========================================================== // Constructors // =========================================================== public ScaleMenuItemDecorator(final IMenuItem pMenuItem, final float pSelectedScale, final float pUnselectedScale) { super(pMenuItem); this.mSelectedScale = pSelectedScale; this.mUnselectedScale = pUnselectedScale; pMenuItem.setScale(pUnselectedScale); } // =========================================================== // Getter & Setter // =========================================================== // =========================================================== // Getter & Setter // =========================================================== // =========================================================== // Methods for/from SuperClass/Interfaces // =========================================================== @Override public void onMenuItemSelected(final IMenuItem pMenuItem) { this.setScale(this.mSelectedScale); } @Override public void onMenuItemUnselected(final IMenuItem pMenuItem) { this.setScale(this.mUnselectedScale); } @Override public void onMenuItemReset(final IMenuItem pMenuItem) { this.setScale(this.mUnselectedScale); } // =========================================================== // Methods // =========================================================== // =========================================================== // Inner and Anonymous Classes // =========================================================== }
Java
package org.anddev.andengine.entity.scene.menu.item.decorator; import org.anddev.andengine.entity.scene.menu.item.IMenuItem; /** * (c) 2010 Nicolas Gramlich * (c) 2011 Zynga Inc. * * @author Nicolas Gramlich * @since 14:25:35 - 07.07.2010 */ public class ColorMenuItemDecorator extends BaseMenuItemDecorator { // =========================================================== // Constants // =========================================================== // =========================================================== // Fields // =========================================================== private final float mSelectedRed; private final float mSelectedGreen; private final float mSelectedBlue; private final float mUnselectedRed; private final float mUnselectedGreen; private final float mUnselectedBlue; // =========================================================== // Constructors // =========================================================== public ColorMenuItemDecorator(final IMenuItem pMenuItem, final float pSelectedRed, final float pSelectedGreen, final float pSelectedBlue, final float pUnselectedRed, final float pUnselectedGreen, final float pUnselectedBlue) { super(pMenuItem); this.mSelectedRed = pSelectedRed; this.mSelectedGreen = pSelectedGreen; this.mSelectedBlue = pSelectedBlue; this.mUnselectedRed = pUnselectedRed; this.mUnselectedGreen = pUnselectedGreen; this.mUnselectedBlue = pUnselectedBlue; pMenuItem.setColor(this.mUnselectedRed, this.mUnselectedGreen, this.mUnselectedBlue); } // =========================================================== // Getter & Setter // =========================================================== // =========================================================== // Getter & Setter // =========================================================== // =========================================================== // Methods for/from SuperClass/Interfaces // =========================================================== @Override public void onMenuItemSelected(final IMenuItem pMenuItem) { pMenuItem.setColor(this.mSelectedRed, this.mSelectedGreen, this.mSelectedBlue); } @Override public void onMenuItemUnselected(final IMenuItem pMenuItem) { pMenuItem.setColor(this.mUnselectedRed, this.mUnselectedGreen, this.mUnselectedBlue); } @Override public void onMenuItemReset(final IMenuItem pMenuItem) { pMenuItem.setColor(this.mUnselectedRed, this.mUnselectedGreen, this.mUnselectedBlue); } // =========================================================== // Methods // =========================================================== // =========================================================== // Inner and Anonymous Classes // =========================================================== }
Java
package org.anddev.andengine.entity.scene; import org.anddev.andengine.engine.camera.Camera; import org.anddev.andengine.entity.modifier.ScaleModifier; import org.anddev.andengine.entity.sprite.Sprite; import org.anddev.andengine.opengl.texture.region.TextureRegion; import org.anddev.andengine.util.modifier.ease.IEaseFunction; /** * (c) 2010 Nicolas Gramlich * (c) 2011 Zynga Inc. * * @author Nicolas Gramlich * @since 09:45:02 - 03.05.2010 */ public class SplashScene extends Scene { // =========================================================== // Constants // =========================================================== // =========================================================== // Fields // =========================================================== // =========================================================== // Constructors // =========================================================== public SplashScene(final Camera pCamera, final TextureRegion pTextureRegion) { this(pCamera, pTextureRegion, -1, 1, 1); } public SplashScene(final Camera pCamera, final TextureRegion pTextureRegion, final float pDuration, final float pScaleFrom, final float pScaleTo) { final Sprite loadingScreenSprite = new Sprite(pCamera.getMinX(), pCamera.getMinY(), pCamera.getWidth(), pCamera.getHeight(), pTextureRegion); if(pScaleFrom != 1 || pScaleTo != 1) { loadingScreenSprite.setScale(pScaleFrom); loadingScreenSprite.registerEntityModifier(new ScaleModifier(pDuration, pScaleFrom, pScaleTo, IEaseFunction.DEFAULT)); } this.attachChild(loadingScreenSprite); } // =========================================================== // Getter & Setter // =========================================================== // =========================================================== // Methods for/from SuperClass/Interfaces // =========================================================== // =========================================================== // Methods // =========================================================== // =========================================================== // Inner and Anonymous Classes // =========================================================== }
Java
package org.anddev.andengine.entity.scene.background; import static org.anddev.andengine.util.constants.ColorConstants.COLOR_FACTOR_INT_TO_FLOAT; import javax.microedition.khronos.opengles.GL10; import org.anddev.andengine.engine.camera.Camera; /** * (c) 2010 Nicolas Gramlich * (c) 2011 Zynga Inc. * * @author Nicolas Gramlich * @since 13:45:24 - 19.07.2010 */ public class ColorBackground extends BaseBackground { // =========================================================== // Constants // =========================================================== // =========================================================== // Fields // =========================================================== private float mRed = 0.0f; private float mGreen = 0.0f; private float mBlue = 0.0f; private float mAlpha = 1.0f; private boolean mColorEnabled = true; // =========================================================== // Constructors // =========================================================== protected ColorBackground() { } public ColorBackground(final float pRed, final float pGreen, final float pBlue) { this.mRed = pRed; this.mGreen = pGreen; this.mBlue = pBlue; } public ColorBackground(final float pRed, final float pGreen, final float pBlue, final float pAlpha) { this.mRed = pRed; this.mGreen = pGreen; this.mBlue = pBlue; this.mAlpha = pAlpha; } // =========================================================== // Getter & Setter // =========================================================== /** * Sets the color using the arithmetic scheme (0.0f - 1.0f RGB triple). * @param pRed The red color value. Should be between 0.0 and 1.0, inclusive. * @param pGreen The green color value. Should be between 0.0 and 1.0, inclusive. * @param pBlue The blue color value. Should be between 0.0 and 1.0, inclusive. */ @Override public void setColor(final float pRed, final float pGreen, final float pBlue) { this.mRed = pRed; this.mGreen = pGreen; this.mBlue = pBlue; } /** * Sets the color using the arithmetic scheme (0.0f - 1.0f RGB quadruple). * @param pRed The red color value. Should be between 0.0 and 1.0, inclusive. * @param pGreen The green color value. Should be between 0.0 and 1.0, inclusive. * @param pBlue The blue color value. Should be between 0.0 and 1.0, inclusive. * @param pAlpha The alpha color value. Should be between 0.0 and 1.0, inclusive. */ @Override public void setColor(final float pRed, final float pGreen, final float pBlue, final float pAlpha) { this.setColor(pRed, pGreen, pBlue); this.mAlpha = pAlpha; } /** * Sets the color using the digital 8-bit per channel scheme (0 - 255 RGB triple). * @param pRed The red color value. Should be between 0 and 255, inclusive. * @param pGreen The green color value. Should be between 0 and 255, inclusive. * @param pBlue The blue color value. Should be between 0 and 255, inclusive. */ public void setColor(final int pRed, final int pGreen, final int pBlue) throws IllegalArgumentException { this.setColor(pRed / COLOR_FACTOR_INT_TO_FLOAT, pGreen / COLOR_FACTOR_INT_TO_FLOAT, pBlue / COLOR_FACTOR_INT_TO_FLOAT); } /** * Sets the color using the digital 8-bit per channel scheme (0 - 255 RGB quadruple). * @param pRed The red color value. Should be between 0 and 255, inclusive. * @param pGreen The green color value. Should be between 0 and 255, inclusive. * @param pBlue The blue color value. Should be between 0 and 255, inclusive. */ public void setColor(final int pRed, final int pGreen, final int pBlue, final int pAlpha) throws IllegalArgumentException { this.setColor(pRed / COLOR_FACTOR_INT_TO_FLOAT, pGreen / COLOR_FACTOR_INT_TO_FLOAT, pBlue / COLOR_FACTOR_INT_TO_FLOAT, pAlpha / COLOR_FACTOR_INT_TO_FLOAT); } public void setColorEnabled(final boolean pColorEnabled) { this.mColorEnabled = pColorEnabled; } public boolean isColorEnabled() { return this.mColorEnabled; } // =========================================================== // Methods for/from SuperClass/Interfaces // =========================================================== @Override public void onDraw(final GL10 pGL, final Camera pCamera) { if(this.mColorEnabled) { pGL.glClearColor(this.mRed, this.mGreen, this.mBlue, this.mAlpha); pGL.glClear(GL10.GL_COLOR_BUFFER_BIT); } } // =========================================================== // Methods // =========================================================== // =========================================================== // Inner and Anonymous Classes // =========================================================== }
Java
package org.anddev.andengine.entity.scene.background; import org.anddev.andengine.engine.handler.IUpdateHandler; import org.anddev.andengine.opengl.IDrawable; import org.anddev.andengine.util.modifier.IModifier; /** * (c) 2010 Nicolas Gramlich * (c) 2011 Zynga Inc. * * @author Nicolas Gramlich * @since 13:47:41 - 19.07.2010 */ public interface IBackground extends IDrawable, IUpdateHandler { // =========================================================== // Final Fields // =========================================================== // =========================================================== // Methods // =========================================================== public void addBackgroundModifier(final IModifier<IBackground> pBackgroundModifier); public boolean removeBackgroundModifier(final IModifier<IBackground> pBackgroundModifier); public void clearBackgroundModifiers(); 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); }
Java
package org.anddev.andengine.entity.scene.background; import org.anddev.andengine.util.modifier.IModifier; import org.anddev.andengine.util.modifier.ModifierList; /** * (c) 2010 Nicolas Gramlich * (c) 2011 Zynga Inc. * * @author Nicolas Gramlich * @since 14:08:17 - 19.07.2010 */ public abstract class BaseBackground implements IBackground { // =========================================================== // Constants // =========================================================== private static final int BACKGROUNDMODIFIERS_CAPACITY_DEFAULT = 4; // =========================================================== // Fields // =========================================================== private final ModifierList<IBackground> mBackgroundModifiers = new ModifierList<IBackground>(this, BACKGROUNDMODIFIERS_CAPACITY_DEFAULT); // =========================================================== // Constructors // =========================================================== // =========================================================== // Getter & Setter // =========================================================== // =========================================================== // Methods for/from SuperClass/Interfaces // =========================================================== @Override public void addBackgroundModifier(final IModifier<IBackground> pBackgroundModifier) { this.mBackgroundModifiers.add(pBackgroundModifier); } @Override public boolean removeBackgroundModifier(final IModifier<IBackground> pBackgroundModifier) { return this.mBackgroundModifiers.remove(pBackgroundModifier); } @Override public void clearBackgroundModifiers() { this.mBackgroundModifiers.clear(); } @Override public void onUpdate(final float pSecondsElapsed) { this.mBackgroundModifiers.onUpdate(pSecondsElapsed); } @Override public void reset() { this.mBackgroundModifiers.reset(); } // =========================================================== // Methods // =========================================================== // =========================================================== // Inner and Anonymous Classes // =========================================================== }
Java
package org.anddev.andengine.entity.scene.background; /** * (c) 2010 Nicolas Gramlich * (c) 2011 Zynga Inc. * * @author Nicolas Gramlich * @since 19:44:31 - 19.07.2010 */ public class AutoParallaxBackground extends ParallaxBackground { // =========================================================== // Constants // =========================================================== // =========================================================== // Fields // =========================================================== private float mParallaxChangePerSecond; // =========================================================== // Constructors // =========================================================== public AutoParallaxBackground(final float pRed, final float pGreen, final float pBlue, final float pParallaxChangePerSecond) { super(pRed, pGreen, pBlue); this.mParallaxChangePerSecond = pParallaxChangePerSecond; } // =========================================================== // Getter & Setter // =========================================================== public void setParallaxChangePerSecond(final float pParallaxChangePerSecond) { this.mParallaxChangePerSecond = pParallaxChangePerSecond; } // =========================================================== // Methods for/from SuperClass/Interfaces // =========================================================== @Override public void onUpdate(final float pSecondsElapsed) { super.onUpdate(pSecondsElapsed); this.mParallaxValue += this.mParallaxChangePerSecond * pSecondsElapsed; } // =========================================================== // Methods // =========================================================== // =========================================================== // Inner and Anonymous Classes // =========================================================== }
Java
package org.anddev.andengine.entity.scene.background.modifier; import org.anddev.andengine.entity.scene.background.IBackground; import org.anddev.andengine.util.modifier.BaseTripleValueSpanModifier; import org.anddev.andengine.util.modifier.ease.IEaseFunction; /** * (c) 2010 Nicolas Gramlich * (c) 2011 Zynga Inc. * * @author Nicolas Gramlich * @since 14:51:03 - 03.09.2010 */ public class ColorModifier extends BaseTripleValueSpanModifier<IBackground> implements IBackgroundModifier { // =========================================================== // Constants // =========================================================== // =========================================================== // Fields // =========================================================== // =========================================================== // Constructors // =========================================================== public ColorModifier(final float pDuration, final float pFromRed, final float pToRed, final float pFromGreen, final float pToGreen, final float pFromBlue, final float pToBlue) { this(pDuration, pFromRed, pToRed, pFromGreen, pToGreen, pFromBlue, pToBlue, null, IEaseFunction.DEFAULT); } public ColorModifier(final float pDuration, final float pFromRed, final float pToRed, final float pFromGreen, final float pToGreen, final float pFromBlue, final float pToBlue, final IEaseFunction pEaseFunction) { this(pDuration, pFromRed, pToRed, pFromGreen, pToGreen, pFromBlue, pToBlue, null, pEaseFunction); } public ColorModifier(final float pDuration, final float pFromRed, final float pToRed, final float pFromGreen, final float pToGreen, final float pFromBlue, final float pToBlue, final IBackgroundModifierListener pBackgroundModifierListener) { super(pDuration, pFromRed, pToRed, pFromGreen, pToGreen, pFromBlue, pToBlue, pBackgroundModifierListener, IEaseFunction.DEFAULT); } public ColorModifier(final float pDuration, final float pFromRed, final float pToRed, final float pFromGreen, final float pToGreen, final float pFromBlue, final float pToBlue, final IBackgroundModifierListener pBackgroundModifierListener, final IEaseFunction pEaseFunction) { super(pDuration, pFromRed, pToRed, pFromGreen, pToGreen, pFromBlue, pToBlue, pBackgroundModifierListener, pEaseFunction); } protected ColorModifier(final ColorModifier pColorModifier) { super(pColorModifier); } @Override public ColorModifier deepCopy(){ return new ColorModifier(this); } // =========================================================== // Getter & Setter // =========================================================== // =========================================================== // Methods for/from SuperClass/Interfaces // =========================================================== @Override protected void onSetInitialValues(final IBackground pBackground, final float pRed, final float pGreen, final float pBlue) { pBackground.setColor(pRed, pGreen, pBlue); } @Override protected void onSetValues(final IBackground pBackground, final float pPerctentageDone, final float pRed, final float pGreen, final float pBlue) { pBackground.setColor(pRed, pGreen, pBlue); } // =========================================================== // Methods // =========================================================== // =========================================================== // Inner and Anonymous Classes // =========================================================== }
Java
package org.anddev.andengine.entity.scene.background.modifier; import org.anddev.andengine.entity.scene.background.IBackground; import org.anddev.andengine.util.modifier.ParallelModifier; /** * (c) 2010 Nicolas Gramlich * (c) 2011 Zynga Inc. * * @author Nicolas Gramlich * @since 15:03:57 - 03.09.2010 */ public class ParallelBackgroundModifier extends ParallelModifier<IBackground> implements IBackgroundModifier { // =========================================================== // Constants // =========================================================== // =========================================================== // Fields // =========================================================== // =========================================================== // Constructors // =========================================================== public ParallelBackgroundModifier(final IBackgroundModifier... pBackgroundModifiers) throws IllegalArgumentException { super(pBackgroundModifiers); } public ParallelBackgroundModifier(final IBackgroundModifierListener pBackgroundModifierListener, final IBackgroundModifier... pBackgroundModifiers) throws IllegalArgumentException { super(pBackgroundModifierListener, pBackgroundModifiers); } protected ParallelBackgroundModifier(final ParallelBackgroundModifier pParallelBackgroundModifier) throws DeepCopyNotSupportedException { super(pParallelBackgroundModifier); } @Override public ParallelBackgroundModifier deepCopy() throws DeepCopyNotSupportedException { return new ParallelBackgroundModifier(this); } // =========================================================== // Getter & Setter // =========================================================== // =========================================================== // Methods for/from SuperClass/Interfaces // =========================================================== // =========================================================== // Methods // =========================================================== // =========================================================== // Inner and Anonymous Classes // =========================================================== }
Java
package org.anddev.andengine.entity.scene.background.modifier; import org.anddev.andengine.entity.scene.background.IBackground; import org.anddev.andengine.util.modifier.IModifier; /** * (c) 2010 Nicolas Gramlich * (c) 2011 Zynga Inc. * * @author Nicolas Gramlich * @since 14:55:54 - 03.09.2010 */ public interface IBackgroundModifier extends IModifier<IBackground> { // =========================================================== // Final Fields // =========================================================== // =========================================================== // Methods // =========================================================== @Override public IBackgroundModifier deepCopy() throws DeepCopyNotSupportedException; // =========================================================== // Inner and Anonymous Classes // =========================================================== public static interface IBackgroundModifierListener extends IModifierListener<IBackground>{ // =========================================================== // Final Fields // =========================================================== // =========================================================== // Methods // =========================================================== } }
Java
package org.anddev.andengine.entity.scene.background.modifier; import org.anddev.andengine.entity.scene.background.IBackground; import org.anddev.andengine.util.modifier.LoopModifier; /** * (c) 2010 Nicolas Gramlich * (c) 2011 Zynga Inc. * * @author Nicolas Gramlich * @since 15:03:53 - 03.09.2010 */ public class LoopBackgroundModifier extends LoopModifier<IBackground> implements IBackgroundModifier { // =========================================================== // Constants // =========================================================== // =========================================================== // Fields // =========================================================== // =========================================================== // Constructors // =========================================================== public LoopBackgroundModifier(final IBackgroundModifier pBackgroundModifier) { super(pBackgroundModifier); } public LoopBackgroundModifier(final IBackgroundModifier pBackgroundModifier, final int pLoopCount) { super(pBackgroundModifier, pLoopCount); } public LoopBackgroundModifier(final IBackgroundModifier pBackgroundModifier, final int pLoopCount, final ILoopBackgroundModifierListener pLoopModifierListener) { super(pBackgroundModifier, pLoopCount, pLoopModifierListener, (IBackgroundModifierListener)null); } public LoopBackgroundModifier(final IBackgroundModifier pBackgroundModifier, final int pLoopCount, final IBackgroundModifierListener pBackgroundModifierListener) { super(pBackgroundModifier, pLoopCount, pBackgroundModifierListener); } public LoopBackgroundModifier(final IBackgroundModifier pBackgroundModifier, final int pLoopCount, final ILoopBackgroundModifierListener pLoopModifierListener, final IBackgroundModifierListener pBackgroundModifierListener) { super(pBackgroundModifier, pLoopCount, pLoopModifierListener, pBackgroundModifierListener); } protected LoopBackgroundModifier(final LoopBackgroundModifier pLoopBackgroundModifier) throws DeepCopyNotSupportedException { super(pLoopBackgroundModifier); } @Override public LoopBackgroundModifier deepCopy() throws DeepCopyNotSupportedException { return new LoopBackgroundModifier(this); } // =========================================================== // Getter & Setter // =========================================================== // =========================================================== // Methods for/from SuperClass/Interfaces // =========================================================== // =========================================================== // Methods // =========================================================== // =========================================================== // Inner and Anonymous Classes // =========================================================== public interface ILoopBackgroundModifierListener extends ILoopModifierListener<IBackground> { // =========================================================== // Final Fields // =========================================================== // =========================================================== // Methods // =========================================================== } }
Java
package org.anddev.andengine.entity.scene.background.modifier; import org.anddev.andengine.entity.scene.background.IBackground; import org.anddev.andengine.util.modifier.SequenceModifier; /** * (c) 2010 Nicolas Gramlich * (c) 2011 Zynga Inc. * * @author Nicolas Gramlich * @since 15:04:02 - 03.09.2010 */ public class SequenceBackgroundModifier extends SequenceModifier<IBackground> implements IBackgroundModifier { // =========================================================== // Constants // =========================================================== // =========================================================== // Fields // =========================================================== // =========================================================== // Constructors // =========================================================== public SequenceBackgroundModifier(final IBackgroundModifier... pBackgroundModifiers) throws IllegalArgumentException { super(pBackgroundModifiers); } public SequenceBackgroundModifier(final ISubSequenceBackgroundModifierListener pSubSequenceBackgroundModifierListener, final IBackgroundModifier... pBackgroundModifiers) throws IllegalArgumentException { super(pSubSequenceBackgroundModifierListener, pBackgroundModifiers); } public SequenceBackgroundModifier(final IBackgroundModifierListener pBackgroundModifierListener, final IBackgroundModifier... pBackgroundModifiers) throws IllegalArgumentException { super(pBackgroundModifierListener, pBackgroundModifiers); } public SequenceBackgroundModifier(final ISubSequenceBackgroundModifierListener pSubSequenceBackgroundModifierListener, final IBackgroundModifierListener pBackgroundModifierListener, final IBackgroundModifier... pBackgroundModifiers) throws IllegalArgumentException { super(pSubSequenceBackgroundModifierListener, pBackgroundModifierListener, pBackgroundModifiers); } protected SequenceBackgroundModifier(final SequenceBackgroundModifier pSequenceBackgroundModifier) throws DeepCopyNotSupportedException { super(pSequenceBackgroundModifier); } @Override public SequenceBackgroundModifier deepCopy() throws DeepCopyNotSupportedException { return new SequenceBackgroundModifier(this); } // =========================================================== // Getter & Setter // =========================================================== // =========================================================== // Methods for/from SuperClass/Interfaces // =========================================================== // =========================================================== // Methods // =========================================================== // =========================================================== // Inner and Anonymous Classes // =========================================================== public interface ISubSequenceBackgroundModifierListener extends ISubSequenceModifierListener<IBackground> { // =========================================================== // Final Fields // =========================================================== // =========================================================== // Methods // =========================================================== } }
Java
package org.anddev.andengine.entity.scene.background; import org.anddev.andengine.entity.sprite.Sprite; import org.anddev.andengine.opengl.texture.TextureManager; import org.anddev.andengine.opengl.texture.TextureOptions; import org.anddev.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlas; import org.anddev.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlasTextureRegionFactory; import org.anddev.andengine.opengl.texture.atlas.bitmap.source.IBitmapTextureAtlasSource; import org.anddev.andengine.opengl.texture.bitmap.BitmapTexture.BitmapTextureFormat; import org.anddev.andengine.opengl.texture.region.TextureRegion; /** * (c) 2010 Nicolas Gramlich * (c) 2011 Zynga Inc. * * @author Nicolas Gramlich * @since 15:11:10 - 19.07.2010 */ public class RepeatingSpriteBackground extends SpriteBackground { // =========================================================== // Constants // =========================================================== // =========================================================== // Fields // =========================================================== private BitmapTextureAtlas mBitmapTextureAtlas; private final float mScale; // =========================================================== // Constructors // =========================================================== /** * @param pCameraWidth * @param pCameraHeight * @param pTextureManager * @param pBitmapTextureAtlasSource needs to be a power of two as otherwise the <code>repeating</code> feature doesn't work. */ public RepeatingSpriteBackground(final float pCameraWidth, final float pCameraHeight, final TextureManager pTextureManager, final IBitmapTextureAtlasSource pBitmapTextureAtlasSource) throws IllegalArgumentException { this(pCameraWidth, pCameraHeight, pTextureManager, pBitmapTextureAtlasSource, 1); } public RepeatingSpriteBackground(final float pCameraWidth, final float pCameraHeight, final TextureManager pTextureManager, final IBitmapTextureAtlasSource pBitmapTextureAtlasSource, final float pScale) throws IllegalArgumentException { super(null); this.mScale = pScale; this.mEntity = this.loadSprite(pCameraWidth, pCameraHeight, pTextureManager, pBitmapTextureAtlasSource); } // =========================================================== // Getter & Setter // =========================================================== public BitmapTextureAtlas getBitmapTextureAtlas() { return this.mBitmapTextureAtlas; } // =========================================================== // Methods for/from SuperClass/Interfaces // =========================================================== // =========================================================== // Methods // =========================================================== private Sprite loadSprite(final float pCameraWidth, final float pCameraHeight, final TextureManager pTextureManager, final IBitmapTextureAtlasSource pBitmapTextureAtlasSource) throws IllegalArgumentException { this.mBitmapTextureAtlas = new BitmapTextureAtlas(pBitmapTextureAtlasSource.getWidth(), pBitmapTextureAtlasSource.getHeight(), BitmapTextureFormat.RGBA_8888, TextureOptions.REPEATING_NEAREST_PREMULTIPLYALPHA); final TextureRegion textureRegion = BitmapTextureAtlasTextureRegionFactory.createFromSource(this.mBitmapTextureAtlas, pBitmapTextureAtlasSource, 0, 0); final int width = Math.round(pCameraWidth / this.mScale); final int height = Math.round(pCameraHeight / this.mScale); textureRegion.setWidth(width); textureRegion.setHeight(height); pTextureManager.loadTexture(this.mBitmapTextureAtlas); final Sprite sprite = new Sprite(0, 0, width, height, textureRegion); sprite.setScaleCenter(0, 0); sprite.setScale(this.mScale); return sprite; } // =========================================================== // Inner and Anonymous Classes // =========================================================== }
Java
package org.anddev.andengine.entity.scene.background; import org.anddev.andengine.entity.sprite.BaseSprite; /** * (c) 2010 Nicolas Gramlich * (c) 2011 Zynga Inc. * * @author Nicolas Gramlich * @since 14:01:43 - 19.07.2010 */ public class SpriteBackground extends EntityBackground { // =========================================================== // Constants // =========================================================== // =========================================================== // Fields // =========================================================== // =========================================================== // Constructors // =========================================================== public SpriteBackground(final BaseSprite pBaseSprite) { super(pBaseSprite); } public SpriteBackground(final float pRed, final float pGreen, final float pBlue, final BaseSprite pBaseSprite) { super(pRed, pGreen, pBlue, pBaseSprite); } // =========================================================== // Getter & Setter // =========================================================== // =========================================================== // Methods for/from SuperClass/Interfaces // =========================================================== // =========================================================== // Methods // =========================================================== // =========================================================== // Inner and Anonymous Classes // =========================================================== }
Java
package org.anddev.andengine.entity.scene.background; import java.util.ArrayList; import javax.microedition.khronos.opengles.GL10; import org.anddev.andengine.engine.camera.Camera; import org.anddev.andengine.entity.shape.Shape; /** * (c) 2010 Nicolas Gramlich * (c) 2011 Zynga Inc. * * @author Nicolas Gramlich * @since 15:36:26 - 19.07.2010 */ public class ParallaxBackground extends ColorBackground { // =========================================================== // Constants // =========================================================== // =========================================================== // Fields // =========================================================== private final ArrayList<ParallaxEntity> mParallaxEntities = new ArrayList<ParallaxEntity>(); private int mParallaxEntityCount; protected float mParallaxValue; // =========================================================== // Constructors // =========================================================== public ParallaxBackground(final float pRed, final float pGreen, final float pBlue) { super(pRed, pGreen, pBlue); } // =========================================================== // Getter & Setter // =========================================================== public void setParallaxValue(final float pParallaxValue) { this.mParallaxValue = pParallaxValue; } // =========================================================== // Methods for/from SuperClass/Interfaces // =========================================================== @Override public void onDraw(final GL10 pGL, final Camera pCamera) { super.onDraw(pGL, pCamera); final float parallaxValue = this.mParallaxValue; final ArrayList<ParallaxEntity> parallaxEntities = this.mParallaxEntities; for(int i = 0; i < this.mParallaxEntityCount; i++) { parallaxEntities.get(i).onDraw(pGL, parallaxValue, pCamera); } } // =========================================================== // Methods // =========================================================== public void attachParallaxEntity(final ParallaxEntity pParallaxEntity) { this.mParallaxEntities.add(pParallaxEntity); this.mParallaxEntityCount++; } public boolean detachParallaxEntity(final ParallaxEntity pParallaxEntity) { this.mParallaxEntityCount--; final boolean success = this.mParallaxEntities.remove(pParallaxEntity); if(!success) { this.mParallaxEntityCount++; } return success; } // =========================================================== // Inner and Anonymous Classes // =========================================================== public static class ParallaxEntity { // =========================================================== // Constants // =========================================================== // =========================================================== // Fields // =========================================================== final float mParallaxFactor; final Shape mShape; // =========================================================== // Constructors // =========================================================== public ParallaxEntity(final float pParallaxFactor, final Shape pShape) { this.mParallaxFactor = pParallaxFactor; this.mShape = pShape; } // =========================================================== // Getter & Setter // =========================================================== // =========================================================== // Methods for/from SuperClass/Interfaces // =========================================================== // =========================================================== // Methods // =========================================================== public void onDraw(final GL10 pGL, final float pParallaxValue, final Camera pCamera) { pGL.glPushMatrix(); { final float cameraWidth = pCamera.getWidth(); final float shapeWidthScaled = this.mShape.getWidthScaled(); float baseOffset = (pParallaxValue * this.mParallaxFactor) % shapeWidthScaled; while(baseOffset > 0) { baseOffset -= shapeWidthScaled; } pGL.glTranslatef(baseOffset, 0, 0); float currentMaxX = baseOffset; do { this.mShape.onDraw(pGL, pCamera); pGL.glTranslatef(shapeWidthScaled, 0, 0); currentMaxX += shapeWidthScaled; } while(currentMaxX < cameraWidth); } pGL.glPopMatrix(); } // =========================================================== // Inner and Anonymous Classes // =========================================================== } }
Java
package org.anddev.andengine.entity.scene.background; import javax.microedition.khronos.opengles.GL10; import org.anddev.andengine.engine.camera.Camera; import org.anddev.andengine.entity.IEntity; /** * (c) 2010 Nicolas Gramlich * (c) 2011 Zynga Inc. * * @author Nicolas Gramlich * @since 18:25:10 - 21.07.2010 */ public class EntityBackground extends ColorBackground { // =========================================================== // Constants // =========================================================== // =========================================================== // Fields // =========================================================== protected IEntity mEntity; // =========================================================== // Constructors // =========================================================== public EntityBackground(final IEntity pEntity) { this.mEntity = pEntity; } public EntityBackground(final float pRed, final float pGreen, final float pBlue, final IEntity pEntity) { super(pRed, pGreen, pBlue); this.mEntity = pEntity; } // =========================================================== // Getter & Setter // =========================================================== // =========================================================== // Methods for/from SuperClass/Interfaces // =========================================================== @Override public void onDraw(final GL10 pGL, final Camera pCamera) { super.onDraw(pGL, pCamera); this.mEntity.onDraw(pGL, pCamera); } // =========================================================== // Methods // =========================================================== // =========================================================== // Inner and Anonymous Classes // =========================================================== }
Java
package org.anddev.andengine.entity.primitive; import javax.microedition.khronos.opengles.GL10; import javax.microedition.khronos.opengles.GL11; import org.anddev.andengine.collision.LineCollisionChecker; import org.anddev.andengine.collision.RectangularShapeCollisionChecker; import org.anddev.andengine.engine.camera.Camera; import org.anddev.andengine.entity.shape.IShape; import org.anddev.andengine.entity.shape.RectangularShape; import org.anddev.andengine.entity.shape.Shape; import org.anddev.andengine.opengl.util.GLHelper; import org.anddev.andengine.opengl.vertex.LineVertexBuffer; /** * (c) 2010 Nicolas Gramlich * (c) 2011 Zynga Inc. * * @author Nicolas Gramlich * @since 09:50:36 - 04.04.2010 */ public class Line extends Shape { // =========================================================== // Constants // =========================================================== private static final float LINEWIDTH_DEFAULT = 1.0f; // =========================================================== // Fields // =========================================================== protected float mX2; protected float mY2; private float mLineWidth; private final LineVertexBuffer mLineVertexBuffer; // =========================================================== // Constructors // =========================================================== public Line(final float pX1, final float pY1, final float pX2, final float pY2) { this(pX1, pY1, pX2, pY2, LINEWIDTH_DEFAULT); } public Line(final float pX1, final float pY1, final float pX2, final float pY2, final float pLineWidth) { super(pX1, pY1); this.mX2 = pX2; this.mY2 = pY2; this.mLineWidth = pLineWidth; this.mLineVertexBuffer = new LineVertexBuffer(GL11.GL_STATIC_DRAW, true); this.updateVertexBuffer(); final float width = this.getWidth(); final float height = this.getHeight(); this.mRotationCenterX = width * 0.5f; this.mRotationCenterY = height * 0.5f; this.mScaleCenterX = this.mRotationCenterX; this.mScaleCenterY = this.mRotationCenterY; } // =========================================================== // Getter & Setter // =========================================================== /** * @deprecated Instead use {@link Line#getX1()} or {@link Line#getX2()}. */ @Deprecated @Override public float getX() { return super.getX(); } /** * @deprecatedInstead use {@link Line#getY1()} or {@link Line#getY2()}. */ @Deprecated @Override public float getY() { return super.getY(); } public float getX1() { return super.getX(); } public float getY1() { return super.getY(); } public float getX2() { return this.mX2; } public float getY2() { return this.mY2; } public float getLineWidth() { return this.mLineWidth; } public void setLineWidth(final float pLineWidth) { this.mLineWidth = pLineWidth; } @Override public float getBaseHeight() { return this.mY2 - this.mY; } @Override public float getBaseWidth() { return this.mX2 - this.mX; } @Override public float getHeight() { return this.mY2 - this.mY; } @Override public float getWidth() { return this.mX2 - this.mX; } /** * @deprecated Instead use {@link Line#setPosition(float, float, float, float)}. */ @Deprecated @Override public void setPosition(final float pX, final float pY) { final float dX = this.mX - pX; final float dY = this.mY - pY; super.setPosition(pX, pY); this.mX2 += dX; this.mY2 += dY; } public void setPosition(final float pX1, final float pY1, final float pX2, final float pY2) { this.mX2 = pX2; this.mY2 = pY2; super.setPosition(pX1, pY1); this.updateVertexBuffer(); } // =========================================================== // Methods for/from SuperClass/Interfaces // =========================================================== @Override protected boolean isCulled(final Camera pCamera) { return pCamera.isLineVisible(this); } @Override protected void onInitDraw(final GL10 pGL) { super.onInitDraw(pGL); GLHelper.disableTextures(pGL); GLHelper.disableTexCoordArray(pGL); GLHelper.lineWidth(pGL, this.mLineWidth); } @Override public LineVertexBuffer getVertexBuffer() { return this.mLineVertexBuffer; } @Override protected void onUpdateVertexBuffer() { this.mLineVertexBuffer.update(0, 0, this.mX2 - this.mX, this.mY2 - this.mY); } @Override protected void drawVertices(final GL10 pGL, final Camera pCamera) { pGL.glDrawArrays(GL10.GL_LINES, 0, LineVertexBuffer.VERTICES_PER_LINE); } @Override public float[] getSceneCenterCoordinates() { return null; // TODO // return convertLocalToSceneCoordinates(this, (this.mX + this.mX2) * 0.5f, (this.mY + this.mY2) * 0.5f); } @Override @Deprecated public boolean contains(final float pX, final float pY) { return false; } @Override @Deprecated public float[] convertSceneToLocalCoordinates(final float pX, final float pY) { return null; } @Override @Deprecated public float[] convertLocalToSceneCoordinates(final float pX, final float pY) { return null; } @Override public boolean collidesWith(final IShape pOtherShape) { if(pOtherShape instanceof Line) { final Line otherLine = (Line) pOtherShape; return LineCollisionChecker.checkLineCollision(this.mX, this.mY, this.mX2, this.mY2, otherLine.mX, otherLine.mY, otherLine.mX2, otherLine.mY2); } else if(pOtherShape instanceof RectangularShape) { final RectangularShape rectangularShape = (RectangularShape) pOtherShape; return RectangularShapeCollisionChecker.checkCollision(rectangularShape, this); } else { return false; } } // =========================================================== // Methods // =========================================================== // =========================================================== // Inner and Anonymous Classes // =========================================================== }
Java
package org.anddev.andengine.entity.primitive; import javax.microedition.khronos.opengles.GL11; import org.anddev.andengine.entity.shape.RectangularShape; import org.anddev.andengine.opengl.vertex.RectangleVertexBuffer; /** * (c) 2010 Nicolas Gramlich * (c) 2011 Zynga Inc. * * @author Nicolas Gramlich * @since 19:05:49 - 11.04.2010 */ public abstract class BaseRectangle extends RectangularShape { // =========================================================== // Constants // =========================================================== // =========================================================== // Fields // =========================================================== // =========================================================== // Constructors // =========================================================== public BaseRectangle(final float pX, final float pY, final float pWidth, final float pHeight) { super(pX, pY, pWidth, pHeight, new RectangleVertexBuffer(GL11.GL_STATIC_DRAW, true)); this.updateVertexBuffer(); } public BaseRectangle(final float pX, final float pY, final float pWidth, final float pHeight, final RectangleVertexBuffer pRectangleVertexBuffer) { super(pX, pY, pWidth, pHeight, pRectangleVertexBuffer); } // =========================================================== // Getter & Setter // =========================================================== // =========================================================== // Methods for/from SuperClass/Interfaces // =========================================================== @Override public RectangleVertexBuffer getVertexBuffer() { return (RectangleVertexBuffer)this.mVertexBuffer; } @Override protected void onUpdateVertexBuffer(){ this.getVertexBuffer().update(this.mWidth, this.mHeight); } // =========================================================== // Methods // =========================================================== // =========================================================== // Inner and Anonymous Classes // =========================================================== }
Java
package org.anddev.andengine.entity.primitive; import javax.microedition.khronos.opengles.GL10; import org.anddev.andengine.opengl.util.GLHelper; import org.anddev.andengine.opengl.vertex.RectangleVertexBuffer; /** * (c) 2010 Nicolas Gramlich * (c) 2011 Zynga Inc. * * @author Nicolas Gramlich * @since 12:18:49 - 13.03.2010 */ public class Rectangle extends BaseRectangle { // =========================================================== // Constants // =========================================================== // =========================================================== // Fields // =========================================================== // =========================================================== // Constructors // =========================================================== public Rectangle(final float pX, final float pY, final float pWidth, final float pHeight) { super(pX, pY, pWidth, pHeight); } public Rectangle(final float pX, final float pY, final float pWidth, final float pHeight, final RectangleVertexBuffer pRectangleVertexBuffer) { super(pX, pY, pWidth, pHeight, pRectangleVertexBuffer); } // =========================================================== // Getter & Setter // =========================================================== // =========================================================== // Methods for/from SuperClass/Interfaces // =========================================================== @Override protected void onInitDraw(final GL10 pGL) { super.onInitDraw(pGL); GLHelper.disableTextures(pGL); GLHelper.disableTexCoordArray(pGL); } // =========================================================== // Methods // =========================================================== // =========================================================== // Inner and Anonymous Classes // =========================================================== }
Java
package org.anddev.andengine.entity.modifier; import org.anddev.andengine.entity.IEntity; import org.anddev.andengine.util.modifier.ease.IEaseFunction; /** * (c) 2010 Nicolas Gramlich * (c) 2011 Zynga Inc. * * @author Nicolas Gramlich * @since 23:24:26 - 16.07.2011 */ public class QuadraticBezierMoveModifier extends DurationEntityModifier { // =========================================================== // Constants // =========================================================== // =========================================================== // Fields // =========================================================== private final float mX1; private final float mY1; private final float mX2; private final float mY2; private final float mX3; private final float mY3; private final IEaseFunction mEaseFunction; // =========================================================== // Constructors // =========================================================== public QuadraticBezierMoveModifier(final float pDuration, final float pX1, final float pY1, final float pX2, final float pY2, final float pX3, final float pY3, final IEaseFunction pEaseFunction) { super(pDuration); this.mX1 = pX1; this.mY1 = pY1; this.mX2 = pX2; this.mY2 = pY2; this.mX3 = pX3; this.mY3 = pY3; this.mEaseFunction = pEaseFunction; } @Override public QuadraticBezierMoveModifier deepCopy() { return new QuadraticBezierMoveModifier(this.mDuration, this.mX1, this.mY1, this.mX2, this.mY2, this.mX3, this.mY3, this.mEaseFunction); } // =========================================================== // Getter & Setter // =========================================================== // =========================================================== // Methods for/from SuperClass/Interfaces // =========================================================== @Override protected void onManagedUpdate(final float pSecondsElapsed, final IEntity pEntity) { final float percentageDone = this.mEaseFunction.getPercentage(this.getSecondsElapsed(), this.mDuration); final float u = 1 - percentageDone; final float tt = percentageDone*percentageDone; final float uu = u*u; final float ut2 = 2 * u * percentageDone; /* Formula: * ((1-t)^2 * p1) + (2*(t)*(1-t) * p2) + ((t^2) * p3) */ final float x = (uu * this.mX1) + (ut2 * this.mX2) + (tt * this.mX3); final float y = (uu * this.mY1) + (ut2 * this.mY2) + (tt * this.mY3); pEntity.setPosition(x, y); } @Override protected void onManagedInitialize(final IEntity pEntity) { } // =========================================================== // Methods // =========================================================== // =========================================================== // Inner and Anonymous Classes // =========================================================== }
Java
package org.anddev.andengine.entity.modifier; import org.anddev.andengine.entity.IEntity; import org.anddev.andengine.util.modifier.ease.IEaseFunction; /** * (c) 2010 Nicolas Gramlich * (c) 2011 Zynga Inc. * * @author Nicolas Gramlich * @since 12:04:21 - 30.08.2010 */ public class MoveYModifier extends SingleValueSpanEntityModifier { // =========================================================== // Constants // =========================================================== // =========================================================== // Fields // =========================================================== // =========================================================== // Constructors // =========================================================== public MoveYModifier(final float pDuration, final float pFromY, final float pToY) { this(pDuration, pFromY, pToY, null, IEaseFunction.DEFAULT); } public MoveYModifier(final float pDuration, final float pFromY, final float pToY, final IEaseFunction pEaseFunction) { this(pDuration, pFromY, pToY, null, pEaseFunction); } public MoveYModifier(final float pDuration, final float pFromY, final float pToY, final IEntityModifierListener pEntityModifierListener) { super(pDuration, pFromY, pToY, pEntityModifierListener, IEaseFunction.DEFAULT); } public MoveYModifier(final float pDuration, final float pFromY, final float pToY, final IEntityModifierListener pEntityModifierListener, final IEaseFunction pEaseFunction) { super(pDuration, pFromY, pToY, pEntityModifierListener, pEaseFunction); } protected MoveYModifier(final MoveYModifier pMoveYModifier) { super(pMoveYModifier); } @Override public MoveYModifier deepCopy(){ return new MoveYModifier(this); } // =========================================================== // Getter & Setter // =========================================================== // =========================================================== // Methods for/from SuperClass/Interfaces // =========================================================== @Override protected void onSetInitialValue(final IEntity pEntity, final float pY) { pEntity.setPosition(pEntity.getX(), pY); } @Override protected void onSetValue(final IEntity pEntity, final float pPercentageDone, final float pY) { pEntity.setPosition(pEntity.getX(), pY); } // =========================================================== // Methods // =========================================================== // =========================================================== // Inner and Anonymous Classes // =========================================================== }
Java
package org.anddev.andengine.entity.modifier; import org.anddev.andengine.entity.IEntity; /** * (c) 2011 Zynga Inc. * * @author Nicolas Gramlich * @since 14:15:52 - 10.08.2011 */ public class MoveByModifier extends DoubleValueChangeEntityModifier { // =========================================================== // Constants // =========================================================== // =========================================================== // Fields // =========================================================== // =========================================================== // Constructors // =========================================================== public MoveByModifier(final float pDuration, final float pX, final float pY) { super(pDuration, pX, pY); } public MoveByModifier(final float pDuration, final float pX, final float pY, final IEntityModifierListener pEntityModifierListener) { super(pDuration, pX, pY, pEntityModifierListener); } protected MoveByModifier(final DoubleValueChangeEntityModifier pDoubleValueChangeEntityModifier) { super(pDoubleValueChangeEntityModifier); } @Override public MoveByModifier deepCopy(){ return new MoveByModifier(this); } // =========================================================== // Getter & Setter // =========================================================== // =========================================================== // Methods for/from SuperClass/Interfaces // =========================================================== @Override protected void onChangeValues(final float pSecondsElapsed, final IEntity pEntity, final float pX, final float pY) { pEntity.setPosition(pEntity.getX() + pX, pEntity.getY() + pY); } // =========================================================== // Methods // =========================================================== // =========================================================== // Inner and Anonymous Classes // =========================================================== }
Java
package org.anddev.andengine.entity.modifier; import org.anddev.andengine.entity.IEntity; import org.anddev.andengine.util.modifier.ease.IEaseFunction; /** * (c) 2010 Nicolas Gramlich * (c) 2011 Zynga Inc. * * @author Nicolas Gramlich * @since 15:39:50 - 29.06.2010 */ public class ColorModifier extends TripleValueSpanEntityModifier { // =========================================================== // Constants // =========================================================== // =========================================================== // Fields // =========================================================== // =========================================================== // Constructors // =========================================================== public ColorModifier(final float pDuration, final float pFromRed, final float pToRed, final float pFromGreen, final float pToGreen, final float pFromBlue, final float pToBlue) { this(pDuration, pFromRed, pToRed, pFromGreen, pToGreen, pFromBlue, pToBlue, null, IEaseFunction.DEFAULT); } public ColorModifier(final float pDuration, final float pFromRed, final float pToRed, final float pFromGreen, final float pToGreen, final float pFromBlue, final float pToBlue, final IEaseFunction pEaseFunction) { this(pDuration, pFromRed, pToRed, pFromGreen, pToGreen, pFromBlue, pToBlue, null, pEaseFunction); } public ColorModifier(final float pDuration, final float pFromRed, final float pToRed, final float pFromGreen, final float pToGreen, final float pFromBlue, final float pToBlue, final IEntityModifierListener pEntityModifierListener) { super(pDuration, pFromRed, pToRed, pFromGreen, pToGreen, pFromBlue, pToBlue, pEntityModifierListener, IEaseFunction.DEFAULT); } public ColorModifier(final float pDuration, final float pFromRed, final float pToRed, final float pFromGreen, final float pToGreen, final float pFromBlue, final float pToBlue, final IEntityModifierListener pEntityModifierListener, final IEaseFunction pEaseFunction) { super(pDuration, pFromRed, pToRed, pFromGreen, pToGreen, pFromBlue, pToBlue, pEntityModifierListener, pEaseFunction); } protected ColorModifier(final ColorModifier pColorModifier) { super(pColorModifier); } @Override public ColorModifier deepCopy(){ return new ColorModifier(this); } // =========================================================== // Getter & Setter // =========================================================== // =========================================================== // Methods for/from SuperClass/Interfaces // =========================================================== @Override protected void onSetInitialValues(final IEntity pEntity, final float pRed, final float pGreen, final float pBlue) { pEntity.setColor(pRed, pGreen, pBlue); } @Override protected void onSetValues(final IEntity pEntity, final float pPerctentageDone, final float pRed, final float pGreen, final float pBlue) { pEntity.setColor(pRed, pGreen, pBlue); } // =========================================================== // Methods // =========================================================== // =========================================================== // Inner and Anonymous Classes // =========================================================== }
Java
package org.anddev.andengine.entity.modifier; import org.anddev.andengine.entity.IEntity; import org.anddev.andengine.util.IMatcher; import org.anddev.andengine.util.modifier.IModifier; /** * (c) 2010 Nicolas Gramlich * (c) 2011 Zynga Inc. * * @author Nicolas Gramlich * @since 11:17:50 - 19.03.2010 */ public interface IEntityModifier extends IModifier<IEntity> { // =========================================================== // Final Fields // =========================================================== // =========================================================== // Methods // =========================================================== @Override public IEntityModifier deepCopy() throws DeepCopyNotSupportedException; // =========================================================== // Inner and Anonymous Classes // =========================================================== public static interface IEntityModifierListener extends IModifierListener<IEntity>{ // =========================================================== // Final Fields // =========================================================== // =========================================================== // Methods // =========================================================== } public interface IEntityModifierMatcher extends IMatcher<IModifier<IEntity>> { // =========================================================== // Constants // =========================================================== // =========================================================== // Methods // =========================================================== } }
Java
package org.anddev.andengine.entity.modifier; import org.anddev.andengine.entity.IEntity; import org.anddev.andengine.util.modifier.ease.IEaseFunction; /** * (c) 2010 Nicolas Gramlich * (c) 2011 Zynga Inc. * * @author Nicolas Gramlich * @since 23:37:53 - 19.03.2010 */ public class ScaleModifier extends DoubleValueSpanEntityModifier { // =========================================================== // Constants // =========================================================== // =========================================================== // Fields // =========================================================== // =========================================================== // Constructors // =========================================================== public ScaleModifier(final float pDuration, final float pFromScale, final float pToScale) { this(pDuration, pFromScale, pToScale, null, IEaseFunction.DEFAULT); } public ScaleModifier(final float pDuration, final float pFromScale, final float pToScale, final IEaseFunction pEaseFunction) { this(pDuration, pFromScale, pToScale, null, pEaseFunction); } public ScaleModifier(final float pDuration, final float pFromScale, final float pToScale, final IEntityModifierListener pEntityModifierListener) { this(pDuration, pFromScale, pToScale, pFromScale, pToScale, pEntityModifierListener, IEaseFunction.DEFAULT); } public ScaleModifier(final float pDuration, final float pFromScale, final float pToScale, final IEntityModifierListener pEntityModifierListener, final IEaseFunction pEaseFunction) { this(pDuration, pFromScale, pToScale, pFromScale, pToScale, pEntityModifierListener, pEaseFunction); } public ScaleModifier(final float pDuration, final float pFromScaleX, final float pToScaleX, final float pFromScaleY, final float pToScaleY) { this(pDuration, pFromScaleX, pToScaleX, pFromScaleY, pToScaleY, null, IEaseFunction.DEFAULT); } public ScaleModifier(final float pDuration, final float pFromScaleX, final float pToScaleX, final float pFromScaleY, final float pToScaleY, final IEaseFunction pEaseFunction) { this(pDuration, pFromScaleX, pToScaleX, pFromScaleY, pToScaleY, null, pEaseFunction); } public ScaleModifier(final float pDuration, final float pFromScaleX, final float pToScaleX, final float pFromScaleY, final float pToScaleY, final IEntityModifierListener pEntityModifierListener) { super(pDuration, pFromScaleX, pToScaleX, pFromScaleY, pToScaleY, pEntityModifierListener, IEaseFunction.DEFAULT); } public ScaleModifier(final float pDuration, final float pFromScaleX, final float pToScaleX, final float pFromScaleY, final float pToScaleY, final IEntityModifierListener pEntityModifierListener, final IEaseFunction pEaseFunction) { super(pDuration, pFromScaleX, pToScaleX, pFromScaleY, pToScaleY, pEntityModifierListener, pEaseFunction); } protected ScaleModifier(final ScaleModifier pScaleModifier) { super(pScaleModifier); } @Override public ScaleModifier deepCopy(){ return new ScaleModifier(this); } // =========================================================== // Getter & Setter // =========================================================== // =========================================================== // Methods for/from SuperClass/Interfaces // =========================================================== @Override protected void onSetInitialValues(final IEntity pEntity, final float pScaleA, final float pScaleB) { pEntity.setScale(pScaleA, pScaleB); } @Override protected void onSetValues(final IEntity pEntity, final float pPercentageDone, final float pScaleA, final float pScaleB) { pEntity.setScale(pScaleA, pScaleB); } // =========================================================== // Methods // =========================================================== // =========================================================== // Inner and Anonymous Classes // =========================================================== }
Java
package org.anddev.andengine.entity.modifier; import org.anddev.andengine.entity.IEntity; import org.anddev.andengine.util.modifier.ease.IEaseFunction; /** * (c) 2010 Nicolas Gramlich * (c) 2011 Zynga Inc. * * @author Nicolas Gramlich * @since 16:12:52 - 19.03.2010 */ public class RotationModifier extends SingleValueSpanEntityModifier { // =========================================================== // Constants // =========================================================== // =========================================================== // Fields // =========================================================== // =========================================================== // Constructors // =========================================================== public RotationModifier(final float pDuration, final float pFromRotation, final float pToRotation) { this(pDuration, pFromRotation, pToRotation, null, IEaseFunction.DEFAULT); } public RotationModifier(final float pDuration, final float pFromRotation, final float pToRotation, final IEaseFunction pEaseFunction) { this(pDuration, pFromRotation, pToRotation, null, pEaseFunction); } public RotationModifier(final float pDuration, final float pFromRotation, final float pToRotation, final IEntityModifierListener pEntityModifierListener) { super(pDuration, pFromRotation, pToRotation, pEntityModifierListener, IEaseFunction.DEFAULT); } public RotationModifier(final float pDuration, final float pFromRotation, final float pToRotation, final IEntityModifierListener pEntityModifierListener, final IEaseFunction pEaseFunction) { super(pDuration, pFromRotation, pToRotation, pEntityModifierListener, pEaseFunction); } protected RotationModifier(final RotationModifier pRotationModifier) { super(pRotationModifier); } @Override public RotationModifier deepCopy(){ return new RotationModifier(this); } // =========================================================== // Getter & Setter // =========================================================== // =========================================================== // Methods for/from SuperClass/Interfaces // =========================================================== @Override protected void onSetInitialValue(final IEntity pEntity, final float pRotation) { pEntity.setRotation(pRotation); } @Override protected void onSetValue(final IEntity pEntity, final float pPercentageDone, final float pRotation) { pEntity.setRotation(pRotation); } // =========================================================== // Methods // =========================================================== // =========================================================== // Inner and Anonymous Classes // =========================================================== }
Java
package org.anddev.andengine.entity.modifier; import org.anddev.andengine.entity.IEntity; import org.anddev.andengine.entity.modifier.CubicBezierMoveModifier; import org.anddev.andengine.util.MathUtils; import org.anddev.andengine.util.modifier.ease.IEaseFunction; /** * <p>A {@link CubicBezierMoveModifier} that rotates the entity so it faces the direction of travel.</p> * * <p>(c) 2010 Nicolas Gramlich<br> * (c) 2011 Zynga Inc.</p> * * @author Scott Kennedy * @author Pawel Plewa * @author Nicolas Gramlich * @since 12:54:00 - 17.08.2011 */ public class RotateCubicBezierMoveModifier extends CubicBezierMoveModifier { public RotateCubicBezierMoveModifier(final float pDuration, final float pX1, final float pY1, final float pX2, final float pY2, final float pX3, final float pY3, final float pX4, final float pY4, final IEaseFunction pEaseFunction) { super(pDuration, pX1, pY1, pX2, pY2, pX3, pY3, pX4, pY4, pEaseFunction); } @Override protected void onManagedUpdate(final float pSecondsElapsed, final IEntity pEntity) { final float startX = pEntity.getX(); final float startY = pEntity.getY(); super.onManagedUpdate(pSecondsElapsed, pEntity); final float deltaX = pEntity.getX() - startX; final float deltaY = pEntity.getY() - startY; pEntity.setRotation(MathUtils.radToDeg(MathUtils.atan2(deltaY, deltaX)) + 90); } }
Java
package org.anddev.andengine.entity.modifier; import org.anddev.andengine.entity.IEntity; import org.anddev.andengine.util.modifier.BaseDoubleValueSpanModifier; import org.anddev.andengine.util.modifier.ease.IEaseFunction; /** * (c) 2010 Nicolas Gramlich * (c) 2011 Zynga Inc. * * @author Nicolas Gramlich * @since 23:29:22 - 19.03.2010 */ public abstract class DoubleValueSpanEntityModifier extends BaseDoubleValueSpanModifier<IEntity> implements IEntityModifier { // =========================================================== // Constants // =========================================================== // =========================================================== // Fields // =========================================================== // =========================================================== // Constructors // =========================================================== public DoubleValueSpanEntityModifier(final float pDuration, final float pFromValueA, final float pToValueA, final float pFromValueB, final float pToValueB) { super(pDuration, pFromValueA, pToValueA, pFromValueB, pToValueB); } public DoubleValueSpanEntityModifier(final float pDuration, final float pFromValueA, final float pToValueA, final float pFromValueB, final float pToValueB, final IEaseFunction pEaseFunction) { super(pDuration, pFromValueA, pToValueA, pFromValueB, pToValueB, pEaseFunction); } public DoubleValueSpanEntityModifier(final float pDuration, final float pFromValueA, final float pToValueA, final float pFromValueB, final float pToValueB, final IEntityModifierListener pEntityModifierListener) { super(pDuration, pFromValueA, pToValueA, pFromValueB, pToValueB, pEntityModifierListener); } public DoubleValueSpanEntityModifier(final float pDuration, final float pFromValueA, final float pToValueA, final float pFromValueB, final float pToValueB, final IEntityModifierListener pEntityModifierListener, final IEaseFunction pEaseFunction) { super(pDuration, pFromValueA, pToValueA, pFromValueB, pToValueB, pEntityModifierListener, pEaseFunction); } protected DoubleValueSpanEntityModifier(final DoubleValueSpanEntityModifier pDoubleValueSpanEntityModifier) { super(pDoubleValueSpanEntityModifier); } // =========================================================== // Getter & Setter // =========================================================== // =========================================================== // Methods for/from SuperClass/Interfaces // =========================================================== // =========================================================== // Methods // =========================================================== // =========================================================== // Inner and Anonymous Classes // =========================================================== }
Java
package org.anddev.andengine.entity.modifier; import org.anddev.andengine.entity.IEntity; import org.anddev.andengine.util.modifier.IModifier; import org.anddev.andengine.util.modifier.SequenceModifier; import org.anddev.andengine.util.modifier.SequenceModifier.ISubSequenceModifierListener; import org.anddev.andengine.util.modifier.ease.IEaseFunction; import android.util.FloatMath; /** * (c) 2010 Nicolas Gramlich * (c) 2011 Zynga Inc. * * @author Nicolas Gramlich * @since 16:50:02 - 16.06.2010 */ public class PathModifier extends EntityModifier { // =========================================================== // Constants // =========================================================== // =========================================================== // Fields // =========================================================== private final SequenceModifier<IEntity> mSequenceModifier; private IPathModifierListener mPathModifierListener; private final Path mPath; // =========================================================== // Constructors // =========================================================== public PathModifier(final float pDuration, final Path pPath) { this(pDuration, pPath, null, null, IEaseFunction.DEFAULT); } public PathModifier(final float pDuration, final Path pPath, final IEaseFunction pEaseFunction) { this(pDuration, pPath, null, null, pEaseFunction); } public PathModifier(final float pDuration, final Path pPath, final IEntityModifierListener pEntityModiferListener) { this(pDuration, pPath, pEntityModiferListener, null, IEaseFunction.DEFAULT); } public PathModifier(final float pDuration, final Path pPath, final IPathModifierListener pPathModifierListener) { this(pDuration, pPath, null, pPathModifierListener, IEaseFunction.DEFAULT); } public PathModifier(final float pDuration, final Path pPath, final IPathModifierListener pPathModifierListener, final IEaseFunction pEaseFunction) { this(pDuration, pPath, null, pPathModifierListener, pEaseFunction); } public PathModifier(final float pDuration, final Path pPath, final IEntityModifierListener pEntityModiferListener, final IEaseFunction pEaseFunction) { this(pDuration, pPath, pEntityModiferListener, null, pEaseFunction); } public PathModifier(final float pDuration, final Path pPath, final IEntityModifierListener pEntityModiferListener, final IPathModifierListener pPathModifierListener) throws IllegalArgumentException { this(pDuration, pPath, pEntityModiferListener, pPathModifierListener, IEaseFunction.DEFAULT); } public PathModifier(final float pDuration, final Path pPath, final IEntityModifierListener pEntityModiferListener, final IPathModifierListener pPathModifierListener, final IEaseFunction pEaseFunction) throws IllegalArgumentException { super(pEntityModiferListener); final int pathSize = pPath.getSize(); if (pathSize < 2) { throw new IllegalArgumentException("Path needs at least 2 waypoints!"); } this.mPath = pPath; this.mPathModifierListener = pPathModifierListener; final MoveModifier[] moveModifiers = new MoveModifier[pathSize - 1]; final float[] coordinatesX = pPath.getCoordinatesX(); final float[] coordinatesY = pPath.getCoordinatesY(); final float velocity = pPath.getLength() / pDuration; final int modifierCount = moveModifiers.length; for(int i = 0; i < modifierCount; i++) { final float duration = pPath.getSegmentLength(i) / velocity; moveModifiers[i] = new MoveModifier(duration, coordinatesX[i], coordinatesX[i + 1], coordinatesY[i], coordinatesY[i + 1], null, pEaseFunction); } /* Create a new SequenceModifier and register the listeners that * call through to mEntityModifierListener and mPathModifierListener. */ this.mSequenceModifier = new SequenceModifier<IEntity>( new ISubSequenceModifierListener<IEntity>() { @Override public void onSubSequenceStarted(final IModifier<IEntity> pModifier, final IEntity pEntity, final int pIndex) { if(PathModifier.this.mPathModifierListener != null) { PathModifier.this.mPathModifierListener.onPathWaypointStarted(PathModifier.this, pEntity, pIndex); } } @Override public void onSubSequenceFinished(final IModifier<IEntity> pEntityModifier, final IEntity pEntity, final int pIndex) { if(PathModifier.this.mPathModifierListener != null) { PathModifier.this.mPathModifierListener.onPathWaypointFinished(PathModifier.this, pEntity, pIndex); } } }, new IEntityModifierListener() { @Override public void onModifierStarted(final IModifier<IEntity> pModifier, final IEntity pEntity) { PathModifier.this.onModifierStarted(pEntity); if(PathModifier.this.mPathModifierListener != null) { PathModifier.this.mPathModifierListener.onPathStarted(PathModifier.this, pEntity); } } @Override public void onModifierFinished(final IModifier<IEntity> pEntityModifier, final IEntity pEntity) { PathModifier.this.onModifierFinished(pEntity); if(PathModifier.this.mPathModifierListener != null) { PathModifier.this.mPathModifierListener.onPathFinished(PathModifier.this, pEntity); } } }, moveModifiers ); } protected PathModifier(final PathModifier pPathModifier) throws DeepCopyNotSupportedException { this.mPath = pPathModifier.mPath.deepCopy(); this.mSequenceModifier = pPathModifier.mSequenceModifier.deepCopy(); } @Override public PathModifier deepCopy() throws DeepCopyNotSupportedException { return new PathModifier(this); } // =========================================================== // Getter & Setter // =========================================================== public Path getPath() { return this.mPath; } // =========================================================== // Methods for/from SuperClass/Interfaces // =========================================================== @Override public boolean isFinished() { return this.mSequenceModifier.isFinished(); } @Override public float getSecondsElapsed() { return this.mSequenceModifier.getSecondsElapsed(); } @Override public float getDuration() { return this.mSequenceModifier.getDuration(); } public IPathModifierListener getPathModifierListener() { return this.mPathModifierListener; } public void setPathModifierListener(final IPathModifierListener pPathModifierListener) { this.mPathModifierListener = pPathModifierListener; } @Override public void reset() { this.mSequenceModifier.reset(); } @Override public float onUpdate(final float pSecondsElapsed, final IEntity pEntity) { return this.mSequenceModifier.onUpdate(pSecondsElapsed, pEntity); } // =========================================================== // Methods // =========================================================== // =========================================================== // Inner and Anonymous Classes // =========================================================== public static interface IPathModifierListener { // =========================================================== // Constants // =========================================================== // =========================================================== // Fields // =========================================================== public void onPathStarted(final PathModifier pPathModifier, final IEntity pEntity); public void onPathWaypointStarted(final PathModifier pPathModifier, final IEntity pEntity, final int pWaypointIndex); public void onPathWaypointFinished(final PathModifier pPathModifier, final IEntity pEntity, final int pWaypointIndex); public void onPathFinished(final PathModifier pPathModifier, final IEntity pEntity); } public static class Path { // =========================================================== // Constants // =========================================================== // =========================================================== // Fields // =========================================================== private final float[] mCoordinatesX; private final float[] mCoordinatesY; private int mIndex; private boolean mLengthChanged = false; private float mLength; // =========================================================== // Constructors // =========================================================== public Path(final int pLength) { this.mCoordinatesX = new float[pLength]; this.mCoordinatesY = new float[pLength]; this.mIndex = 0; this.mLengthChanged = false; } public Path(final float[] pCoordinatesX, final float[] pCoordinatesY) throws IllegalArgumentException { if (pCoordinatesX.length != pCoordinatesY.length) { throw new IllegalArgumentException("Coordinate-Arrays must have the same length."); } this.mCoordinatesX = pCoordinatesX; this.mCoordinatesY = pCoordinatesY; this.mIndex = pCoordinatesX.length; this.mLengthChanged = true; } public Path(final Path pPath) { final int size = pPath.getSize(); this.mCoordinatesX = new float[size]; this.mCoordinatesY = new float[size]; System.arraycopy(pPath.mCoordinatesX, 0, this.mCoordinatesX, 0, size); System.arraycopy(pPath.mCoordinatesY, 0, this.mCoordinatesY, 0, size); this.mIndex = pPath.mIndex; this.mLengthChanged = pPath.mLengthChanged; this.mLength = pPath.mLength; } public Path deepCopy() { return new Path(this); } // =========================================================== // Getter & Setter // =========================================================== public Path to(final float pX, final float pY) { this.mCoordinatesX[this.mIndex] = pX; this.mCoordinatesY[this.mIndex] = pY; this.mIndex++; this.mLengthChanged = true; return this; } public float[] getCoordinatesX() { return this.mCoordinatesX; } public float[] getCoordinatesY() { return this.mCoordinatesY; } public int getSize() { return this.mCoordinatesX.length; } public float getLength() { if(this.mLengthChanged) { this.updateLength(); } return this.mLength; } public float getSegmentLength(final int pSegmentIndex) { final float[] coordinatesX = this.mCoordinatesX; final float[] coordinatesY = this.mCoordinatesY; final int nextSegmentIndex = pSegmentIndex + 1; final float dx = coordinatesX[pSegmentIndex] - coordinatesX[nextSegmentIndex]; final float dy = coordinatesY[pSegmentIndex] - coordinatesY[nextSegmentIndex]; return FloatMath.sqrt(dx * dx + dy * dy); } // =========================================================== // Methods for/from SuperClass/Interfaces // =========================================================== // =========================================================== // Methods // =========================================================== private void updateLength() { float length = 0.0f; for(int i = this.mIndex - 2; i >= 0; i--) { length += this.getSegmentLength(i); } this.mLength = length; } // =========================================================== // Inner and Anonymous Classes // =========================================================== } }
Java
package org.anddev.andengine.entity.modifier; import org.anddev.andengine.entity.IEntity; import org.anddev.andengine.util.modifier.LoopModifier; /** * (c) 2010 Nicolas Gramlich * (c) 2011 Zynga Inc. * * @author Nicolas Gramlich * @since 12:42:13 - 03.09.2010 */ public class LoopEntityModifier extends LoopModifier<IEntity> implements IEntityModifier { // =========================================================== // Constants // =========================================================== // =========================================================== // Fields // =========================================================== // =========================================================== // Constructors // =========================================================== public LoopEntityModifier(final IEntityModifier pEntityModifier) { super(pEntityModifier); } public LoopEntityModifier(final IEntityModifier pEntityModifier, final int pLoopCount) { super(pEntityModifier, pLoopCount); } public LoopEntityModifier(final IEntityModifier pEntityModifier, final int pLoopCount, final ILoopEntityModifierListener pLoopModifierListener) { super(pEntityModifier, pLoopCount, pLoopModifierListener); } public LoopEntityModifier(final IEntityModifier pEntityModifier, final int pLoopCount, final IEntityModifierListener pEntityModifierListener) { super(pEntityModifier, pLoopCount, pEntityModifierListener); } public LoopEntityModifier(final IEntityModifierListener pEntityModifierListener, final int pLoopCount, final ILoopEntityModifierListener pLoopModifierListener, final IEntityModifier pEntityModifier) { super(pEntityModifier, pLoopCount, pLoopModifierListener, pEntityModifierListener); } protected LoopEntityModifier(final LoopEntityModifier pLoopEntityModifier) throws DeepCopyNotSupportedException { super(pLoopEntityModifier); } @Override public LoopEntityModifier deepCopy() throws DeepCopyNotSupportedException { return new LoopEntityModifier(this); } // =========================================================== // Getter & Setter // =========================================================== // =========================================================== // Methods for/from SuperClass/Interfaces // =========================================================== // =========================================================== // Methods // =========================================================== // =========================================================== // Inner and Anonymous Classes // =========================================================== public interface ILoopEntityModifierListener extends ILoopModifierListener<IEntity> { // =========================================================== // Final Fields // =========================================================== // =========================================================== // Methods // =========================================================== } }
Java
package org.anddev.andengine.entity.modifier; import org.anddev.andengine.entity.IEntity; import org.anddev.andengine.util.modifier.BaseTripleValueSpanModifier; import org.anddev.andengine.util.modifier.ease.IEaseFunction; /** * (c) 2010 Nicolas Gramlich * (c) 2011 Zynga Inc. * * @author Nicolas Gramlich * @since 15:35:18 - 29.06.2010 */ public abstract class TripleValueSpanEntityModifier extends BaseTripleValueSpanModifier<IEntity> implements IEntityModifier { // =========================================================== // Constants // =========================================================== // =========================================================== // Fields // =========================================================== // =========================================================== // Constructors // =========================================================== public TripleValueSpanEntityModifier(final float pDuration, final float pFromValueA, final float pToValueA, final float pFromValueB, final float pToValueB, final float pFromValueC, final float pToValueC, final IEaseFunction pEaseFunction) { super(pDuration, pFromValueA, pToValueA, pFromValueB, pToValueB, pFromValueC, pToValueC, pEaseFunction); } public TripleValueSpanEntityModifier(final float pDuration, final float pFromValueA, final float pToValueA, final float pFromValueB, final float pToValueB, final float pFromValueC, final float pToValueC, final IEntityModifierListener pEntityModifierListener, final IEaseFunction pEaseFunction) { super(pDuration, pFromValueA, pToValueA, pFromValueB, pToValueB, pFromValueC, pToValueC, pEntityModifierListener, pEaseFunction); } protected TripleValueSpanEntityModifier(final TripleValueSpanEntityModifier pTripleValueSpanEntityModifier) { super(pTripleValueSpanEntityModifier); } // =========================================================== // Getter & Setter // =========================================================== // =========================================================== // Methods for/from SuperClass/Interfaces // =========================================================== // =========================================================== // Methods // =========================================================== // =========================================================== // Inner and Anonymous Classes // =========================================================== }
Java
package org.anddev.andengine.entity.modifier; import org.anddev.andengine.entity.IEntity; import org.anddev.andengine.util.modifier.BaseSingleValueChangeModifier; /** * (c) 2010 Nicolas Gramlich * (c) 2011 Zynga Inc. * * @author Nicolas Gramlich * @since 15:34:35 - 17.06.2010 */ public abstract class SingleValueChangeEntityModifier extends BaseSingleValueChangeModifier<IEntity> implements IEntityModifier { // =========================================================== // Constants // =========================================================== // =========================================================== // Fields // =========================================================== // =========================================================== // Constructors // =========================================================== public SingleValueChangeEntityModifier(final float pDuration, final float pValueChange) { super(pDuration, pValueChange); } public SingleValueChangeEntityModifier(final float pDuration, final float pValueChange, final IEntityModifierListener pEntityModifierListener) { super(pDuration, pValueChange, pEntityModifierListener); } protected SingleValueChangeEntityModifier(final SingleValueChangeEntityModifier pSingleValueChangeEntityModifier) { super(pSingleValueChangeEntityModifier); } // =========================================================== // Getter & Setter // =========================================================== // =========================================================== // Methods for/from SuperClass/Interfaces // =========================================================== // =========================================================== // Methods // =========================================================== // =========================================================== // Inner and Anonymous Classes // =========================================================== }
Java
package org.anddev.andengine.entity.modifier; import org.anddev.andengine.util.modifier.ease.IEaseFunction; /** * (c) 2010 Nicolas Gramlich * (c) 2011 Zynga Inc. * * @author Nicolas Gramlich * @since 19:03:12 - 08.06.2010 */ public class FadeInModifier extends AlphaModifier { // =========================================================== // Constants // =========================================================== // =========================================================== // Fields // =========================================================== // =========================================================== // Constructors // =========================================================== public FadeInModifier(final float pDuration) { super(pDuration, 0.0f, 1.0f, IEaseFunction.DEFAULT); } public FadeInModifier(final float pDuration, final IEaseFunction pEaseFunction) { super(pDuration, 0.0f, 1.0f, pEaseFunction); } public FadeInModifier(final float pDuration, final IEntityModifierListener pEntityModifierListener) { super(pDuration, 0.0f, 1.0f, pEntityModifierListener, IEaseFunction.DEFAULT); } public FadeInModifier(final float pDuration, final IEntityModifierListener pEntityModifierListener, final IEaseFunction pEaseFunction) { super(pDuration, 0.0f, 1.0f, pEntityModifierListener, pEaseFunction); } protected FadeInModifier(final FadeInModifier pFadeInModifier) { super(pFadeInModifier); } @Override public FadeInModifier deepCopy() { return new FadeInModifier(this); } // =========================================================== // Getter & Setter // =========================================================== // =========================================================== // Methods for/from SuperClass/Interfaces // =========================================================== // =========================================================== // Methods // =========================================================== // =========================================================== // Inner and Anonymous Classes // =========================================================== }
Java
package org.anddev.andengine.entity.modifier; import org.anddev.andengine.entity.IEntity; import org.anddev.andengine.util.modifier.ease.IEaseFunction; /** * (c) 2010 Nicolas Gramlich * (c) 2011 Zynga Inc. * * @author Pawel Plewa * @author Nicolas Gramlich * @since 23:24:26 - 16.07.2011 */ public class CubicBezierMoveModifier extends DurationEntityModifier { // =========================================================== // Constants // =========================================================== // =========================================================== // Fields // =========================================================== private final float mX1; private final float mY1; private final float mX2; private final float mY2; private final float mX3; private final float mY3; private final float mX4; private final float mY4; private final IEaseFunction mEaseFunction; // =========================================================== // Constructors // =========================================================== /** * @param pDuration * @param pX1 x coordinate of the start point. * @param pY1 y coordinate of the start point. * @param pX2 x coordinate of the first control point. * @param pY2 y coordinate of the first control point. * @param pX3 x coordinate of the second control point. * @param pY3 y coordinate of the second control point. * @param pX4 x coordinate of the end point. * @param pY4 y coordinate of the end point. * @param pEaseFunction */ public CubicBezierMoveModifier(final float pDuration, final float pX1, final float pY1, final float pX2, final float pY2, final float pX3, final float pY3, final float pX4, final float pY4, final IEaseFunction pEaseFunction) { super(pDuration); this.mX1 = pX1; this.mY1 = pY1; this.mX2 = pX2; this.mY2 = pY2; this.mX3 = pX3; this.mY3 = pY3; this.mX4 = pX4; this.mY4 = pY4; this.mEaseFunction = pEaseFunction; } @Override public CubicBezierMoveModifier deepCopy() { return new CubicBezierMoveModifier(this.mDuration, this.mX1, this.mY1, this.mX2, this.mY2, this.mX3, this.mY3, this.mX4, this.mY4, this.mEaseFunction); } // =========================================================== // Getter & Setter // =========================================================== // =========================================================== // Methods for/from SuperClass/Interfaces // =========================================================== @Override protected void onManagedUpdate(final float pSecondsElapsed, final IEntity pEntity) { final float percentageDone = this.mEaseFunction.getPercentage(this.getSecondsElapsed(), this.mDuration); final float u = 1 - percentageDone; final float tt = percentageDone * percentageDone; final float uu = u * u; final float uuu = uu * u; final float ttt = tt * percentageDone; final float ut3 = 3 * uu * percentageDone; final float utt3 = 3 * u * tt; /* * Formula: ((1-t)^3 * p1) + (3*(t)*(1-t)^2 * p2) + (3*(t^2)*(1-t) * p3) + (t^3 * p4) */ final float x = (uuu * this.mX1) + (ut3 * this.mX2) + (utt3 * this.mX3) + (ttt * this.mX4); final float y = (uuu * this.mY1) + (ut3 * this.mY2) + (utt3 * this.mY3) + (ttt * this.mY4); pEntity.setPosition(x, y); } @Override protected void onManagedInitialize(final IEntity pEntity) { } // =========================================================== // Methods // =========================================================== // =========================================================== // Inner and Anonymous Classes // =========================================================== }
Java
package org.anddev.andengine.entity.modifier; import org.anddev.andengine.entity.IEntity; import org.anddev.andengine.util.modifier.ease.IEaseFunction; /** * (c) 2010 Nicolas Gramlich * (c) 2011 Zynga Inc. * * @author Nicolas Gramlich * @since 21:53:30 - 06.07.2010 */ public class ScaleAtModifier extends ScaleModifier { // =========================================================== // Constants // =========================================================== // =========================================================== // Fields // =========================================================== private final float mScaleCenterX; private final float mScaleCenterY; // =========================================================== // Constructors // =========================================================== public ScaleAtModifier(final float pDuration, final float pFromScale, final float pToScale, final float pScaleCenterX, final float pScaleCenterY) { this(pDuration, pFromScale, pToScale, pScaleCenterX, pScaleCenterY, IEaseFunction.DEFAULT); } public ScaleAtModifier(final float pDuration, final float pFromScale, final float pToScale, final float pScaleCenterX, final float pScaleCenterY, final IEaseFunction pEaseFunction) { this(pDuration, pFromScale, pToScale, pScaleCenterX, pScaleCenterY, null, pEaseFunction); } public ScaleAtModifier(final float pDuration, final float pFromScale, final float pToScale, final float pScaleCenterX, final float pScaleCenterY, final IEntityModifierListener pEntityModifierListener) { this(pDuration, pFromScale, pToScale, pScaleCenterX, pScaleCenterY, pEntityModifierListener, IEaseFunction.DEFAULT); } public ScaleAtModifier(final float pDuration, final float pFromScale, final float pToScale, final float pScaleCenterX, final float pScaleCenterY, final IEntityModifierListener pEntityModifierListener, final IEaseFunction pEaseFunction) { this(pDuration, pFromScale, pToScale, pFromScale, pToScale, pScaleCenterX, pScaleCenterY, pEntityModifierListener, pEaseFunction); } public ScaleAtModifier(final float pDuration, final float pFromScaleX, final float pToScaleX, final float pFromScaleY, final float pToScaleY, final float pScaleCenterX, final float pScaleCenterY) { this(pDuration, pFromScaleX, pToScaleX, pFromScaleY, pToScaleY, pScaleCenterX, pScaleCenterY, IEaseFunction.DEFAULT); } public ScaleAtModifier(final float pDuration, final float pFromScaleX, final float pToScaleX, final float pFromScaleY, final float pToScaleY, final float pScaleCenterX, final float pScaleCenterY, final IEaseFunction pEaseFunction) { this(pDuration, pFromScaleX, pToScaleX, pFromScaleY, pToScaleY, pScaleCenterX, pScaleCenterY, null, pEaseFunction); } public ScaleAtModifier(final float pDuration, final float pFromScaleX, final float pToScaleX, final float pFromScaleY, final float pToScaleY, final float pScaleCenterX, final float pScaleCenterY, final IEntityModifierListener pEntityModifierListener) { this(pDuration, pFromScaleX, pToScaleX, pFromScaleY, pToScaleY, pScaleCenterX, pScaleCenterY, pEntityModifierListener, IEaseFunction.DEFAULT); } public ScaleAtModifier(final float pDuration, final float pFromScaleX, final float pToScaleX, final float pFromScaleY, final float pToScaleY, final float pScaleCenterX, final float pScaleCenterY, final IEntityModifierListener pEntityModifierListener, final IEaseFunction pEaseFunction) { super(pDuration, pFromScaleX, pToScaleX, pFromScaleY, pToScaleY, pEntityModifierListener, pEaseFunction); this.mScaleCenterX = pScaleCenterX; this.mScaleCenterY = pScaleCenterY; } protected ScaleAtModifier(final ScaleAtModifier pScaleAtModifier) { super(pScaleAtModifier); this.mScaleCenterX = pScaleAtModifier.mScaleCenterX; this.mScaleCenterY = pScaleAtModifier.mScaleCenterY; } @Override public ScaleAtModifier deepCopy(){ return new ScaleAtModifier(this); } // =========================================================== // Getter & Setter // =========================================================== // =========================================================== // Methods for/from SuperClass/Interfaces // =========================================================== @Override protected void onManagedInitialize(final IEntity pEntity) { super.onManagedInitialize(pEntity); pEntity.setScaleCenter(this.mScaleCenterX, this.mScaleCenterY); } // =========================================================== // Methods // =========================================================== // =========================================================== // Inner and Anonymous Classes // =========================================================== }
Java
package org.anddev.andengine.entity.modifier; import org.anddev.andengine.entity.IEntity; import org.anddev.andengine.util.modifier.ParallelModifier; /** * (c) 2010 Nicolas Gramlich * (c) 2011 Zynga Inc. * * @author Nicolas Gramlich * @since 12:40:31 - 03.09.2010 */ public class ParallelEntityModifier extends ParallelModifier<IEntity> implements IEntityModifier { // =========================================================== // Constants // =========================================================== // =========================================================== // Fields // =========================================================== // =========================================================== // Constructors // =========================================================== public ParallelEntityModifier(final IEntityModifier... pEntityModifiers) throws IllegalArgumentException { super(pEntityModifiers); } public ParallelEntityModifier(final IEntityModifierListener pEntityModifierListener, final IEntityModifier... pEntityModifiers) throws IllegalArgumentException { super(pEntityModifierListener, pEntityModifiers); } protected ParallelEntityModifier(final ParallelEntityModifier pParallelShapeModifier) throws DeepCopyNotSupportedException { super(pParallelShapeModifier); } @Override public ParallelEntityModifier deepCopy() throws DeepCopyNotSupportedException { return new ParallelEntityModifier(this); } // =========================================================== // Getter & Setter // =========================================================== // =========================================================== // Methods for/from SuperClass/Interfaces // =========================================================== // =========================================================== // Methods // =========================================================== // =========================================================== // Inner and Anonymous Classes // =========================================================== }
Java
package org.anddev.andengine.entity.modifier; import org.anddev.andengine.entity.IEntity; import org.anddev.andengine.util.modifier.BaseDurationModifier; /** * (c) 2010 Nicolas Gramlich * (c) 2011 Zynga Inc. * * @author Nicolas Gramlich * @since 16:10:42 - 19.03.2010 */ public abstract class DurationEntityModifier extends BaseDurationModifier<IEntity> implements IEntityModifier { // =========================================================== // Constants // =========================================================== // =========================================================== // Fields // =========================================================== // =========================================================== // Constructors // =========================================================== public DurationEntityModifier(final float pDuration) { super(pDuration); } public DurationEntityModifier(final float pDuration, final IEntityModifierListener pEntityModifierListener) { super(pDuration, pEntityModifierListener); } protected DurationEntityModifier(final DurationEntityModifier pDurationEntityModifier) { super(pDurationEntityModifier); } // =========================================================== // Getter & Setter // =========================================================== // =========================================================== // Methods for/from SuperClass/Interfaces // =========================================================== // =========================================================== // Methods // =========================================================== // =========================================================== // Inner and Anonymous Classes // =========================================================== }
Java
package org.anddev.andengine.entity.modifier; import org.anddev.andengine.entity.IEntity; import org.anddev.andengine.util.modifier.BaseModifier; /** * (c) 2010 Nicolas Gramlich * (c) 2011 Zynga Inc. * * @author Nicolas Gramlich * @since 10:53:16 - 03.09.2010 */ public abstract class EntityModifier extends BaseModifier<IEntity> implements IEntityModifier { // =========================================================== // Constants // =========================================================== // =========================================================== // Fields // =========================================================== // =========================================================== // Constructors // =========================================================== public EntityModifier() { super(); } public EntityModifier(final IEntityModifierListener pEntityModifierListener) { super(pEntityModifierListener); } // =========================================================== // Getter & Setter // =========================================================== // =========================================================== // Methods for/from SuperClass/Interfaces // =========================================================== // =========================================================== // Methods // =========================================================== // =========================================================== // Inner and Anonymous Classes // =========================================================== }
Java
package org.anddev.andengine.entity.modifier; import org.anddev.andengine.entity.IEntity; import org.anddev.andengine.util.modifier.SequenceModifier; /** * (c) 2010 Nicolas Gramlich * (c) 2011 Zynga Inc. * * @author Nicolas Gramlich * @since 12:41:15 - 03.09.2010 */ public class SequenceEntityModifier extends SequenceModifier<IEntity> implements IEntityModifier { // =========================================================== // Constants // =========================================================== // =========================================================== // Fields // =========================================================== // =========================================================== // Constructors // =========================================================== public SequenceEntityModifier(final IEntityModifier... pEntityModifiers) throws IllegalArgumentException { super(pEntityModifiers); } public SequenceEntityModifier(final ISubSequenceShapeModifierListener pSubSequenceShapeModifierListener, final IEntityModifier... pEntityModifiers) throws IllegalArgumentException { super(pSubSequenceShapeModifierListener, pEntityModifiers); } public SequenceEntityModifier(final IEntityModifierListener pEntityModifierListener, final IEntityModifier... pEntityModifiers) throws IllegalArgumentException { super(pEntityModifierListener, pEntityModifiers); } public SequenceEntityModifier(final ISubSequenceShapeModifierListener pSubSequenceShapeModifierListener, final IEntityModifierListener pEntityModifierListener, final IEntityModifier... pEntityModifiers) throws IllegalArgumentException { super(pSubSequenceShapeModifierListener, pEntityModifierListener, pEntityModifiers); } protected SequenceEntityModifier(final SequenceEntityModifier pSequenceShapeModifier) throws DeepCopyNotSupportedException { super(pSequenceShapeModifier); } @Override public SequenceEntityModifier deepCopy() throws DeepCopyNotSupportedException { return new SequenceEntityModifier(this); } // =========================================================== // Getter & Setter // =========================================================== // =========================================================== // Methods for/from SuperClass/Interfaces // =========================================================== // =========================================================== // Methods // =========================================================== // =========================================================== // Inner and Anonymous Classes // =========================================================== public interface ISubSequenceShapeModifierListener extends ISubSequenceModifierListener<IEntity> { // =========================================================== // Final Fields // =========================================================== // =========================================================== // Methods // =========================================================== } }
Java
package org.anddev.andengine.entity.modifier; import org.anddev.andengine.entity.IEntity; import org.anddev.andengine.util.modifier.ease.IEaseFunction; /** * (c) 2010 Nicolas Gramlich * (c) 2011 Zynga Inc. * * @author Nicolas Gramlich * @since 16:12:52 - 19.03.2010 */ public class MoveModifier extends DoubleValueSpanEntityModifier { // =========================================================== // Constants // =========================================================== // =========================================================== // Fields // =========================================================== // =========================================================== // Constructors // =========================================================== public MoveModifier(final float pDuration, final float pFromX, final float pToX, final float pFromY, final float pToY) { this(pDuration, pFromX, pToX, pFromY, pToY, null, IEaseFunction.DEFAULT); } public MoveModifier(final float pDuration, final float pFromX, final float pToX, final float pFromY, final float pToY, final IEaseFunction pEaseFunction) { this(pDuration, pFromX, pToX, pFromY, pToY, null, pEaseFunction); } public MoveModifier(final float pDuration, final float pFromX, final float pToX, final float pFromY, final float pToY, final IEntityModifierListener pEntityModifierListener) { super(pDuration, pFromX, pToX, pFromY, pToY, pEntityModifierListener, IEaseFunction.DEFAULT); } public MoveModifier(final float pDuration, final float pFromX, final float pToX, final float pFromY, final float pToY, final IEntityModifierListener pEntityModifierListener, final IEaseFunction pEaseFunction) { super(pDuration, pFromX, pToX, pFromY, pToY, pEntityModifierListener, pEaseFunction); } protected MoveModifier(final MoveModifier pMoveModifier) { super(pMoveModifier); } @Override public MoveModifier deepCopy(){ return new MoveModifier(this); } // =========================================================== // Getter & Setter // =========================================================== // =========================================================== // Methods for/from SuperClass/Interfaces // =========================================================== @Override protected void onSetInitialValues(final IEntity pEntity, final float pX, final float pY) { pEntity.setPosition(pX, pY); } @Override protected void onSetValues(final IEntity pEntity, final float pPercentageDone, final float pX, final float pY) { pEntity.setPosition(pX, pY); } // =========================================================== // Methods // =========================================================== // =========================================================== // Inner and Anonymous Classes // =========================================================== }
Java
package org.anddev.andengine.entity.modifier; import org.anddev.andengine.util.modifier.ease.IEaseFunction; /** * (c) 2010 Nicolas Gramlich * (c) 2011 Zynga Inc. * * @author Nicolas Gramlich * @since 19:03:12 - 08.06.2010 */ public class FadeOutModifier extends AlphaModifier { // =========================================================== // Constants // =========================================================== // =========================================================== // Fields // =========================================================== // =========================================================== // Constructors // =========================================================== public FadeOutModifier(final float pDuration) { super(pDuration, 1.0f, 0.0f, IEaseFunction.DEFAULT); } public FadeOutModifier(final float pDuration, final IEaseFunction pEaseFunction) { super(pDuration, 1.0f, 0.0f, pEaseFunction); } public FadeOutModifier(final float pDuration, final IEntityModifierListener pEntityModifierListener) { super(pDuration, 1.0f, 0.0f, pEntityModifierListener, IEaseFunction.DEFAULT); } public FadeOutModifier(final float pDuration, final IEntityModifierListener pEntityModifierListener, final IEaseFunction pEaseFunction) { super(pDuration, 1.0f, 0.0f, pEntityModifierListener, pEaseFunction); } protected FadeOutModifier(final FadeOutModifier pFadeOutModifier) { super(pFadeOutModifier); } @Override public FadeOutModifier deepCopy() { return new FadeOutModifier(this); } // =========================================================== // Getter & Setter // =========================================================== // =========================================================== // Methods for/from SuperClass/Interfaces // =========================================================== // =========================================================== // Methods // =========================================================== // =========================================================== // Inner and Anonymous Classes // =========================================================== }
Java
package org.anddev.andengine.entity.modifier; import org.anddev.andengine.entity.IEntity; import org.anddev.andengine.util.modifier.ModifierList; /** * (c) 2010 Nicolas Gramlich * (c) 2011 Zynga Inc. * * @author Nicolas Gramlich * @since 14:19:18 - 24.12.2010 */ public class EntityModifierList extends ModifierList<IEntity> { // =========================================================== // Constants // =========================================================== private static final long serialVersionUID = 161652765736600082L; // =========================================================== // Fields // =========================================================== // =========================================================== // Constructors // =========================================================== public EntityModifierList(final IEntity pTarget) { super(pTarget); } public EntityModifierList(final IEntity pTarget, final int pCapacity) { super(pTarget, pCapacity); } // =========================================================== // Getter & Setter // =========================================================== // =========================================================== // Methods for/from SuperClass/Interfaces // =========================================================== // =========================================================== // Methods // =========================================================== // =========================================================== // Inner and Anonymous Classes // =========================================================== }
Java
package org.anddev.andengine.entity.modifier; import org.anddev.andengine.entity.IEntity; import org.anddev.andengine.util.modifier.BaseSingleValueSpanModifier; import org.anddev.andengine.util.modifier.ease.IEaseFunction; /** * (c) 2010 Nicolas Gramlich * (c) 2011 Zynga Inc. * * @author Nicolas Gramlich * @since 23:29:22 - 19.03.2010 */ public abstract class SingleValueSpanEntityModifier extends BaseSingleValueSpanModifier<IEntity> implements IEntityModifier { // =========================================================== // Constants // =========================================================== // =========================================================== // Fields // =========================================================== // =========================================================== // Constructors // =========================================================== public SingleValueSpanEntityModifier(final float pDuration, final float pFromValue, final float pToValue) { super(pDuration, pFromValue, pToValue); } public SingleValueSpanEntityModifier(final float pDuration, final float pFromValue, final float pToValue, final IEaseFunction pEaseFunction) { super(pDuration, pFromValue, pToValue, pEaseFunction); } public SingleValueSpanEntityModifier(final float pDuration, final float pFromValue, final float pToValue, final IEntityModifierListener pEntityModifierListener) { super(pDuration, pFromValue, pToValue, pEntityModifierListener); } public SingleValueSpanEntityModifier(final float pDuration, final float pFromValue, final float pToValue, final IEntityModifierListener pEntityModifierListener, final IEaseFunction pEaseFunction) { super(pDuration, pFromValue, pToValue, pEntityModifierListener, pEaseFunction); } protected SingleValueSpanEntityModifier(final SingleValueSpanEntityModifier pSingleValueSpanEntityModifier) { super(pSingleValueSpanEntityModifier); } // =========================================================== // Getter & Setter // =========================================================== // =========================================================== // Methods for/from SuperClass/Interfaces // =========================================================== // =========================================================== // Methods // =========================================================== // =========================================================== // Inner and Anonymous Classes // =========================================================== }
Java
package org.anddev.andengine.entity.modifier; import org.anddev.andengine.entity.IEntity; import org.anddev.andengine.util.modifier.BaseDoubleValueChangeModifier; /** * (c) Zynga 2011 * * @author Nicolas Gramlich <ngramlich@zynga.com> * @since 14:27:48 - 10.08.2011 */ public abstract class DoubleValueChangeEntityModifier extends BaseDoubleValueChangeModifier<IEntity> implements IEntityModifier { // =========================================================== // Constants // =========================================================== // =========================================================== // Fields // =========================================================== // =========================================================== // Constructors // =========================================================== public DoubleValueChangeEntityModifier(float pDuration, float pValueChangeA, float pValueChangeB) { super(pDuration, pValueChangeA, pValueChangeB); } public DoubleValueChangeEntityModifier(float pDuration, float pValueChangeA, float pValueChangeB, IEntityModifierListener pModifierListener) { super(pDuration, pValueChangeA, pValueChangeB, pModifierListener); } public DoubleValueChangeEntityModifier(DoubleValueChangeEntityModifier pDoubleValueChangeEntityModifier) { super(pDoubleValueChangeEntityModifier); } // =========================================================== // Getter & Setter // =========================================================== // =========================================================== // Methods for/from SuperClass/Interfaces // =========================================================== // =========================================================== // Methods // =========================================================== // =========================================================== // Inner and Anonymous Classes // =========================================================== }
Java
package org.anddev.andengine.entity.modifier; import org.anddev.andengine.entity.IEntity; /** * (c) 2010 Nicolas Gramlich * (c) 2011 Zynga Inc. * * @author Nicolas Gramlich * @since 22:55:13 - 19.03.2010 */ public class DelayModifier extends DurationEntityModifier { // =========================================================== // Constants // =========================================================== // =========================================================== // Fields // =========================================================== // =========================================================== // Constructors // =========================================================== public DelayModifier(final float pDuration, final IEntityModifierListener pEntityModifierListener) { super(pDuration, pEntityModifierListener); } public DelayModifier(final float pDuration) { super(pDuration); } protected DelayModifier(final DelayModifier pDelayModifier) { super(pDelayModifier); } @Override public DelayModifier deepCopy(){ return new DelayModifier(this); } // =========================================================== // Getter & Setter // =========================================================== // =========================================================== // Methods for/from SuperClass/Interfaces // =========================================================== @Override protected void onManagedInitialize(final IEntity pEntity) { } @Override protected void onManagedUpdate(final float pSecondsElapsed, final IEntity pEntity) { } // =========================================================== // Methods // =========================================================== // =========================================================== // Inner and Anonymous Classes // =========================================================== }
Java
package org.anddev.andengine.entity.modifier; import org.anddev.andengine.entity.IEntity; import org.anddev.andengine.util.modifier.ease.IEaseFunction; /** * (c) 2010 Nicolas Gramlich * (c) 2011 Zynga Inc. * * @author Nicolas Gramlich * @since 12:03:22 - 30.08.2010 */ public class MoveXModifier extends SingleValueSpanEntityModifier { // =========================================================== // Constants // =========================================================== // =========================================================== // Fields // =========================================================== // =========================================================== // Constructors // =========================================================== public MoveXModifier(final float pDuration, final float pFromX, final float pToX) { this(pDuration, pFromX, pToX, null, IEaseFunction.DEFAULT); } public MoveXModifier(final float pDuration, final float pFromX, final float pToX, final IEaseFunction pEaseFunction) { this(pDuration, pFromX, pToX, null, pEaseFunction); } public MoveXModifier(final float pDuration, final float pFromX, final float pToX, final IEntityModifierListener pEntityModifierListener) { super(pDuration, pFromX, pToX, pEntityModifierListener, IEaseFunction.DEFAULT); } public MoveXModifier(final float pDuration, final float pFromX, final float pToX, final IEntityModifierListener pEntityModifierListener, final IEaseFunction pEaseFunction) { super(pDuration, pFromX, pToX, pEntityModifierListener, pEaseFunction); } protected MoveXModifier(final MoveXModifier pMoveXModifier) { super(pMoveXModifier); } @Override public MoveXModifier deepCopy(){ return new MoveXModifier(this); } // =========================================================== // Getter & Setter // =========================================================== // =========================================================== // Methods for/from SuperClass/Interfaces // =========================================================== @Override protected void onSetInitialValue(final IEntity pEntity, final float pX) { pEntity.setPosition(pX, pEntity.getY()); } @Override protected void onSetValue(final IEntity pEntity, final float pPercentageDone, final float pX) { pEntity.setPosition(pX, pEntity.getY()); } // =========================================================== // Methods // =========================================================== // =========================================================== // Inner and Anonymous Classes // =========================================================== }
Java
package org.anddev.andengine.entity.modifier; import org.anddev.andengine.entity.IEntity; import org.anddev.andengine.util.modifier.ease.IEaseFunction; /** * (c) 2010 Nicolas Gramlich * (c) 2011 Zynga Inc. * * @author Nicolas Gramlich * @since 21:59:38 - 06.07.2010 */ public class RotationAtModifier extends RotationModifier { // =========================================================== // Constants // =========================================================== // =========================================================== // Fields // =========================================================== private final float mRotationCenterX; private final float mRotationCenterY; // =========================================================== // Constructors // =========================================================== public RotationAtModifier(final float pDuration, final float pFromRotation, final float pToRotation, final float pRotationCenterX, final float pRotationCenterY) { super(pDuration, pFromRotation, pToRotation, IEaseFunction.DEFAULT); this.mRotationCenterX = pRotationCenterX; this.mRotationCenterY = pRotationCenterY; } public RotationAtModifier(final float pDuration, final float pFromRotation, final float pToRotation, final float pRotationCenterX, final float pRotationCenterY, final IEaseFunction pEaseFunction) { super(pDuration, pFromRotation, pToRotation, pEaseFunction); this.mRotationCenterX = pRotationCenterX; this.mRotationCenterY = pRotationCenterY; } public RotationAtModifier(final float pDuration, final float pFromRotation, final float pToRotation, final float pRotationCenterX, final float pRotationCenterY, final IEntityModifierListener pEntityModifierListener) { super(pDuration, pFromRotation, pToRotation, pEntityModifierListener, IEaseFunction.DEFAULT); this.mRotationCenterX = pRotationCenterX; this.mRotationCenterY = pRotationCenterY; } public RotationAtModifier(final float pDuration, final float pFromRotation, final float pToRotation, final float pRotationCenterX, final float pRotationCenterY, final IEntityModifierListener pEntityModifierListener, final IEaseFunction pEaseFunction) { super(pDuration, pFromRotation, pToRotation, pEntityModifierListener, pEaseFunction); this.mRotationCenterX = pRotationCenterX; this.mRotationCenterY = pRotationCenterY; } protected RotationAtModifier(final RotationAtModifier pRotationAtModifier) { super(pRotationAtModifier); this.mRotationCenterX = pRotationAtModifier.mRotationCenterX; this.mRotationCenterY = pRotationAtModifier.mRotationCenterY; } @Override public RotationAtModifier deepCopy(){ return new RotationAtModifier(this); } // =========================================================== // Getter & Setter // =========================================================== // =========================================================== // Methods for/from SuperClass/Interfaces // =========================================================== @Override protected void onManagedInitialize(final IEntity pEntity) { super.onManagedInitialize(pEntity); pEntity.setRotationCenter(this.mRotationCenterX, this.mRotationCenterY); } // =========================================================== // Methods // =========================================================== // =========================================================== // Inner and Anonymous Classes // =========================================================== }
Java
package org.anddev.andengine.entity.modifier; import org.anddev.andengine.entity.IEntity; /** * (c) 2010 Nicolas Gramlich * (c) 2011 Zynga Inc. * * @author Nicolas Gramlich * @since 16:12:52 - 19.03.2010 */ public class RotationByModifier extends SingleValueChangeEntityModifier { // =========================================================== // Constants // =========================================================== // =========================================================== // Fields // =========================================================== // =========================================================== // Constructors // =========================================================== public RotationByModifier(final float pDuration, final float pRotation) { super(pDuration, pRotation); } public RotationByModifier(final float pDuration, final float pRotation, final IEntityModifierListener pEntityModifierListener) { super(pDuration, pRotation, pEntityModifierListener); } protected RotationByModifier(final RotationByModifier pRotationByModifier) { super(pRotationByModifier); } @Override public RotationByModifier deepCopy(){ return new RotationByModifier(this); } // =========================================================== // Getter & Setter // =========================================================== // =========================================================== // Methods for/from SuperClass/Interfaces // =========================================================== @Override protected void onChangeValue(final float pSecondsElapsed, final IEntity pEntity, final float pRotation) { pEntity.setRotation(pEntity.getRotation() + pRotation); } // =========================================================== // Methods // =========================================================== // =========================================================== // Inner and Anonymous Classes // =========================================================== }
Java
package org.anddev.andengine.entity.modifier; import org.anddev.andengine.entity.IEntity; import org.anddev.andengine.util.modifier.ease.IEaseFunction; /** * (c) 2010 Nicolas Gramlich * (c) 2011 Zynga Inc. * * @author Nicolas Gramlich * @since 23:13:01 - 19.03.2010 */ public class AlphaModifier extends SingleValueSpanEntityModifier { // =========================================================== // Constants // =========================================================== // =========================================================== // Fields // =========================================================== // =========================================================== // Constructors // =========================================================== public AlphaModifier(final float pDuration, final float pFromAlpha, final float pToAlpha) { this(pDuration, pFromAlpha, pToAlpha, null, IEaseFunction.DEFAULT); } public AlphaModifier(final float pDuration, final float pFromAlpha, final float pToAlpha, final IEaseFunction pEaseFunction) { this(pDuration, pFromAlpha, pToAlpha, null, pEaseFunction); } public AlphaModifier(final float pDuration, final float pFromAlpha, final float pToAlpha, final IEntityModifierListener pEntityModifierListener) { super(pDuration, pFromAlpha, pToAlpha, pEntityModifierListener, IEaseFunction.DEFAULT); } public AlphaModifier(final float pDuration, final float pFromAlpha, final float pToAlpha, final IEntityModifierListener pEntityModifierListener, final IEaseFunction pEaseFunction) { super(pDuration, pFromAlpha, pToAlpha, pEntityModifierListener, pEaseFunction); } protected AlphaModifier(final AlphaModifier pAlphaModifier) { super(pAlphaModifier); } @Override public AlphaModifier deepCopy(){ return new AlphaModifier(this); } // =========================================================== // Getter & Setter // =========================================================== // =========================================================== // Methods for/from SuperClass/Interfaces // =========================================================== @Override protected void onSetInitialValue(final IEntity pEntity, final float pAlpha) { pEntity.setAlpha(pAlpha); } @Override protected void onSetValue(final IEntity pEntity, final float pPercentageDone, final float pAlpha) { pEntity.setAlpha(pAlpha); } // =========================================================== // Methods // =========================================================== // =========================================================== // Inner and Anonymous Classes // =========================================================== }
Java
package org.anddev.andengine.entity; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import javax.microedition.khronos.opengles.GL10; import org.anddev.andengine.engine.camera.Camera; import org.anddev.andengine.engine.handler.IUpdateHandler; import org.anddev.andengine.engine.handler.UpdateHandlerList; import org.anddev.andengine.entity.modifier.EntityModifierList; import org.anddev.andengine.entity.modifier.IEntityModifier; import org.anddev.andengine.entity.modifier.IEntityModifier.IEntityModifierMatcher; import org.anddev.andengine.util.ParameterCallable; import org.anddev.andengine.util.SmartList; import org.anddev.andengine.util.Transformation; import org.anddev.andengine.util.constants.Constants; /** * (c) 2010 Nicolas Gramlich * (c) 2011 Zynga Inc. * * @author Nicolas Gramlich * @since 12:00:48 - 08.03.2010 */ public class Entity implements IEntity { // =========================================================== // Constants // =========================================================== private static final int CHILDREN_CAPACITY_DEFAULT = 4; private static final int ENTITYMODIFIERS_CAPACITY_DEFAULT = 4; private static final int UPDATEHANDLERS_CAPACITY_DEFAULT = 4; private static final float[] VERTICES_SCENE_TO_LOCAL_TMP = new float[2]; private static final float[] VERTICES_LOCAL_TO_SCENE_TMP = new float[2]; private static final ParameterCallable<IEntity> PARAMETERCALLABLE_DETACHCHILD = new ParameterCallable<IEntity>() { @Override public void call(final IEntity pEntity) { pEntity.setParent(null); pEntity.onDetached(); } }; // =========================================================== // Fields // =========================================================== protected boolean mVisible = true; protected boolean mIgnoreUpdate = false; protected boolean mChildrenVisible = true; protected boolean mChildrenIgnoreUpdate = false; protected int mZIndex = 0; private IEntity mParent; protected SmartList<IEntity> mChildren; private EntityModifierList mEntityModifiers; private UpdateHandlerList mUpdateHandlers; protected float mRed = 1f; protected float mGreen = 1f; protected float mBlue = 1f; protected float mAlpha = 1f; protected float mX; protected float mY; private final float mInitialX; private final float mInitialY; protected float mRotation = 0; protected float mRotationCenterX = 0; protected float mRotationCenterY = 0; protected float mScaleX = 1f; protected float mScaleY = 1f; protected float mScaleCenterX = 0; protected float mScaleCenterY = 0; private boolean mLocalToParentTransformationDirty = true; private boolean mParentToLocalTransformationDirty = true; private final Transformation mLocalToParentTransformation = new Transformation(); private final Transformation mParentToLocalTransformation = new Transformation(); private final Transformation mLocalToSceneTransformation = new Transformation(); private final Transformation mSceneToLocalTransformation = new Transformation(); private Object mUserData; // =========================================================== // Constructors // =========================================================== public Entity() { this(0, 0); } public Entity(final float pX, final float pY) { this.mInitialX = pX; this.mInitialY = pY; this.mX = pX; this.mY = pY; } // =========================================================== // Getter & Setter // =========================================================== // =========================================================== // Methods for/from SuperClass/Interfaces // =========================================================== @Override public boolean isVisible() { return this.mVisible; } @Override public void setVisible(final boolean pVisible) { this.mVisible = pVisible; } @Override public boolean isChildrenVisible() { return this.mChildrenVisible; } @Override public void setChildrenVisible(final boolean pChildrenVisible) { this.mChildrenVisible = pChildrenVisible; } @Override public boolean isIgnoreUpdate() { return this.mIgnoreUpdate; } @Override public void setIgnoreUpdate(final boolean pIgnoreUpdate) { this.mIgnoreUpdate = pIgnoreUpdate; } @Override public boolean isChildrenIgnoreUpdate() { return this.mChildrenIgnoreUpdate; } @Override public void setChildrenIgnoreUpdate(final boolean pChildrenIgnoreUpdate) { this.mChildrenIgnoreUpdate = pChildrenIgnoreUpdate; } @Override public boolean hasParent() { return this.mParent != null; } @Override public IEntity getParent() { return this.mParent; } @Override public void setParent(final IEntity pEntity) { this.mParent = pEntity; } @Override public int getZIndex() { return this.mZIndex; } @Override public void setZIndex(final int pZIndex) { this.mZIndex = pZIndex; } @Override public float getX() { return this.mX; } @Override public float getY() { return this.mY; } @Override public float getInitialX() { return this.mInitialX; } @Override public float getInitialY() { return this.mInitialY; } @Override public void setPosition(final IEntity pOtherEntity) { this.setPosition(pOtherEntity.getX(), pOtherEntity.getY()); } @Override public void setPosition(final float pX, final float pY) { this.mX = pX; this.mY = pY; this.mLocalToParentTransformationDirty = true; this.mParentToLocalTransformationDirty = true; } @Override public void setInitialPosition() { this.mX = this.mInitialX; this.mY = this.mInitialY; this.mLocalToParentTransformationDirty = true; this.mParentToLocalTransformationDirty = true; } @Override public float getRotation() { return this.mRotation; } @Override public boolean isRotated() { return this.mRotation != 0; } @Override public void setRotation(final float pRotation) { this.mRotation = pRotation; this.mLocalToParentTransformationDirty = true; this.mParentToLocalTransformationDirty = true; } @Override public float getRotationCenterX() { return this.mRotationCenterX; } @Override public float getRotationCenterY() { return this.mRotationCenterY; } @Override public void setRotationCenterX(final float pRotationCenterX) { this.mRotationCenterX = pRotationCenterX; this.mLocalToParentTransformationDirty = true; this.mParentToLocalTransformationDirty = true; } @Override public void setRotationCenterY(final float pRotationCenterY) { this.mRotationCenterY = pRotationCenterY; this.mLocalToParentTransformationDirty = true; this.mParentToLocalTransformationDirty = true; } @Override public void setRotationCenter(final float pRotationCenterX, final float pRotationCenterY) { this.mRotationCenterX = pRotationCenterX; this.mRotationCenterY = pRotationCenterY; this.mLocalToParentTransformationDirty = true; this.mParentToLocalTransformationDirty = true; } @Override public boolean isScaled() { return this.mScaleX != 1 || this.mScaleY != 1; } @Override public float getScaleX() { return this.mScaleX; } @Override public float getScaleY() { return this.mScaleY; } @Override public void setScaleX(final float pScaleX) { this.mScaleX = pScaleX; this.mLocalToParentTransformationDirty = true; this.mParentToLocalTransformationDirty = true; } @Override public void setScaleY(final float pScaleY) { this.mScaleY = pScaleY; this.mLocalToParentTransformationDirty = true; this.mParentToLocalTransformationDirty = true; } @Override public void setScale(final float pScale) { this.mScaleX = pScale; this.mScaleY = pScale; this.mLocalToParentTransformationDirty = true; this.mParentToLocalTransformationDirty = true; } @Override public void setScale(final float pScaleX, final float pScaleY) { this.mScaleX = pScaleX; this.mScaleY = pScaleY; this.mLocalToParentTransformationDirty = true; this.mParentToLocalTransformationDirty = true; } @Override public float getScaleCenterX() { return this.mScaleCenterX; } @Override public float getScaleCenterY() { return this.mScaleCenterY; } @Override public void setScaleCenterX(final float pScaleCenterX) { this.mScaleCenterX = pScaleCenterX; this.mLocalToParentTransformationDirty = true; this.mParentToLocalTransformationDirty = true; } @Override public void setScaleCenterY(final float pScaleCenterY) { this.mScaleCenterY = pScaleCenterY; this.mLocalToParentTransformationDirty = true; this.mParentToLocalTransformationDirty = true; } @Override public void setScaleCenter(final float pScaleCenterX, final float pScaleCenterY) { this.mScaleCenterX = pScaleCenterX; this.mScaleCenterY = pScaleCenterY; this.mLocalToParentTransformationDirty = true; this.mParentToLocalTransformationDirty = true; } @Override public float getRed() { return this.mRed; } @Override public float getGreen() { return this.mGreen; } @Override public float getBlue() { return this.mBlue; } @Override public float getAlpha() { return this.mAlpha; } /** * @param pAlpha from <code>0.0f</code> (transparent) to <code>1.0f</code> (opaque) */ @Override public void setAlpha(final float pAlpha) { this.mAlpha = pAlpha; } /** * @param pRed from <code>0.0f</code> to <code>1.0f</code> * @param pGreen from <code>0.0f</code> to <code>1.0f</code> * @param pBlue from <code>0.0f</code> to <code>1.0f</code> */ @Override public void setColor(final float pRed, final float pGreen, final float pBlue) { this.mRed = pRed; this.mGreen = pGreen; this.mBlue = pBlue; } /** * @param pRed from <code>0.0f</code> to <code>1.0f</code> * @param pGreen from <code>0.0f</code> to <code>1.0f</code> * @param pBlue from <code>0.0f</code> to <code>1.0f</code> * @param pAlpha from <code>0.0f</code> (transparent) to <code>1.0f</code> (opaque) */ @Override public void setColor(final float pRed, final float pGreen, final float pBlue, final float pAlpha) { this.mRed = pRed; this.mGreen = pGreen; this.mBlue = pBlue; this.mAlpha = pAlpha; } @Override public int getChildCount() { if(this.mChildren == null) { return 0; } return this.mChildren.size(); } @Override public IEntity getChild(final int pIndex) { if(this.mChildren == null) { return null; } return this.mChildren.get(pIndex); } @Override public int getChildIndex(final IEntity pEntity) { if (this.mChildren == null || pEntity.getParent() != this) { return -1; } return this.mChildren.indexOf(pEntity); } @Override public boolean setChildIndex(final IEntity pEntity, final int pIndex) { if (this.mChildren == null || pEntity.getParent() != this) { return false; } try { this.mChildren.remove(pEntity); this.mChildren.add(pIndex, pEntity); return true; } catch (final IndexOutOfBoundsException e) { return false; } } @Override public IEntity getFirstChild() { if(this.mChildren == null) { return null; } return this.mChildren.get(0); } @Override public IEntity getLastChild() { if(this.mChildren == null) { return null; } return this.mChildren.get(this.mChildren.size() - 1); } @Override public boolean detachSelf() { final IEntity parent = this.mParent; if(parent != null) { return parent.detachChild(this); } else { return false; } } @Override public void detachChildren() { if(this.mChildren == null) { return; } this.mChildren.clear(PARAMETERCALLABLE_DETACHCHILD); } @Override public void attachChild(final IEntity pEntity) throws IllegalStateException { if(pEntity.hasParent()) { throw new IllegalStateException("pEntity already has a parent!"); } if(this.mChildren == null) { this.allocateChildren(); } this.mChildren.add(pEntity); pEntity.setParent(this); pEntity.onAttached(); } @Override public boolean attachChild(final IEntity pEntity, final int pIndex) throws IllegalStateException { if(pEntity.hasParent()) { throw new IllegalStateException("pEntity already has a parent!"); } if (this.mChildren == null) { this.allocateChildren(); } try { this.mChildren.add(pIndex, pEntity); pEntity.setParent(this); pEntity.onAttached(); return true; } catch (final IndexOutOfBoundsException e) { return false; } } @Override public IEntity findChild(final IEntityMatcher pEntityMatcher) { if(this.mChildren == null) { return null; } return this.mChildren.find(pEntityMatcher); } @Override public boolean swapChildren(final IEntity pEntityA, final IEntity pEntityB) { return this.swapChildren(this.getChildIndex(pEntityA), this.getChildIndex(pEntityB)); } @Override public boolean swapChildren(final int pIndexA, final int pIndexB) { try { Collections.swap(this.mChildren, pIndexA, pIndexB); return true; } catch (final IndexOutOfBoundsException e) { return false; } } @Override public void sortChildren() { if(this.mChildren == null) { return; } ZIndexSorter.getInstance().sort(this.mChildren); } @Override public void sortChildren(final Comparator<IEntity> pEntityComparator) { if(this.mChildren == null) { return; } ZIndexSorter.getInstance().sort(this.mChildren, pEntityComparator); } @Override public boolean detachChild(final IEntity pEntity) { if(this.mChildren == null) { return false; } return this.mChildren.remove(pEntity, PARAMETERCALLABLE_DETACHCHILD); } @Override public IEntity detachChild(final IEntityMatcher pEntityMatcher) { if(this.mChildren == null) { return null; } return this.mChildren.remove(pEntityMatcher, Entity.PARAMETERCALLABLE_DETACHCHILD); } @Override public boolean detachChildren(final IEntityMatcher pEntityMatcher) { if(this.mChildren == null) { return false; } return this.mChildren.removeAll(pEntityMatcher, Entity.PARAMETERCALLABLE_DETACHCHILD); } @Override public void callOnChildren(final IEntityCallable pEntityCallable) { if(this.mChildren == null) { return; } this.mChildren.call(pEntityCallable); } @Override public void callOnChildren(final IEntityMatcher pEntityMatcher, final IEntityCallable pEntityCallable) { if(this.mChildren == null) { return; } this.mChildren.call(pEntityMatcher, pEntityCallable); } @Override public void registerUpdateHandler(final IUpdateHandler pUpdateHandler) { if(this.mUpdateHandlers == null) { this.allocateUpdateHandlers(); } this.mUpdateHandlers.add(pUpdateHandler); } @Override public boolean unregisterUpdateHandler(final IUpdateHandler pUpdateHandler) { if(this.mUpdateHandlers == null) { return false; } return this.mUpdateHandlers.remove(pUpdateHandler); } @Override public boolean unregisterUpdateHandlers(final IUpdateHandlerMatcher pUpdateHandlerMatcher) { if(this.mUpdateHandlers == null) { return false; } return this.mUpdateHandlers.removeAll(pUpdateHandlerMatcher); } @Override public void clearUpdateHandlers() { if(this.mUpdateHandlers == null) { return; } this.mUpdateHandlers.clear(); } @Override public void registerEntityModifier(final IEntityModifier pEntityModifier) { if(this.mEntityModifiers == null) { this.allocateEntityModifiers(); } this.mEntityModifiers.add(pEntityModifier); } @Override public boolean unregisterEntityModifier(final IEntityModifier pEntityModifier) { if(this.mEntityModifiers == null) { return false; } return this.mEntityModifiers.remove(pEntityModifier); } @Override public boolean unregisterEntityModifiers(final IEntityModifierMatcher pEntityModifierMatcher) { if(this.mEntityModifiers == null) { return false; } return this.mEntityModifiers.removeAll(pEntityModifierMatcher); } @Override public void clearEntityModifiers() { if(this.mEntityModifiers == null) { return; } this.mEntityModifiers.clear(); } @Override public float[] getSceneCenterCoordinates() { return this.convertLocalToSceneCoordinates(0, 0); } public Transformation getLocalToParentTransformation() { final Transformation localToParentTransformation = this.mLocalToParentTransformation; if(this.mLocalToParentTransformationDirty) { localToParentTransformation.setToIdentity(); /* Scale. */ final float scaleX = this.mScaleX; final float scaleY = this.mScaleY; if(scaleX != 1 || scaleY != 1) { final float scaleCenterX = this.mScaleCenterX; final float scaleCenterY = this.mScaleCenterY; /* TODO Check if it is worth to check for scaleCenterX == 0 && scaleCenterY == 0 as the two postTranslate can be saved. * The same obviously applies for all similar occurrences of this pattern in this class. */ localToParentTransformation.postTranslate(-scaleCenterX, -scaleCenterY); localToParentTransformation.postScale(scaleX, scaleY); localToParentTransformation.postTranslate(scaleCenterX, scaleCenterY); } /* TODO There is a special, but very likely case when mRotationCenter and mScaleCenter are the same. * In that case the last postTranslate of the scale and the first postTranslate of the rotation is superfluous. */ /* Rotation. */ final float rotation = this.mRotation; if(rotation != 0) { final float rotationCenterX = this.mRotationCenterX; final float rotationCenterY = this.mRotationCenterY; localToParentTransformation.postTranslate(-rotationCenterX, -rotationCenterY); localToParentTransformation.postRotate(rotation); localToParentTransformation.postTranslate(rotationCenterX, rotationCenterY); } /* Translation. */ localToParentTransformation.postTranslate(this.mX, this.mY); this.mLocalToParentTransformationDirty = false; } return localToParentTransformation; } public Transformation getParentToLocalTransformation() { final Transformation parentToLocalTransformation = this.mParentToLocalTransformation; if(this.mParentToLocalTransformationDirty) { parentToLocalTransformation.setToIdentity(); /* Translation. */ parentToLocalTransformation.postTranslate(-this.mX, -this.mY); /* Rotation. */ final float rotation = this.mRotation; if(rotation != 0) { final float rotationCenterX = this.mRotationCenterX; final float rotationCenterY = this.mRotationCenterY; parentToLocalTransformation.postTranslate(-rotationCenterX, -rotationCenterY); parentToLocalTransformation.postRotate(-rotation); parentToLocalTransformation.postTranslate(rotationCenterX, rotationCenterY); } /* TODO There is a special, but very likely case when mRotationCenter and mScaleCenter are the same. * In that case the last postTranslate of the rotation and the first postTranslate of the scale is superfluous. */ /* Scale. */ final float scaleX = this.mScaleX; final float scaleY = this.mScaleY; if(scaleX != 1 || scaleY != 1) { final float scaleCenterX = this.mScaleCenterX; final float scaleCenterY = this.mScaleCenterY; parentToLocalTransformation.postTranslate(-scaleCenterX, -scaleCenterY); parentToLocalTransformation.postScale(1 / scaleX, 1 / scaleY); parentToLocalTransformation.postTranslate(scaleCenterX, scaleCenterY); } this.mParentToLocalTransformationDirty = false; } return parentToLocalTransformation; } @Override public Transformation getLocalToSceneTransformation() { // TODO Cache if parent(recursive) not dirty. final Transformation localToSceneTransformation = this.mLocalToSceneTransformation; localToSceneTransformation.setTo(this.getLocalToParentTransformation()); final IEntity parent = this.mParent; if(parent != null) { localToSceneTransformation.postConcat(parent.getLocalToSceneTransformation()); } return localToSceneTransformation; } @Override public Transformation getSceneToLocalTransformation() { // TODO Cache if parent(recursive) not dirty. final Transformation sceneToLocalTransformation = this.mSceneToLocalTransformation; sceneToLocalTransformation.setTo(this.getParentToLocalTransformation()); final IEntity parent = this.mParent; if(parent != null) { sceneToLocalTransformation.postConcat(parent.getSceneToLocalTransformation()); } return sceneToLocalTransformation; } /* (non-Javadoc) * @see org.anddev.andengine.entity.IEntity#convertLocalToSceneCoordinates(float, float) */ @Override public float[] convertLocalToSceneCoordinates(final float pX, final float pY) { return this.convertLocalToSceneCoordinates(pX, pY, VERTICES_LOCAL_TO_SCENE_TMP); } /* (non-Javadoc) * @see org.anddev.andengine.entity.IEntity#convertLocalToSceneCoordinates(float, float, float[]) */ @Override public float[] convertLocalToSceneCoordinates(final float pX, final float pY, final float[] pReuse) { pReuse[Constants.VERTEX_INDEX_X] = pX; pReuse[Constants.VERTEX_INDEX_Y] = pY; this.getLocalToSceneTransformation().transform(pReuse); return pReuse; } /* (non-Javadoc) * @see org.anddev.andengine.entity.IEntity#convertLocalToSceneCoordinates(float[]) */ @Override public float[] convertLocalToSceneCoordinates(final float[] pCoordinates) { return this.convertSceneToLocalCoordinates(pCoordinates, VERTICES_LOCAL_TO_SCENE_TMP); } /* (non-Javadoc) * @see org.anddev.andengine.entity.IEntity#convertLocalToSceneCoordinates(float[], float[]) */ @Override public float[] convertLocalToSceneCoordinates(final float[] pCoordinates, final float[] pReuse) { pReuse[Constants.VERTEX_INDEX_X] = pCoordinates[Constants.VERTEX_INDEX_X]; pReuse[Constants.VERTEX_INDEX_Y] = pCoordinates[Constants.VERTEX_INDEX_Y]; this.getLocalToSceneTransformation().transform(pReuse); return pReuse; } /* (non-Javadoc) * @see org.anddev.andengine.entity.IEntity#convertSceneToLocalCoordinates(float, float) */ @Override public float[] convertSceneToLocalCoordinates(final float pX, final float pY) { return this.convertSceneToLocalCoordinates(pX, pY, VERTICES_SCENE_TO_LOCAL_TMP); } /* (non-Javadoc) * @see org.anddev.andengine.entity.IEntity#convertSceneToLocalCoordinates(float, float, float[]) */ @Override public float[] convertSceneToLocalCoordinates(final float pX, final float pY, final float[] pReuse) { pReuse[Constants.VERTEX_INDEX_X] = pX; pReuse[Constants.VERTEX_INDEX_Y] = pY; this.getSceneToLocalTransformation().transform(pReuse); return pReuse; } /* (non-Javadoc) * @see org.anddev.andengine.entity.IEntity#convertSceneToLocalCoordinates(float[]) */ @Override public float[] convertSceneToLocalCoordinates(final float[] pCoordinates) { return this.convertSceneToLocalCoordinates(pCoordinates, VERTICES_SCENE_TO_LOCAL_TMP); } /* (non-Javadoc) * @see org.anddev.andengine.entity.IEntity#convertSceneToLocalCoordinates(float[], float[]) */ @Override public float[] convertSceneToLocalCoordinates(final float[] pCoordinates, final float[] pReuse) { pReuse[Constants.VERTEX_INDEX_X] = pCoordinates[Constants.VERTEX_INDEX_X]; pReuse[Constants.VERTEX_INDEX_Y] = pCoordinates[Constants.VERTEX_INDEX_Y]; this.getSceneToLocalTransformation().transform(pReuse); return pReuse; } @Override public void onAttached() { } @Override public void onDetached() { } @Override public Object getUserData() { return this.mUserData; } @Override public void setUserData(final Object pUserData) { this.mUserData = pUserData; } @Override public final void onDraw(final GL10 pGL, final Camera pCamera) { if(this.mVisible) { this.onManagedDraw(pGL, pCamera); } } @Override public final void onUpdate(final float pSecondsElapsed) { if(!this.mIgnoreUpdate) { this.onManagedUpdate(pSecondsElapsed); } } @Override public void reset() { this.mVisible = true; this.mIgnoreUpdate = false; this.mChildrenVisible = true; this.mChildrenIgnoreUpdate = false; this.mX = this.mInitialX; this.mY = this.mInitialY; this.mRotation = 0; this.mScaleX = 1; this.mScaleY = 1; this.mRed = 1.0f; this.mGreen = 1.0f; this.mBlue = 1.0f; this.mAlpha = 1.0f; if(this.mEntityModifiers != null) { this.mEntityModifiers.reset(); } if(this.mChildren != null) { final ArrayList<IEntity> entities = this.mChildren; for(int i = entities.size() - 1; i >= 0; i--) { entities.get(i).reset(); } } } // =========================================================== // Methods // =========================================================== /** * @param pGL the OpenGL GL1.0 Context (potentially higher than 1.0) to use for drawing. * @param pCamera the currently active {@link Camera} i.e. to be used for culling. */ protected void doDraw(final GL10 pGL, final Camera pCamera) { } private void allocateEntityModifiers() { this.mEntityModifiers = new EntityModifierList(this, Entity.ENTITYMODIFIERS_CAPACITY_DEFAULT); } private void allocateChildren() { this.mChildren = new SmartList<IEntity>(Entity.CHILDREN_CAPACITY_DEFAULT); } private void allocateUpdateHandlers() { this.mUpdateHandlers = new UpdateHandlerList(Entity.UPDATEHANDLERS_CAPACITY_DEFAULT); } protected void onApplyTransformations(final GL10 pGL) { /* Translation. */ this.applyTranslation(pGL); /* Rotation. */ this.applyRotation(pGL); /* Scale. */ this.applyScale(pGL); } protected void applyTranslation(final GL10 pGL) { pGL.glTranslatef(this.mX, this.mY, 0); } protected void applyRotation(final GL10 pGL) { final float rotation = this.mRotation; if(rotation != 0) { final float rotationCenterX = this.mRotationCenterX; final float rotationCenterY = this.mRotationCenterY; pGL.glTranslatef(rotationCenterX, rotationCenterY, 0); pGL.glRotatef(rotation, 0, 0, 1); pGL.glTranslatef(-rotationCenterX, -rotationCenterY, 0); /* TODO There is a special, but very likely case when mRotationCenter and mScaleCenter are the same. * In that case the last glTranslatef of the rotation and the first glTranslatef of the scale is superfluous. * The problem is that applyRotation and applyScale would need to be "merged" in order to efficiently check for that condition. */ } } protected void applyScale(final GL10 pGL) { final float scaleX = this.mScaleX; final float scaleY = this.mScaleY; if(scaleX != 1 || scaleY != 1) { final float scaleCenterX = this.mScaleCenterX; final float scaleCenterY = this.mScaleCenterY; pGL.glTranslatef(scaleCenterX, scaleCenterY, 0); pGL.glScalef(scaleX, scaleY, 1); pGL.glTranslatef(-scaleCenterX, -scaleCenterY, 0); } } protected void onManagedDraw(final GL10 pGL, final Camera pCamera) { pGL.glPushMatrix(); { this.onApplyTransformations(pGL); this.doDraw(pGL, pCamera); this.onDrawChildren(pGL, pCamera); } pGL.glPopMatrix(); } protected void onDrawChildren(final GL10 pGL, final Camera pCamera) { if(this.mChildren != null && this.mChildrenVisible) { this.onManagedDrawChildren(pGL, pCamera); } } public void onManagedDrawChildren(final GL10 pGL, final Camera pCamera) { final ArrayList<IEntity> children = this.mChildren; final int childCount = children.size(); for(int i = 0; i < childCount; i++) { children.get(i).onDraw(pGL, pCamera); } } protected void onManagedUpdate(final float pSecondsElapsed) { if(this.mEntityModifiers != null) { this.mEntityModifiers.onUpdate(pSecondsElapsed); } if(this.mUpdateHandlers != null) { this.mUpdateHandlers.onUpdate(pSecondsElapsed); } if(this.mChildren != null && !this.mChildrenIgnoreUpdate) { final ArrayList<IEntity> entities = this.mChildren; final int entityCount = entities.size(); for(int i = 0; i < entityCount; i++) { entities.get(i).onUpdate(pSecondsElapsed); } } } // =========================================================== // Inner and Anonymous Classes // =========================================================== }
Java
package org.anddev.andengine.entity.text; import javax.microedition.khronos.opengles.GL10; import javax.microedition.khronos.opengles.GL11; import org.anddev.andengine.engine.camera.Camera; import org.anddev.andengine.entity.shape.RectangularShape; import org.anddev.andengine.opengl.font.Font; import org.anddev.andengine.opengl.texture.buffer.TextTextureBuffer; import org.anddev.andengine.opengl.util.GLHelper; import org.anddev.andengine.opengl.vertex.TextVertexBuffer; import org.anddev.andengine.util.HorizontalAlign; import org.anddev.andengine.util.StringUtils; /** * (c) 2010 Nicolas Gramlich * (c) 2011 Zynga Inc. * * @author Nicolas Gramlich * @since 10:54:59 - 03.04.2010 */ public class Text extends RectangularShape { // =========================================================== // Constants // =========================================================== // =========================================================== // Fields // =========================================================== private final TextTextureBuffer mTextTextureBuffer; private String mText; private String[] mLines; private int[] mWidths; private final Font mFont; private int mMaximumLineWidth; protected final int mCharactersMaximum; protected final int mVertexCount; // =========================================================== // Constructors // =========================================================== public Text(final float pX, final float pY, final Font pFont, final String pText) { this(pX, pY, pFont, pText, HorizontalAlign.LEFT); } public Text(final float pX, final float pY, final Font pFont, final String pText, final HorizontalAlign pHorizontalAlign) { this(pX, pY, pFont, pText, pHorizontalAlign, pText.length() - StringUtils.countOccurrences(pText, '\n')); } protected Text(final float pX, final float pY, final Font pFont, final String pText, final HorizontalAlign pHorizontalAlign, final int pCharactersMaximum) { super(pX, pY, 0, 0, new TextVertexBuffer(pCharactersMaximum, pHorizontalAlign, GL11.GL_STATIC_DRAW, true)); this.mCharactersMaximum = pCharactersMaximum; this.mVertexCount = TextVertexBuffer.VERTICES_PER_CHARACTER * this.mCharactersMaximum; this.mTextTextureBuffer = new TextTextureBuffer(2 * this.mVertexCount, GL11.GL_STATIC_DRAW, true); this.mFont = pFont; this.updateText(pText); this.initBlendFunction(); } protected void updateText(final String pText) { this.mText = pText; final Font font = this.mFont; this.mLines = StringUtils.split(this.mText, '\n', this.mLines); final String[] lines = this.mLines; final int lineCount = lines.length; final boolean widthsReusable = this.mWidths != null && this.mWidths.length == lineCount; if(!widthsReusable) { this.mWidths = new int[lineCount]; } final int[] widths = this.mWidths; int maximumLineWidth = 0; for (int i = lineCount - 1; i >= 0; i--) { widths[i] = font.getStringWidth(lines[i]); maximumLineWidth = Math.max(maximumLineWidth, widths[i]); } this.mMaximumLineWidth = maximumLineWidth; super.mWidth = this.mMaximumLineWidth; final float width = super.mWidth; super.mBaseWidth = width; super.mHeight = lineCount * font.getLineHeight() + (lineCount - 1) * font.getLineGap(); final float height = super.mHeight; super.mBaseHeight = height; this.mRotationCenterX = width * 0.5f; this.mRotationCenterY = height * 0.5f; this.mScaleCenterX = this.mRotationCenterX; this.mScaleCenterY = this.mRotationCenterY; this.mTextTextureBuffer.update(font, lines); this.updateVertexBuffer(); } // =========================================================== // Getter & Setter // =========================================================== public String getText() { return this.mText; } public int getCharactersMaximum() { return this.mCharactersMaximum; } @Override public TextVertexBuffer getVertexBuffer() { return (TextVertexBuffer)this.mVertexBuffer; } // =========================================================== // Methods for/from SuperClass/Interfaces // =========================================================== @Override protected void onInitDraw(final GL10 pGL) { super.onInitDraw(pGL); GLHelper.enableTextures(pGL); GLHelper.enableTexCoordArray(pGL); } @Override protected void drawVertices(final GL10 pGL, final Camera pCamera) { pGL.glDrawArrays(GL10.GL_TRIANGLES, 0, this.mVertexCount); } @Override protected void onUpdateVertexBuffer() { final Font font = this.mFont; if(font != null) { this.getVertexBuffer().update(font, this.mMaximumLineWidth, this.mWidths, this.mLines); } } @Override protected void onApplyTransformations(final GL10 pGL) { super.onApplyTransformations(pGL); this.applyTexture(pGL); } @Override protected void finalize() throws Throwable { super.finalize(); if(this.mTextTextureBuffer.isManaged()) { this.mTextTextureBuffer.unloadFromActiveBufferObjectManager(); } } // =========================================================== // Methods // =========================================================== private void initBlendFunction() { if(this.mFont.getTexture().getTextureOptions().mPreMultipyAlpha) { this.setBlendFunction(BLENDFUNCTION_SOURCE_PREMULTIPLYALPHA_DEFAULT, BLENDFUNCTION_DESTINATION_PREMULTIPLYALPHA_DEFAULT); } } private void applyTexture(final GL10 pGL) { if(GLHelper.EXTENSIONS_VERTEXBUFFEROBJECTS) { final GL11 gl11 = (GL11)pGL; this.mTextTextureBuffer.selectOnHardware(gl11); this.mFont.getTexture().bind(pGL); GLHelper.texCoordZeroPointer(gl11); } else { this.mFont.getTexture().bind(pGL); GLHelper.texCoordPointer(pGL, this.mTextTextureBuffer.getFloatBuffer()); } } // =========================================================== // Inner and Anonymous Classes // =========================================================== }
Java
package org.anddev.andengine.entity.text; import javax.microedition.khronos.opengles.GL10; import org.anddev.andengine.engine.camera.Camera; import org.anddev.andengine.opengl.font.Font; import org.anddev.andengine.opengl.vertex.TextVertexBuffer; import org.anddev.andengine.util.HorizontalAlign; import org.anddev.andengine.util.StringUtils; /** * (c) 2010 Nicolas Gramlich * (c) 2011 Zynga Inc. * * @author Nicolas Gramlich * @since 18:07:06 - 08.07.2010 */ public class ChangeableText extends Text { // =========================================================== // Constants // =========================================================== private static final String ELLIPSIS = "..."; private static final int ELLIPSIS_CHARACTER_COUNT = ELLIPSIS.length(); // =========================================================== // Fields // =========================================================== private int mCharacterCountCurrentText; // =========================================================== // Constructors // =========================================================== public ChangeableText(final float pX, final float pY, final Font pFont, final String pText) { this(pX, pY, pFont, pText, pText.length() - StringUtils.countOccurrences(pText, '\n')); } public ChangeableText(final float pX, final float pY, final Font pFont, final String pText, final int pCharactersMaximum) { this(pX, pY, pFont, pText, HorizontalAlign.LEFT, pCharactersMaximum); } public ChangeableText(final float pX, final float pY, final Font pFont, final String pText, final HorizontalAlign pHorizontalAlign, final int pCharactersMaximum) { super(pX, pY, pFont, pText, pHorizontalAlign, pCharactersMaximum); this.mCharacterCountCurrentText = pText.length() - StringUtils.countOccurrences(pText, '\n'); } // =========================================================== // Getter & Setter // =========================================================== public void setText(final String pText) { this.setText(pText, false); } /** * @param pText * @param pAllowEllipsis in the case pText is longer than <code>pCharactersMaximum</code>, * which was passed to the constructor, the displayed text will end with an ellipsis ("..."). */ public void setText(final String pText, final boolean pAllowEllipsis) { final int textCharacterCount = pText.length() - StringUtils.countOccurrences(pText, '\n'); if(textCharacterCount > this.mCharactersMaximum) { if(pAllowEllipsis && this.mCharactersMaximum > ELLIPSIS_CHARACTER_COUNT) { this.updateText(pText.substring(0, this.mCharactersMaximum - ELLIPSIS_CHARACTER_COUNT).concat(ELLIPSIS)); // TODO This allocation could maybe be avoided... } else { this.updateText(pText.substring(0, this.mCharactersMaximum)); // TODO This allocation could be avoided... } this.mCharacterCountCurrentText = this.mCharactersMaximum; } else { this.updateText(pText); this.mCharacterCountCurrentText = textCharacterCount; } } // =========================================================== // Methods for/from SuperClass/Interfaces // =========================================================== @Override protected void drawVertices(final GL10 pGL, final Camera pCamera) { pGL.glDrawArrays(GL10.GL_TRIANGLES, 0, this.mCharacterCountCurrentText * TextVertexBuffer.VERTICES_PER_CHARACTER); } // =========================================================== // Methods // =========================================================== // =========================================================== // Inner and Anonymous Classes // =========================================================== }
Java