There is something what I can use to rotate object without ending? I want start game and start rotate sprite with some speed but I don't want to end rotate. There is any way to use: new RotationModifier(20f, 0, 360), but with no end of rotation? Or there is any other way?
I think you can use LoopEntityModifier, something like (haven't tried it out):
LoopEntityModifier EntityModifier = new LoopEntityModifier(
new RotationModifier(1,0,360));
Related
I am new in andengine game Development. I am trying to make a game where a playerSprite moves forward and backward through X- axis. How can I continuously move the background along with the playerSprite ? If the player goes forward , the background will go forward and will repeat itself continuously . Same for moving the playerSprite to backward. How can I do this ?
What you are looking for is ParalaxBackground. Here is simple example:
private void createBackground()
{
ParallaxBackground background = new ParallaxBackground(0, 0, 0);
background.attachParallaxEntity(new ParallaxEntity(0, new Sprite(0, 0, background_region, vbo)));
scene.setBackground(background);
}
It is from Matim-Dev andEngine Tutorial: Matim-Dev tutorial
You might also look into sample code for AutoParalaxBackground: AutoParalaxBackground
I want to smooth rotate my spirtes. I have 6 sprites and I want to rotate them on 360.
This is my code:
unactiveTimerWaitingForPlayersTxtSprite
.registerUpdateHandler(timerToUnactiveTimerWaitingTxt);
TimerHandler timerToUnactiveTimerWaitingTxt = new TimerHandler(0.1f, true,
new ITimerCallback() {
public void onTimePassed(TimerHandler pTimerHandler) {
unactiveTimerWaitingForPlayersTxtSprite
.setRotation(unactiveTimerWaitingForPlayersTxtSprite
.getRotation() - ANGLE_WAITING_TXT);
}
});
This is code for one sprite. For all my sprites I do that in the same way. When I run application on Asus transformer 700 rotate of objects is not smooth. I add this code to engine:
engineOptions.getRenderOptions().setDithering(true);
engineOptions.getRenderOptions().setMultiSampling(true);
but still the same effect. There is any way to smooth rotate objects?
Use Modifiers: In this case you are looking for the RotationModifier.
If you want to rotate the sprites using custom TimerHandlers then you have to multiply the angle change (ANGLE_WAITING_TXT) with the elapsed time in order to have a smooth animation.
I have an AnimatedSprite that after it finishes the animation I want to reverse animate it. I want to do that continuously. Once the reverse animation is complete I want to play the original one. This may be easy one but I am new to Android and AndEngine.
mFlower1Sprite = new AnimatedSprite(20, 800, this.mFlower1);
mFlower1Sprite.setScale((float) 1.5);
mFlower1Sprite.animate(500, 0, new IAnimationListener () {
public void onAnimationEnd(final AnimatedSprite pAnimatedSprite) {
// reverse animation
}
});
mScene.attachChild(mFlower1Sprite);
return mScene;
Use animate method:
public AnimatedSprite animate (long[] pFrameDurations, int[] pFrames,
int pLoopCount, AnimatedSprite.IAnimationListener pAnimationListener)
Animate specifics frames.
Parameters:
pFrameDurations must have the same length as pFrames.
pFrames indices of the frames to animate.
Simply list the indices in reverse order.
I'm working with sprites myself atm and I came across this jQuery plugin. Check it out.
http://spritely.net/
I'm not aware of any support to reverse the frames of an AnimatedSprite, although it's probably a useful feature so I'd love to find out if I'm wrong.
Your best bet would probably be to create another sprite sheet with the frames reversed and another instance of an AnimatedSprite for that sheet. Then define one or two private IAnimationListeners inside your activity (rather than on the fly when you call .animate()), which alternately detach and attach the two sprites at the end of each animation.
I am developing game using andengine. I want to add a sprite as a child to another sprite so that sprite will rotate along with another sprite. Since I am new to andengine I didn't know how to add sprite as a child. By rotating main sprite the child has to rotate with it.
Some of them suggest to call sprite.attachChild() method to add as child but I can't get this method. I am extending BaseGameActivity.
Edited: Some of them says it's due to old version of andengine. Would anyone give me link for download new version of andengine?
AnimatedSpriteHelicopter mSpriteHelicopter = new AnimatedSpriteHelicopter(0, 0, this.mTRHelicopter);
mSpriteHelicopter.animate(50);
this.mScene.getChild(GameLayers.HELICPTER_LAYER).attachChild(mSpriteHelicopter);
this.mScene.registerTouchArea(mSpriteHelicopter);
this.mScene.setTouchAreaBindingEnabled(true);
// ==========================
// Missile
// ===========================
AnimatedSpriteMissile mMissile = new AnimatedSpriteMissile(0, 0, this.mTRMissile);
mMissile.animate(100);
mSpriteHelicopter.attachChild(mMissile);
return this.mScene;
Just a sample code. now missile will move with helicopter sprite :) very simple.
I have my own classes extended with AnimatedSprite.
The source code is located at http://code.google.com/p/andengine/ and indeed sprite composition is a feature in the most recent version of AndEngine as verified in this forum thread.
I'm using it and can personally verify that it's functional.
I have written a first person camera class for android.
The class is really simple , the camera object has its three axes
X,y and Z
and there are functions to create the ModelView matrix ( i.e. calculateModelViewMatrix() ),
rotate the camera along its X and Y axis
and Translate the camera along its Z-axis.
I think that my ModelViewMatrix calulation is correct and i can also translate the camera along the Z-axis.
Rotation along x-axis seems to work but along Y-axis it gives strange results.
Also another problem with the rotation seems to be that instead of the camera being rotated, my 3d model starts to rotate instead along its axis.
I have written another implementation based on the look at point and using the openGL ES's GLU.gluLookAt( ) function to obtain the ModelView matrix but that too seems to suffer from the exactly the same problems.
EDIT
First of all thanks for your reply.
I have actually made a second implementation of the Camera class, this time using the rotation functions provided in android.opengl.Matrix class as you said.
I have provided the code below, which is much simpler.
To my surprise, the results are "Exactly" the same.
This means that my rotation functions and Android's rotation functions are producing the same results.
I did a simple test and looked at my data.
I just rotated the LookAt point 1-dgree at a time around Y-axis and looked at the coordinates. It seems that my LookAt point is lagging behind the exact rotation angle e.g. at 20-deg it has only roatated 10 to 12 degree.
And after 45-degrees it starts reversing back
There is a class android.opengl.Matrix which is a collection of static methods which do everything you need on a float[16] you pass in. I highly recommend you use those functions instead of rolling your own. You'd probably want either setLookAtM with the lookat point calculated from your camera angles (using sin, cos as you are doing in your code - I assume you know how to do this.)
-- edit in response to new answer --
(you should probably have edited your original question, by the way - your answer as another question confused me for a bit)
Ok, so here's one way of doing it. This is uncompiled and untested. I decided to build the matrix manually instead; perhaps that'll give a bit more information about what's going on...
class TomCamera {
// These are our inputs - eye position, and the orientation of the camera.
public float mEyeX, mEyeY, mEyeZ; // position
public float mYaw, mPitch, mRoll; // euler angles.
// this is the outputted matrix to pass to OpenGL.
public float mCameraMatrix[] = new float [16];
// convert inputs to outputs.
public void createMatrix() {
// create a camera matrix (YXZ order is pretty standard)
// you may want to negate some of these constant 1s to match expectations.
Matrix.setRotateM(mCameraMatrix, 0, mYaw, 0, 1, 0);
Matrix.rotateM(mCameraMatrix, 0, mPitch, 1, 0, 0);
Matrix.rotateM(mCameraMatrix, 0, mRoll, 0, 0, 1);
Matrix.translateM(mCameraMatrix, 0, -mEyeX, -mEyeY, -mEyeZ);
}
}