image flip effect using animation in android - android

I'm currently working on an Android game
I want to create an image flip effect using animation.
How would I do it?

There is a good example of such here

try this:
Android Animation - Flip
or more complex:
http://www.inter-fuser.com/2009/08/android-animations-3d-flip.html

I managed to achieve this using setScaleX (for flip/reflection around the Y axis). Use setScaleY for flip/reflection around the X axis.
final ValueAnimator rotation = ValueAnimator.ofFloat(0, 360);
Then in your onAnimationUpdate function, set scale on X or Y using the cosine function on your range of angles.
view.setScaleX((float)Math.cos(Math.toRadians((Float)valueAnimator.getAnimatedValue())));
Hope this helps

Related

Rotate item in a circle shape using phone accelerometer/gravity sensor vector

I'm trying to make a small circle move in another bigger circle as a ball moving in circle relative to Android phone tilting. I'm doing this in Godot but I think the principle is the same in all game engines probably. I make a scene in Godot and add two sprites as the two circles as the following picture. I get the accelerometer 3D vector, use x and y values and calculate the angle in x and y plate (relative to y axis i.e Vector2(0, 1) ) and rotate the mentioned scene to that degree using an animation, using this code
func _process(delta: float) -> void:
var vec3 = Input.get_accelerometer()
accelVec = Vector2(-stepify(vec3.x, 0.1), -stepify(vec3.y, 0.1))
var angle = accelVec.angle_to(Vector2(0, 1))
rotateTween.interpolate_property(self, "rotation", rotation, angle, 0.2,
Tween.TRANS_LINEAR)
rotateTween.start()
return
But the problem lies in here that when the x value of accelerometer 3D vector changes from a positive to negative value i.e when the ball is at top of the circle and is going to go to the other half of the circle, it actually moves from bottom of the circle to the desired point rather than from top of the circle.
I hope I explained the problem well, though I doubt it.
I added the Gif that shows actual test on an android phone here Testing in Android.
Any idea how to solve this problem?
Thanks in advance.
This is because Tween is interpolating linear values. It doesn't know it's working with angles, or that they should wrap around.
So when you're at -179 degrees and you tween to 179--a difference of 2 degrees--Tween just sees -179 -> 179 and goes through the whole circle.
You probably don't need a Tween here at all because _process() happens every frame.

to rotate whole imageViews in linearlayout in y axis

There are many answers to how to rotate image in y axis. Also, there are answers to rotate layer in z axis. However, what I want is to put many image side by side in a linear layer (or whatever), and rotate them in Y axis for a specific degree at once. just like the picture attached. In addition, the ImageViews still can be touched to invoke events.
I think this might help you:
ObjectAnimator anim = ObjectAnimator.ofFloat(<yourView>,"rotationY",0f,180f);
anim.setDuration(ANIMATION_TIME);
anim.start();
Or maybe without animation you can use this answer: link

Animate image size

I would like to have an image "bump" (or change its size) according to music. I don't need the music detect side, I just need a way to resize the image dymaically and according to an animation. What is the best way to do this?
If you're using at least API 11 and want to animate it smoothly, you can use an ObjectAnimator to animate various changes to the properties of a View. For example:
ObjectAnimator oa = ObjectAnimator.ofFloat(myView, View.SCALE_X, 1.0, 1.25);
oa.setDuration(25); //how long the animation lasts in ms, probably short for your purposes
oa.start();
This will scale the X size of the view myView from the default (1.0) to slightly larger (1.25). You will then need to do the same for the SCALE_Y property. Note that you will probably want to keep track of the current scale value so that your next animations look nice. For example:
float currentScale = 1.0;
...
void scaleMyView(float newScale) {
ObjectAnimator oa = ObjectAnimator.ofFloat(myView, View.SCALE_X, currentScale, newScale);
oa.setDuration(25);
oa.start();
currentScale = newScale;
}
See also the documentation on ObjectAnimators if you need more info. Hope this helps!
Every View has setScaleX and setScaleY methods. I believe you can use it for this. As far as syncing it to the music, that depends on the way you're playing it.
There is greate animation library for Android.
https://github.com/daimajia/AndroidViewAnimations
https://github.com/2359media/EasyAndroidAnimations

Rotate animation on x-axis

I want to rotate my image on x-axis, I tried many alternatives, also tried Rotate3dAnimation and it always rotate on Y axis. I want to do my image as:
How can i do it?
You should use android.graphics.Camera.rotateX(degrees);
Old question but no solid answer yet. So :
In case your Image is a view you can use ViewPropertyAnimator (Minimal implementation) like this :
yourImage.animate().rotateX(360);
You can chain together all the methods that you need and customize your animation f.e. :
yourImage.animate()
.rotateX(360)
.setDuration(1000)
.setStartDelay(500)
.setInterpolator(new AccelerateDecelerateInterpolator);
Check all available methods in the docs.
ViewPropertyAnimator is available since API 12.

3D rotation while object being translated

I've been playing with Android animation framework and I found the following 3D rotation sample code:
http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/animation/Transition3d.html
http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/animation/Rotate3dAnimation.html
It does pretty much what I want but I want the ImageView to rotate while it's being translated from point A to point B and the it should rotate along it's own center(which is moving) instead of the center of the container of screen.
Does anyone know how to do that?
-Rachel
Well it's pretty close to what you posted. Essentially you're multiplying the rotational matrix by the translation matrix. That's essentially what happens under the covers. Android hides that detail from you with it's API:
Matrix matrix = transformation.getMatrix();
matrix.rotate( rotateX, rotateY );
matrix.postTranslate( transX, transY );
Rotate first then translate will rotate the image around it's own axis first before translating it.

Categories

Resources