Java Code Examples for org.andengine.entity.IEntity#setPosition()
The following examples show how to use
org.andengine.entity.IEntity#setPosition() .
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: PhysicsConnector.java From tilt-game-android with MIT License | 6 votes |
@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 2
Source File: QuadraticBezierCurveMoveModifier.java From tilt-game-android with MIT License | 6 votes |
@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 3
Source File: CubicBezierCurveMoveModifier.java From tilt-game-android with MIT License | 6 votes |
@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*(tt)*(1-t) * P3) + (ttt * 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); }
Example 4
Source File: PhysicsHandler.java From tilt-game-android with MIT License | 6 votes |
@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 5
Source File: QuadraticBezierCurveMoveModifier.java From 30-android-libraries-in-30-days with Apache License 2.0 | 6 votes |
@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 6
Source File: CubicBezierCurveMoveModifier.java From 30-android-libraries-in-30-days with Apache License 2.0 | 6 votes |
@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*(tt)*(1-t) * P3) + (ttt * 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); }
Example 7
Source File: PhysicsHandler.java From 30-android-libraries-in-30-days with Apache License 2.0 | 6 votes |
@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 8
Source File: CardinalSplineMoveModifier.java From tilt-game-android with MIT License | 4 votes |
@Override protected void onManagedUpdate(final float pSecondsElapsed, final IEntity pEntity) { final float percentageDone = this.mEaseFunction.getPercentage(this.getSecondsElapsed(), this.mDuration); /* Calculate active control point. */ final int p; if (percentageDone == 1) { p = this.mControlSegmentCount; } else { p = (int) (percentageDone / this.mControlSegmentCountInverse); } /* Retrieve control points. */ final int p0 = MathUtils.bringToBounds(0, this.mControlSegmentCount, p - 1); final float pX0 = this.mCardinalSplineMoveModifierConfig.mControlPointXs[p0]; final float pY0 = this.mCardinalSplineMoveModifierConfig.mControlPointYs[p0]; final int p1 = MathUtils.bringToBounds(0, this.mControlSegmentCount, p); final float pX1 = this.mCardinalSplineMoveModifierConfig.mControlPointXs[p1]; final float pY1 = this.mCardinalSplineMoveModifierConfig.mControlPointYs[p1]; final int p2 = MathUtils.bringToBounds(0, this.mControlSegmentCount, p + 1); final float pX2 = this.mCardinalSplineMoveModifierConfig.mControlPointXs[p2]; final float pY2 = this.mCardinalSplineMoveModifierConfig.mControlPointYs[p2]; final int p3 = MathUtils.bringToBounds(0, this.mControlSegmentCount, p + 2); final float pX3 = this.mCardinalSplineMoveModifierConfig.mControlPointXs[p3]; final float pY3 = this.mCardinalSplineMoveModifierConfig.mControlPointYs[p3]; /* Calculate new position. */ final float t = (percentageDone - (p * this.mControlSegmentCountInverse)) / this.mControlSegmentCountInverse; final float tt = t * t; final float ttt = tt * t; /* * Formula: s * (-ttt + 2tt – t) * P1 + s * (-ttt + tt) * P2 + (2ttt – 3tt + 1) * P2 + s(ttt – 2tt + t) * P3 + (-2ttt + 3tt) * P3 + s * (ttt – tt) * P4 */ final float s = (1 - this.mCardinalSplineMoveModifierConfig.mTension) / 2; final float b1 = s * ((-ttt + (2 * tt)) - t); // (s * (-ttt + 2tt – t)) * P1 final float b2 = (s * (-ttt + tt)) + (((2 * ttt) - (3 * tt)) + 1); // (s * (-ttt + tt) + (2ttt – 3tt + 1)) * P2 final float b3 = (s * ((ttt - (2 * tt)) + t)) + ((-2 * ttt) + (3 * tt)); // (s * (ttt – 2tt + t) + (-2ttt + 3tt)) * P3 final float b4 = s * (ttt - tt); // (s * (ttt – tt)) * P4 final float x = ((pX0 * b1) + (pX1 * b2) + (pX2 * b3) + (pX3 * b4)); final float y = ((pY0 * b1) + (pY1 * b2) + (pY2 * b3) + (pY3 * b4)); pEntity.setPosition(x, y); }
Example 9
Source File: MoveByModifier.java From tilt-game-android with MIT License | 4 votes |
@Override protected void onChangeValues(final float pSecondsElapsed, final IEntity pEntity, final float pX, final float pY) { pEntity.setPosition(pEntity.getX() + pX, pEntity.getY() + pY); }
Example 10
Source File: MoveModifier.java From tilt-game-android with MIT License | 4 votes |
@Override protected void onSetInitialValues(final IEntity pEntity, final float pX, final float pY) { pEntity.setPosition(pX, pY); }
Example 11
Source File: MoveModifier.java From tilt-game-android with MIT License | 4 votes |
@Override protected void onSetValues(final IEntity pEntity, final float pPercentageDone, final float pX, final float pY) { pEntity.setPosition(pX, pY); }
Example 12
Source File: CameraScene.java From tilt-game-android with MIT License | 4 votes |
public void centerEntityInCamera(final IEntity pEntity) { pEntity.setPosition(this.mCamera.getCenterX(), this.mCamera.getCenterY()); }
Example 13
Source File: CardinalSplineMoveModifier.java From 30-android-libraries-in-30-days with Apache License 2.0 | 4 votes |
@Override protected void onManagedUpdate(final float pSecondsElapsed, final IEntity pEntity) { final float percentageDone = this.mEaseFunction.getPercentage(this.getSecondsElapsed(), this.mDuration); /* Calculate active control point. */ final int p; if(percentageDone == 1) { p = this.mControlSegmentCount; } else { p = (int) (percentageDone / this.mControlSegmentCountInverse); } /* Retrieve control points. */ final int p0 = MathUtils.bringToBounds(0, this.mControlSegmentCount, p - 1); final float pX0 = this.mCardinalSplineMoveModifierConfig.mControlPointXs[p0]; final float pY0 = this.mCardinalSplineMoveModifierConfig.mControlPointYs[p0]; final int p1 = MathUtils.bringToBounds(0, this.mControlSegmentCount, p); final float pX1 = this.mCardinalSplineMoveModifierConfig.mControlPointXs[p1]; final float pY1 = this.mCardinalSplineMoveModifierConfig.mControlPointYs[p1]; final int p2 = MathUtils.bringToBounds(0, this.mControlSegmentCount, p + 1); final float pX2 = this.mCardinalSplineMoveModifierConfig.mControlPointXs[p2]; final float pY2 = this.mCardinalSplineMoveModifierConfig.mControlPointYs[p2]; final int p3 = MathUtils.bringToBounds(0, this.mControlSegmentCount, p + 2); final float pX3 = this.mCardinalSplineMoveModifierConfig.mControlPointXs[p3]; final float pY3 = this.mCardinalSplineMoveModifierConfig.mControlPointYs[p3]; /* Calculate new position. */ final float t = (percentageDone - (p * this.mControlSegmentCountInverse)) / this.mControlSegmentCountInverse; final float tt = t * t; final float ttt = tt * t; /* * Formula: s * (-ttt + 2tt – t) * P1 + s * (-ttt + tt) * P2 + (2ttt – 3tt + 1) * P2 + s(ttt – 2tt + t) * P3 + (-2ttt + 3tt) * P3 + s * (ttt – tt) * P4 */ final float s = (1 - this.mCardinalSplineMoveModifierConfig.mTension) / 2; final float b1 = s * ((-ttt + (2 * tt)) - t); // (s * (-ttt + 2tt – t)) * P1 final float b2 = (s * (-ttt + tt)) + (((2 * ttt) - (3 * tt)) + 1); // (s * (-ttt + tt) + (2ttt – 3tt + 1)) * P2 final float b3 = (s * ((ttt - (2 * tt)) + t)) + ((-2 * ttt) + (3 * tt)); // (s * (ttt – 2tt + t) + (-2ttt + 3tt)) * P3 final float b4 = s * (ttt - tt); // (s * (ttt – tt)) * P4 final float x = ((pX0 * b1) + (pX1 * b2) + (pX2 * b3) + (pX3 * b4)); final float y = ((pY0 * b1) + (pY1 * b2) + (pY2 * b3) + (pY3 * b4)); pEntity.setPosition(x, y); }
Example 14
Source File: MoveByModifier.java From 30-android-libraries-in-30-days with Apache License 2.0 | 4 votes |
@Override protected void onChangeValues(final float pSecondsElapsed, final IEntity pEntity, final float pX, final float pY) { pEntity.setPosition(pEntity.getX() + pX, pEntity.getY() + pY); }
Example 15
Source File: MoveModifier.java From 30-android-libraries-in-30-days with Apache License 2.0 | 4 votes |
@Override protected void onSetInitialValues(final IEntity pEntity, final float pX, final float pY) { pEntity.setPosition(pX, pY); }
Example 16
Source File: MoveModifier.java From 30-android-libraries-in-30-days with Apache License 2.0 | 4 votes |
@Override protected void onSetValues(final IEntity pEntity, final float pPercentageDone, final float pX, final float pY) { pEntity.setPosition(pX, pY); }