org.andengine.entity.IEntity Java Examples

The following examples show how to use org.andengine.entity.IEntity. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: QuadraticBezierCurveMoveModifier.java    From 30-android-libraries-in-30-days with Apache License 2.0 6 votes vote down vote up
@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) + ((tt) * 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);
}
 
Example #2
Source File: PhysicsHandler.java    From 30-android-libraries-in-30-days with Apache License 2.0 6 votes vote down vote up
@Override
protected void onUpdate(final float pSecondsElapsed, final IEntity pEntity) {
	if(this.mEnabled) {
		/* Apply linear acceleration. */
		final float accelerationX = this.mAccelerationX;
		final float accelerationY = this.mAccelerationY;
		if(accelerationX != 0 || accelerationY != 0) {
			this.mVelocityX += accelerationX * pSecondsElapsed;
			this.mVelocityY += accelerationY * pSecondsElapsed;
		}

		/* Apply angular velocity. */
		final float angularVelocity = this.mAngularVelocity;
		if(angularVelocity != 0) {
			pEntity.setRotation(pEntity.getRotation() + angularVelocity * pSecondsElapsed);
		}

		/* Apply linear velocity. */
		final float velocityX = this.mVelocityX;
		final float velocityY = this.mVelocityY;
		if(velocityX != 0 || velocityY != 0) {
			pEntity.setPosition(pEntity.getX() + velocityX * pSecondsElapsed, pEntity.getY() + velocityY * pSecondsElapsed);
		}
	}
}
 
Example #3
Source File: SpriteBatch.java    From 30-android-libraries-in-30-days with Apache License 2.0 6 votes vote down vote up
/**
 * @see {@link SpriteBatchVertexBufferObject#add(ITextureRegion, float, float, float, float, float)} {@link SpriteBatchVertexBufferObject#add(ITextureRegion, float, float, Transformation, float, float, float, float)}.
 */
public void draw(final ITextureRegion pTextureRegion, final IEntity pEntity, final float pWidth, final float pHeight, final float pColorABGRPackedInt) {
	if(pEntity.isVisible()) {
		this.assertCapacity();

		this.assertTexture(pTextureRegion);

		if(pEntity.isRotatedOrScaledOrSkewed()) {
			this.addWithPackedColor(pTextureRegion, pWidth, pHeight, pEntity.getLocalToParentTransformation(), pColorABGRPackedInt);
		} else {
			this.addWithPackedColor(pTextureRegion, pEntity.getX(), pEntity.getY(), pWidth, pHeight, pColorABGRPackedInt);
		}

		this.mIndex++;
	}
}
 
Example #4
Source File: PhysicsConnector.java    From tilt-game-android with MIT License 6 votes vote down vote up
@Override
public void onUpdate(final float pSecondsElapsed) {
	final IEntity entity = this.mEntity;
	final Body body = this.mBody;

	if (this.mUpdatePosition) {
		final Vector2 position = body.getPosition();
		final float pixelToMeterRatio = this.mPixelToMeterRatio;
		entity.setPosition(position.x * pixelToMeterRatio, position.y * pixelToMeterRatio);
	}

	if (this.mUpdateRotation) {
		final float angle = body.getAngle();
		entity.setRotation(-MathUtils.radToDeg(angle));
	}
}
 
Example #5
Source File: LevelParser.java    From 30-android-libraries-in-30-days with Apache License 2.0 6 votes vote down vote up
@Override
public void startElement(final String pUri, final String pLocalName, final String pQualifiedName, final Attributes pAttributes) throws SAXException {
	final String entityName = pLocalName;

	final IEntity parent = (this.mParentEntityStack.isEmpty()) ? null : this.mParentEntityStack.getLast();

	final IEntityLoader entityLoader = this.mEntityLoaders.get(entityName);

	final IEntity entity;
	if(entityLoader != null) {
		entity = entityLoader.onLoadEntity(entityName, pAttributes);
	} else if(this.mDefaultEntityLoader != null) {
		entity = this.mDefaultEntityLoader.onLoadEntity(entityName, pAttributes);
	} else {
		throw new IllegalArgumentException("Unexpected tag: '" + entityName + "'.");
	}

	if(parent != null && entity != null) {
		parent.attachChild(entity);
	}

	this.mParentEntityStack.addLast(entity);
}
 
