Android 2d and 3d synchornization - android

Is there any way to synchronize 2d and 3d animations in android.
Let me explain:
i want to run a normal zoom/move/ animation of an android widget using surface view.
Same time i want a 3d cube rotation using Glsurface.
Can i achieve a parallel animation effect.
Thanks in advance.

It all depends on how you implement the animations. It could very well be enough to set the duration of both animations to exactly the same, and then start them at the same time.
As far as I know there is no "AnimationProgress" listener that you can use to get how far the 2d animation has progressed, so if you need a very exact synchronization of the two animations, you might be best off running your own animation thread updating the position of both objects continuously.

Related

Track on screen rendering

I m trying to track after the screen rendering in Android for move a simple Object on screen but with no luck.
For Example: The background and the bars in flappy bird game, How does they "move" and the bird is flying like?!
I m trying to avoid from using OpenGL.
Any tutorial? Any Tip/Trick?
In iOS it's super simple, In android is it the same?
Thanks in advance!
If you are trying to build a game (especialy if you build it for android and IOS) and need to use some tweening go and use platform such as
Corona:
http://coronalabs.com/products/corona-sdk/
Unity:
http://unity3d.com/
you could use openGL but this is a lot of power for some little app...
if you just want animations you could try to use the android animations:
http://developer.android.com/training/animation/index.html
also a nice tutorial for animations and tweening:
http://code.tutsplus.com/tutorials/android-sdk-creating-a-simple-tween-animation--mobile-14898
or extend the view class and override onDraw, this way you could draw stuff on a canvas and even create your own animations by calling invalidate() again.
all depend on your needs.

Is the structure of this code suitable for its purpose and how do I smooth animations in Android?

