I am developing a (vertical) scrolling shooter app for android. Everything is working fine, its fast and smooth... but so far it just has a black background. I wanted to make a scrolling background by creating a very tall bitmap of the background, and show a part of it using code like this:
canvas.drawBitmap(background_bitmap, sample_rect, fullscreen_rect, null);
where the sample_rect gets moved along as the game progresses. The code works, but the frame rate has now plummeted and is no longer smooth.
I can think of some possible ways to do this better, but it seems silly to reinvent the wheel if there is a standard method that everyone uses. Any suggestions?
EDIT: By the way the image is not a simple pattern that I can implement with small tiles.
EDIT: Should I be employing BitmapShader? Should I resize my bitmap to match the screen before the game starts?
Related
I'm trying to make animated widget for Android. I'm using Android Studio currently. It's a ImageView that rotates 30 times a second (30fps). I want to be able to change the rotating speed of the image. It's just like a clock (but turning much faster). I know, that this will pull battery energy extremely, but I think this is the only way to make it look like a "smooth" animated widget. Correct me if I'm wrong.
What is the most efficient way (for battery) to make something like this? I thought about following things like:
- Rotating ImageView 30 times a second with a Timer in JAVA (best way?)
- Trying to use a animated GIF (didn't got anything working yet - couldn't change the rotating speed that easy)
Any ideas?
I want to create an image auto scrolling for an outer-space type of game. To make it more exact, I want to load 2 background image that uses a single image occupying the whole screen and auto-scroll it alternatively to create an animation that the background image is moving. Don't get confused with auto scrolling and and shifting to another image automatically. I really meant auto scrolling like moving background using 1 image.
I did some research but what I saw are segments of java codes that made me confused. If possible can anyone provide me an example? From loading the image from xml (should I use an imageview with this? or just set the background image of the layout?) and how I should process it in java code to make an image autoscrolling.
Any ideas guys? Thanks! Sorry for asking too much.
At the moment, I am using Euro 2012 app and it has some interesting layout parts. If you go to matches->knockout screen, you'll see 3 screens like this.
If you slide left or right, you move between them not like between one activity to another, but just like all these elements are laid on one big canvas and you slide each screen into focus. Even thou, if you slide left/right, the screen cannot be stopped in the way that half of each image is visible, so I guess it's not a big canvas. Somehow you can slide screen like one big image, and yet it always lock perfectly as if they used 3 activities for this.
How did the do this?
It's a ViewPager, available in Android support package and described in their blog.
The designing is not so much difficult, As i think to draw that boxes showing quarterfinals, semifinals.
They having layout( we can do by placing image in background also).
The major role played by FrameLayout which shows you that effect(emphasis), the flages are fetch from url as matches are decided(not essentially images only names are sufficient as flags came inside app and gets applied as updated).
After your click i think the start image gets change it's just replacing that image with new one.
As you said they are not on single canvas (but if they did customization of heir Viewpager that it's not stopping in between activities), but i think it's on single canvas.
If your taking about quickness of loading and all it's up to you as much code and processing you optimized it gives you smooth feel and fast processing.
We can appreciate the work but we can not say it's too much difficult as i think it's quit easy...
Hope this explanation helps you to understand ....
I want to implement the curtain animation like in ios in my application.For this i have taken a framelayout and added two linear layout and in the top most linear layout i have put two imageviews and i am applying translate up and down to the imageviews.
It is working ,but the problem is that it is not smooth as compared to the ios.Does anybody have any better solution for smooth transition of the image views?
The smoothness of the transition will be dependent mostly on the device and it's computing power. Have you tried your app on an actual device, or just the emulator. It might just be running slow on the emulator.
Also, perhaps its the loading of the images that are causing things to be slow. Have you tried caching them in memory?
I'm attempting to fade between two background images on my Droid, but the animation seems to get 5fps if not less. Is there any method I can use other than fading in\out a couple image views that would be smoother?
You can set your background to be defined by a TransitionDrawable. Used it to develop a nice splash screen that fades in and didn't have any issues.
I'm not exactly sure what you want to do, but if you want to change from one screen to the other within the same app you should use the ViewFlipper.
View Flipper on Android Developer site
This will allow to smoothly change from one screen to the other (much like the iPhone way).
If it is about the actual Android background i can't help you. Sorry.