Example #6
Source File: PhysicsHandler.java    From tilt-game-android with MIT License 6 votes vote down vote up
@Override
protected void onUpdate(final float pSecondsElapsed, final IEntity pEntity) {
	if (this.mEnabled) {
		/* Apply linear acceleration. */
		final float accelerationX = this.mAccelerationX;
		final float accelerationY = this.mAccelerationY;
		if (accelerationX != 0 || accelerationY != 0) {
			this.mVelocityX += accelerationX * pSecondsElapsed;
			this.mVelocityY += accelerationY * pSecondsElapsed;
		}

		/* Apply angular velocity. */
		final float angularVelocity = this.mAngularVelocity;
		if (angularVelocity != 0) {
			pEntity.setRotation(pEntity.getRotation() + angularVelocity * pSecondsElapsed);
		}

		/* Apply linear velocity. */
		final float velocityX = this.mVelocityX;
		final float velocityY = this.mVelocityY;
		if (velocityX != 0 || velocityY != 0) {
			pEntity.setPosition(pEntity.getX() + velocityX * pSecondsElapsed, pEntity.getY() + velocityY * pSecondsElapsed);
		}
	}
}
 
Example #7
Source File: PhysicsConnectorManager.java    From tilt-game-android with MIT License 5 votes vote down vote up
public PhysicsConnector findPhysicsConnectorByShape(final IEntity pShape) {
	final ArrayList<PhysicsConnector> physicsConnectors = this;
	for (int i = physicsConnectors.size() - 1; i >= 0; i--) {
		final PhysicsConnector physicsConnector = physicsConnectors.get(i);
		if (physicsConnector.mEntity == pShape) {
			return physicsConnector;
		}
	}
	return null;
}
 
Example #8
Source File: SpriteBatch.java    From tilt-game-android with MIT License 5 votes vote down vote up
public void drawWithoutChecks(final ITextureRegion pTextureRegion, final IEntity pEntity, final float pRed, final float pGreen, final float pBlue, final float pAlpha) {
	if (pEntity.isVisible()) {
		if (pEntity.isRotatedOrScaledOrSkewed()) {
			this.add(pTextureRegion, pEntity.getWidth(), pEntity.getHeight(), pEntity.getLocalToParentTransformation(), pRed, pGreen, pBlue, pAlpha);
		} else {
			this.add(pTextureRegion, pEntity.getX(), pEntity.getY(), pEntity.getWidth(), pEntity.getHeight(), pRed, pGreen, pBlue, pAlpha);
		}

		this.mIndex++;
	}
}
 
Example #9
Source File: ParallaxBackground.java    From tilt-game-android with MIT License 5 votes vote down vote up
public ParallaxEntity(final float pParallaxFactor, final IEntity pEntity) {
	this.mParallaxFactor = pParallaxFactor;
	this.mEntity = pEntity;

	// TODO Adjust onDraw calculations, so that these assumptions aren't necessary.
	if (this.mEntity.getX() != 0) {
		Debug.w("The X position of a " + this.getClass().getSimpleName() + " is expected to be 0.");
	}

	if (this.mEntity.getOffsetCenterX() != 0) {
		Debug.w("The OffsetCenterXposition of a " + this.getClass().getSimpleName() + " is expected to be 0.");
	}
}
 
Example #10
Source File: SpriteGroup.java    From 30-android-libraries-in-30-days with Apache License 2.0 5 votes vote down vote up
/**
 * Instead use {@link SpriteGroup#attachChild(BaseSprite)}.
 */
