In my game, I have a 4x4 grid of TextViews, each displaying one letter, arranged in a TableLayout.
I'd like to implement a "rotate 90 degrees clockwise" feature, and I'd like the grid to rotate, but I want the letters to stay upright.
It could be achieved by applying a 0 to 90 degree rotation on the TableLayout and another 0 to -90 degrees animation on each TextView. Then it will appear as if the letters are still oriented upwards, because the grid will be rotated from 0 to 90 degrees, and the TextViews' animation will cancel the rotation, as it's the exact opposite.
It works, but the animation is choppy on low-end devices and that doesn't look good. Is there something I can do to improve the animation performance, as I'm animating 17 views at once now. Is there some trick I might employ, like disabling antialiasing or setting lower color depth for the duration of animation (on slower devices)? Or is there some way to glue the 16 TextViews together and let Android do only one animation on this glued view?
Related
When animating small deltas for SCALE_X and SCALE_Y on TextViews, the results are choppy and don't look smooth.
To illustrate this problem, I have coded up a sample project here:
https://github.com/blah1234/TextScaleApplication
Sample result looks like the screen record video here:
example.mp4
(may need to download the mp4 file to get a high-resolution copy, rather than just viewing on the google photos album page)
The top TextView's SCALE_X and SCALE_Y properties are being animated from 1 to 1.067 over 5 seconds, while the TextView's SCALE_X and SCALE_Y properties are being animated from 1 to 1.5 over 5 seconds.
The top TextView's animation does not look smooth, and with individual characters shifting around leading to a choppy effect. It almost seems like the TextPaint is not anti-aliased, and it isn't able to blend pixels when drawing the text at various pixel locations.
The bottom TextView's animation is much smoother when animating over larger scale deltas.
Anybody know what is causing this artifact when animating small deltas? And is there a workaround?
Got an answer from Google:
https://developer.android.com/reference/android/graphics/Paint#LINEAR_TEXT_FLAG
and
https://developer.android.com/reference/android/graphics/Paint#SUBPIXEL_TEXT_FLAG
Works great!
I'd like to rotate an ImageView with a different pivot in Android Studio.
This is how it rotates when it's -45 degree by default pivot(centre).
So, when we do animation, it works in a fixed image area such as a fan or a windmill.
But what I want to do is like this.
The red point is the new pivot that I want. In this way, it will take over 4 times bigger areas if it rotates 360 degrees.
How can I implement this?
I'm attempting to put together a slick animation in which a view that takes up most of the screen space rotates to reveal another view on the rear side:
rotatingView.animate().rotationY(90)
.setDuration(250)
.setInterpolator(new AccelerateInterpolator())
.withEndAction( /* Runnable that sets up the rear side of the view,
then rotates Y another 90 degrees */);
Problem is, about 80% of the way through this animation, the view disappears. The view doesn't reappear until about 20% of the way into the second half. Put another way, it disappears at 11 o'clock and reappears at 1 o'clock. Why is this?
I finally stumbled on the answer to this type of problem. UsesetCameraDistance(), but note that:
The distance is expressed in "depth pixels." The default distance depends on the screen density. For instance, on a medium density display, the default distance is 1280. On a high density display, the default distance is 1920.
So, to "raise" the camera to the point where the near edge of a view doesn't clip it, set the distance to several times the "default" distance. In my case with several tablet screens, a value of 4000f was needed. See the link for more onsetCameraDistance()parameter calculation.
You may want to combinesetCameraDistance()with clipToPadding="false" and clipChildren="false" in your XML file; these control masking of one view by another.
Also, I suspect YMMV across different Android releases and vendors.
I'm using AutoParallaxBackground (from the AndEngine example) to create a background (only 20% of screen height), that appears to be moving. It works, but now I would like to add a Sprite that also moves in X direction, but isn't repeating.
The sprite should be positioned behind the background.
How can I achieve this?
I tried setting the Z index on sprites, but it isn't working, probably because the background is always the lowest.
I'm writing a game and now I'm starting to realize that the performance has to be improved (link to game (market)).
If you can't check it out: It's a snake-like game with birds. You control the first bird (by drawing a path for it to follow / using dpad), and a swarm of smaller birds follows it in line. The birds are animated, and can be rotated by 180° and mirrored (depending where they're flying through).
At the moment I animate the first bird only, then scale it down and save it in an invisible element which is shown 4 frames later (fluid animation purposes), instead of animating each bird individually. So for each bird you see on screen, there are 4 objects with a bitmap each. Now my question is, should I make a spritesheet and reduce the number of possible rotations (say, 1 set of sprites every 10°) or calculate the animation for each bird, or keep it my way?
There is no point making your rotated sprite sheets by hand, I'd just load in a single sprite sheet. Then make an array of Bitmaps, for each angle, and rotate and copy the base sprite sheets over each. (you may need an array of arrays to handle the animations, or do separate rotates for each frame of the sprite sheet) This also lets you change your art later with ease.
something like:
Bitmap baseFrame;
Bitmap rotatedFrame[]=new Bitmap[360/10];
...
Matrix rotationMatrix=new Matrix();
rotationMatrix.setRotate(n*10);
rotatedFrame[n]=Bitmap.createBitmap(baseFrame,0,0,
baseFrame.getWidth(), baseFrame.getHeight(),
rotationMatrix, false);
The width, and height of the rotated images may need to be larger then to base image, and you may want you set it up to rotate around the centre but you get the idea
By the way,
Having a look at your screenshots of your game I suspect that drawing your background may have a bigger effect then rotating the birds. You may want to profile your code to see how long it's taking to draw each image. ( http://developer.android.com/guide/developing/debugging/debugging-tracing.html ). I'd make sure your background is being loaded in a RGB_565 format, it can be quite a lot faster when rendering in software.
I have found rotating images in android to be surprisingly fast, being able to rotate hundreds of small bitmaps at a good frame rate.
Here is the simple explanation of the Rotation Animation:
http://androidtutorials60.blogspot.in/2013/09/simple-rotate-animation-in-android.html