/** Returns the distance between this entity and the given entity in pixels. */ public float getDistancePixels(Entity other) { Vector2 thisPos = getCenter(); Vector2 otherPos = other.getCenter(); float distance = thisPos.dst(otherPos); Vector2Pool.recycle(thisPos); Vector2Pool.recycle(otherPos); return distance; }
private void jumpMario(final AnimatedSprite face) { final Body faceBody = (Body) face.getUserData(); // float bufX = mario.getX(); // float bufY = mario.getY(); // mario.setVisible(false); // mario = marioJump; // mario.setPosition(bufX, bufY); // mario.setVisible(true); final Vector2 velocity = Vector2Pool.obtain(this.mGravityX * -1, (float) (this.mGravityY * -0.7)); faceBody.setLinearVelocity(velocity); Vector2Pool.recycle(velocity); }
private int indexOfRightmostVertexOf(final Vector2 pVector) { final Vector2[] vertices = this.mVertices; final int vertexCount = this.mVertexCount; int i = 0; for (int j = 1; j < vertexCount; j++) { final Vector2 vector2A = Vector2Pool.obtain().set(vertices[j]); final Vector2 vector2B = Vector2Pool.obtain().set(vertices[i]); if (Vector2Util.isLess(vector2A.sub(pVector), vector2B.sub(pVector))) { i = j; } Vector2Pool.recycle(vector2A); Vector2Pool.recycle(vector2B); } return i; }
@Override public void onAccelerometerChanged(final AccelerometerData pAccelerometerData) { this.mGravityX = pAccelerometerData.getX(); this.mGravityY = pAccelerometerData.getY(); if (pAccelerometerData.getX() > 0) { marioMoveRight = true; marioMoveLeft = false; marioStand = false; } else if (pAccelerometerData.getX() == 0) { marioMoveLeft = false; marioMoveRight = false; marioStand = true; } else if (pAccelerometerData.getX() < 0) { marioStand = false; marioMoveLeft = true; marioMoveRight = false; } float bufX = mario.getX(); float bufY = mario.getY(); if (marioMoveLeft && mario != marioLeft) { mario.setVisible(false); mario = marioLeft; } else if (marioMoveRight && mario != marioRight) { mario.setVisible(false); mario = marioRight; } else if (marioStand) { mario.setVisible(false); } mario.setPosition(bufX, bufY); mario.setVisible(true); final Vector2 gravity = Vector2Pool.obtain(this.mGravityX * 5, this.mGravityY); this.mPhysicsWorld.setGravity(gravity); Vector2Pool.recycle(gravity); }
public void newEvent(float pX, float pY, int pSlot) { mCubicChooseSpite[TYPE].setVisible(false); SLOT = pSlot; CUBIC_SLOT[SLOT] = true; checkArrow(); this.setPosition(0, 100); ACTION = ACTION_DEFAULT; mCubicStartAniSprite.setVisible(true); mScrollLeftSprite.clearEntityModifiers(); mScrollLeftSprite.registerEntityModifier( new LoopEntityModifier( new SequenceEntityModifier( new AlphaModifier(0.5f, 0.2f, 1.0f), new AlphaModifier(0.5f, 1.0f, 0.2f)))); mScrollLeftSprite.setVisible(true); this.setVisible(true); final Body body = (Body) CubicEntity.this.getUserData(); Vector2 vector2 = Vector2Pool.obtain( pX / PhysicsConstants.PIXEL_TO_METER_RATIO_DEFAULT, pY / PhysicsConstants.PIXEL_TO_METER_RATIO_DEFAULT); body.setTransform(vector2, 0); Vector2Pool.recycle(vector2); }
private void action(int action) { mCubicStartAniSprite.setVisible(false); mCubicStartAniSprite.stopAnimation(0); switch (action) { case ACTION_TURN_LEVEL_1: case ACTION_TURN_LEVEL_2: case ACTION_TURN_LEVEL_3: ACTION = action; final Body body = (Body) this.getUserData(); final Vector2 vector2 = Vector2Pool.obtain(body.getPosition()); int frame[] = new int[] {0, 1}; body.setAngularDamping(1.2f); vector2.x = vector2.x / 3; vector2.y = vector2.y / 3; if (action == ACTION_TURN_LEVEL_2) { frame = new int[] {2, 3}; body.setAngularDamping(2.2f); vector2.x = vector2.x / 2; vector2.y = vector2.y / 2; } else if (action == ACTION_TURN_LEVEL_3) { frame = new int[] {4, 5}; body.setAngularDamping(3.2f); } Vol3Osyougatsu.OGG_A3_A_5_KOMATEI.play(); mCubicTurnAniSprite.animate(new long[] {250, 250}, frame, -1); mCubicTurnAniSprite.setVisible(true); body.setActive(true); Log.i(TAG, "body.getPosition " + vector2); vector2.x = random(vector2.x) + new Random().nextFloat(); vector2.y = random(vector2.y) + new Random().nextFloat(); body.setLinearVelocity(vector2); Log.i(TAG, "body.getPosition change " + vector2); this.unregisterUpdateHandler(timerHandler); this.registerUpdateHandler( timerHandler = new TimerHandler( 6f, new ITimerCallback() { @Override public void onTimePassed(TimerHandler timerHandler) { // Stop Turn stopTurn(); } })); break; } }
/** * Returns a vector holding the coordinates to the center of the entity in scene coordinates. The * vector should be returned to the vector pool by calling Vector2Pool.recycle(v); */ public Vector2 getCenter() { return Vector2Pool.obtain(getCenterX(), getCenterY()); }
/** * Returns a vector holding the linear velocity of the entity. The vector should be returned to * the vector pool by calling Vector2Pool.recycle(v); */ public Vector2 getLinearVelocity() { return Vector2Pool.obtain(bodySpriteConnector.getBody().getLinearVelocity()); }
@Override public void onAccelerationChanged(AccelerationData pAccelerationData) { final Vector2 gravity = Vector2Pool.obtain(pAccelerationData.getX(), pAccelerationData.getY()); this.mPhysicsWorld.setGravity(gravity); Vector2Pool.recycle(gravity); }