@Override
@Deprecated
public void attachChild(final IEntity pEntity) throws IllegalArgumentException {
	if(pEntity instanceof Sprite) {
		this.attachChild((Sprite)pEntity);
	} else {
		throw new IllegalArgumentException("A " + SpriteGroup.class.getSimpleName() + " can only handle children of type Sprite or subclasses of Sprite, like TiledSprite or AnimatedSprite.");
	}
}
 
Example #11
Source File: EntityDetachRunnablePoolUpdateHandler.java    From tilt-game-android with MIT License 5 votes vote down vote up
/**
 * @param pEntity the @{link IEntity} to be detached safely.
 * @param pCallback will be called after the @{link IEntity} actually was detached.
 */
public void scheduleDetach(final IEntity pEntity, final Callback<IEntity> pCallback) {
	final EntityDetachRunnablePoolItem entityDetachRunnablePoolItem = this.obtainPoolItem();
	entityDetachRunnablePoolItem.setEntity(pEntity);
	entityDetachRunnablePoolItem.setCallback(pCallback);
	this.postPoolItem(entityDetachRunnablePoolItem);
}
 
Example #12
Source File: PhysicsFactory.java    From tilt-game-android with MIT License 5 votes vote down vote up
@SuppressWarnings("deprecation")
public static Body createBoxBody(final PhysicsWorld pPhysicsWorld, final IEntity pEntity, final BodyType pBodyType, final FixtureDef pFixtureDef, final float pPixelToMeterRatio) {
	final float[] sceneCenterCoordinates = pEntity.getSceneCenterCoordinates();
	final float centerX = sceneCenterCoordinates[Constants.VERTEX_INDEX_X];
	final float centerY = sceneCenterCoordinates[Constants.VERTEX_INDEX_Y];
	return PhysicsFactory.createBoxBody(pPhysicsWorld, centerX, centerY, pEntity.getWidthScaled(), pEntity.getHeightScaled(), pEntity.getRotation(), pBodyType, pFixtureDef, pPixelToMeterRatio);
}
 
Example #13
Source File: SpriteBatch.java    From 30-android-libraries-in-30-days with Apache License 2.0 5 votes vote down vote up
public void drawWithoutChecks(final ITextureRegion pTextureRegion, final IEntity pEntity, final float pWidth, final float pHeight, final float pRed, final float pGreen, final float pBlue, final float pAlpha) {
	if(pEntity.isVisible()) {
		if(pEntity.isRotatedOrScaledOrSkewed()) {
			this.add(pTextureRegion, pWidth, pHeight, pEntity.getLocalToParentTransformation(), pRed, pGreen, pBlue, pAlpha);
		} else {
			this.add(pTextureRegion, pEntity.getX(), pEntity.getY(), pWidth, pHeight, pRed, pGreen, pBlue, pAlpha);
		}

		this.mIndex++;
	}
}
 
Example #14
Source File: JumpModifier.java    From 30-android-libraries-in-30-days with Apache License 2.0 5 votes vote down vote up
@Override
protected void onSetValues(final IEntity pEntity, final float pPercentageDone, final float pX, final float pY) {
	final float fraction = (pPercentageDone * this.mJumpCount) % 1.0f;
	final float deltaY = this.mJumpHeight * 4 * fraction * (1 - fraction);

	super.onSetValues(pEntity, pPercentageDone, pX, pY - deltaY);
}
 
Example #15
Source File: BaseMenuItemDecorator.java    From tilt-game-android with MIT License 4 votes vote down vote up
@Override
public IEntity getChildByTag(final int pTag) {
	return this.mMenuItem.getChildByTag(pTag);
}
 
Example #16
Source File: BaseEntityUpdateHandler.java    From 30-android-libraries-in-30-days with Apache License 2.0 4 votes vote down vote up
public BaseEntityUpdateHandler(final IEntity pEntity) {
	this.mEntity = pEntity;
}
 