I am implementing a piano tiles clone for an educational purposes. I've created 5 Views (that's the rows) which extends LinearLayout. Each one of them has 4 childs (that's the 4 tiles).
I am using an Handler for the animation, and change the Y property manually every "tick".
Problem is, the animation is somewhat twitching and not smooth.
I have two questions:
Is that a good design? I know for example about surfaceView as alternative for drawing and animating but that seemed to me a bit complicated for my cause.
How would you animate those tiles? currently I use an Handler (actually I was guided on another thread to use Animation. What do you think the most feet to my case?
Thanks!
I like your grid idea, but you may have to change it if you would like the tiles to be procedurally generated. Also, here is a thread on how to make animations smoother in Java (This can probably apply to Android too):
How can I make a Java Swing animation smoother
Here is one for Android: Moving animation not smooth in android
Also, I feel you are a bit behind, the Piano Tiles phase has disappeared now, much like Flappy bird.

3D animation between layouts like the lock screen in jelly bean

So basically I'm trying to replicate this. It will be used like a view flipper. I haven't had much experience in doing this sort of stuff in android yet so any help would be appreciated!
I'm not exactly sure, what are you going to achieve, but I would start with such lecture: Android flip 3D animation. It's quite easy to replace views in the middle of such animation. You may consider writing your own container, if the ViewFlipper is not enough.
If the view is too complex for Android to handle, or your animation is intended to be more interesting than simple flip/scale/move, then you may consider using OpenGL and shaders. Simply draw your views to bitmaps, pass it to OpenGL and do whatever you want to do with them.

What is the Android equivalent of Graphics g.translate(xPos,yPos); ?

The background of my game is going to be scrolling. Instead of making it scroll by moving all the objects in relation to my main character, I want to just move the camera to follow him.
I could do that with g.translate(x,y) in java but what is the equivalent in Android?
Also, if you want let me know your thoughts about if moving the camera is the best choice. Why does everyone just make the background move, and not the camera?
Thanks!
I could do that with g.translate(x,y) in java but not sure how in Android.
The equivalent would be c.translate(xPos,yPos), where c is of type Canvas.
Also, if you want let me know your thoughts about if moving the camera is the best choice. Why does everyone just make the background move, and not the camera?
Probably because they are unaware they can apply matrix transformations to drawing operations.

Android: tween animation of a bitmap

My app implements its own sprites by calling the following in my view's onDraw() method:
canvas.drawBitmap(sprite.getBitmap(), sprite.getX(), sprite.getY(), null);
The app is a physics simulation, and so far this has worked out great. But now I'd like to enhance the animation by morphing between images for the sprites when certain events occur.
For example- when a collision happens, I would like to play an animation of an explosion. My idea was to replace the usual sprite bitmap with that of an explosion PNG, and use Android "tween animation" to make the explosion grow larger.
But the Android tween animation example assumes that you have an ImageView defined somewhere statically in your XML configuration.
Is there a way to animate a bitmap as drawn in onDraw() using tween animation? Or do I need to convert my sprites to use some sort of ImageView? If the latter, can you point me to an example of proper sprite animation in Android?
Thanks
I built a generic Tween Engine in java that you can use to animate anything, including your sprites. It's optimized for Android and games because it does not allocate anything at runtime, to avoid any garbage collection. Moreover, Tweens are pooled, so really: no garbage collection at all!
You can see a complete demo here as an android application, or here as a WebGL html page (requires Chrome)!
All you have to do is implement the TweenAccessor interface to add Tween support to all your sprites. You don't even have to change your Sprite class, just create a SpriteTweenAccessor class that implements TweenAccessor<Sprite>, and register it to the engine at initialization. Just have a look at the GetStarted wiki page ;)
http://code.google.com/p/java-universal-tween-engine/
I'm also building a visual timeline editor that can be embedded in any application. It will feature a timeline similar to the Flash authoring tool and Expression Blend (a Silverlight dev tool).
The whole engine is heavily documented (all public methods and classes have detailed javadoc), and the syntax is quite similar to Greensock's TweenMax/TweenLite engine that is used in the Flash world. Note that it supports every Robert Penner easing equation.
// Arguments are (1) the target, (2) the type of interpolation,
// and (3) the duration in seconds. Additional methods specify
// the target values, and the easing function.
Tween.to(mySprite, Type.POSITION_XY, 1.0f).target(50, 50).ease(Elastic.INOUT);
// Possibilities are:
Tween.to(...); // interpolates from the current values to the targets
Tween.from(...); // interpolates from the given values to the current ones
Tween.set(...); // apply the target values without animation (useful with a delay)
Tween.call(...); // calls a method (useful with a delay)
// Current options are:
yourTween.delay(0.5f);
yourTween.repeat(2, 0.5f);
yourTween.repeatYoyo(2, 0.5f);
yourTween.pause();
yourTween.resume();
yourTween.setCallback(callback);
yourTween.setCallbackTriggers(flags);
yourTween.setUserData(obj);
// You can of course chain everything:
Tween.to(...).delay(1.0f).repeat(2, 0.5f).start();
// Moreover, slow-motion, fast-motion and reverse play is easy,
// you just need to change the speed of the update:
yourTween.update(delta * speed);
Of course, no tween engine would be complete without providing a way to build powerful sequences :)
Timeline.createSequence()
// First, set all objects to their initial positions
.push(Tween.set(...))
.push(Tween.set(...))
.push(Tween.set(...))
// Wait 1s
.pushPause(1.0f)
// Move the objects around, one after the other
.push(Tween.to(...))
.push(Tween.to(...))
.push(Tween.to(...))
// Then, move the objects around at the same time
.beginParallel()
.push(Tween.to(...))
.push(Tween.to(...))
.push(Tween.to(...))
.end()
// And repeat the whole sequence 2 times
// with a 0.5s pause between each iteration
.repeatYoyo(2, 0.5f)
// Let's go!
.start();
I hope you're convinced :) There are a lot of people already using the engine in their games or for android UI animation.
You can do the tween animation without the ImageView coming from an xml file, but it does need to actually be a View in your view hierarchy.
The drawing you're doing in your Canvas is opaque to the view hierarchy. I think you have two options:
Overlay an ImageView on top of your custom view and animate that using tween animations.
Use Canvas draw routines to animate your explosion.
I'd say that using Canvas routines, along with their maxtrix transformations, makes sense given that you probably already have an animation thread in your app.
You could draw and animate your explosion in Adobe Flash, export the sprite images using swfSheet or similar and then use Frame animation
If you are creating a game, you can use Vectors(Mathematical) to update the position of your images and then draw then with getX and getY. You should iterate and update this vector in some direction through some speed.
Those Vectors are not native (Game APIs has).
You need have a loop to iterate and update the position, then redraw.
For games, it's not a good idea to have components such ImageViews to make animations. They need the system to calc all the layout again and again over time.

Categories

Resources