Example #17
Source File: BaseMenuItemDecorator.java    From tilt-game-android with MIT License 4 votes vote down vote up
@Override
public ArrayList<IEntity> query(final IEntityMatcher pEntityMatcher) {
	return this.mMenuItem.query(pEntityMatcher);
}
 
Example #18
Source File: BaseMenuItemDecorator.java    From 30-android-libraries-in-30-days with Apache License 2.0 4 votes vote down vote up
@Override
public IEntity getParent() {
	return this.mMenuItem.getParent();
}
 
Example #19
Source File: BaseMenuItemDecorator.java    From 30-android-libraries-in-30-days with Apache License 2.0 4 votes vote down vote up
@Override
public void setParent(final IEntity pEntity) {
	this.mMenuItem.setParent(pEntity);
}
 
Example #20
Source File: PathModifier.java    From tilt-game-android with MIT License 4 votes vote down vote up
@Override
public float onUpdate(final float pSecondsElapsed, final IEntity pEntity) {
	return this.mSequenceModifier.onUpdate(pSecondsElapsed, pEntity);
}
 
Example #21
Source File: BaseMenuItemDecorator.java    From tilt-game-android with MIT License 4 votes vote down vote up
@Override
public void attachChild(final IEntity pEntity) {
	this.mMenuItem.attachChild(pEntity);
}
 
Example #22
Source File: PathModifier.java    From tilt-game-android with MIT License 4 votes vote down vote up
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], coordinatesY[i], coordinatesX[i + 1], 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
	);
}
 
Example #23
Source File: BaseMenuItemDecorator.java    From 30-android-libraries-in-30-days with Apache License 2.0 4 votes vote down vote up
@Override
public <L extends List<S>, S extends IEntity> L queryForSubclass(final IEntityMatcher pEntityMatcher, final L pResult) throws ClassCastException {
	return this.mMenuItem.queryForSubclass(pEntityMatcher, pResult);
}
 
Example #24
Source File: SkewXModifier.java    From tilt-game-android with MIT License 4 votes vote down vote up
@Override
protected void onSetValue(final IEntity pEntity, final float pPercentageDone, final float pSkewX) {
	pEntity.setSkewX(pSkewX);
}
 
Example #25
Source File: BaseEntityUpdateHandler.java    From tilt-game-android with MIT License 4 votes vote down vote up
public void setEntity(final IEntity pEntity) {
	this.mEntity = pEntity;
}
 
Example #26
Source File: BaseMenuItemDecorator.java    From tilt-game-android with MIT License 4 votes vote down vote up
@Override
public IEntity getParent() {
	return this.mMenuItem.getParent();
}
 
Example #27
Source File: RotationModifier.java    From 30-android-libraries-in-30-days with Apache License 2.0 4 votes vote down vote up
@Override
protected void onSetValue(final IEntity pEntity, final float pPercentageDone, final float pRotation) {
	pEntity.setRotation(pRotation);
}
 
Example #28
Source File: SkewModifier.java    From tilt-game-android with MIT License 4 votes vote down vote up
@Override
protected void onSetValues(final IEntity pEntity, final float pPercentageDone, final float pSkewX, final float pSkewY) {
	pEntity.setSkew(pSkewX, pSkewY);
}
 
Example #29
Source File: SkewModifier.java    From tilt-game-android with MIT License 4 votes vote down vote up
@Override
protected void onSetInitialValues(final IEntity pEntity, final float pSkewX, final float pSkewY) {
	pEntity.setSkew(pSkewX, pSkewY);
}
 
Example #30
Source File: BaseMenuItemDecorator.java    From tilt-game-android with MIT License 4 votes vote down vote up
@Override
public <L extends List<S>, S extends IEntity> L queryForSubclass(final IEntityMatcher pEntityMatcher, final L pResult) throws ClassCastException {
	return this.mMenuItem.queryForSubclass(pEntityMatcher, pResult);
}