Hi, In my app, I'm trying to make an explosion animation occur, wherever an enemy is destroyed on my custom view. What is the best way to accomplish this, because I know you can't draw an imageView onto a canvas using onDraw? How do I get the animation to play at the location of the enemy?
You could first create a list of exploding and show them one after the other using a thread and handler. For example, if you created 10 images, namely explosion-1.png, explosion-2.png...explosion-10.png then, using canvas.drawBitmap, you could make them appear one after the other until the sequence finishes using a loop.
Related
I've recently started building my second android app and I've hit a wall. What I want to know in general is this. In almost all other programming languages that I've used there is a simple way of drawing arbitrarily on screen. Usually there is some sort of Scene or Canvas type class and another GraphicObject type class. So If, say, I want to draw a car, I create a class that descends from GraphicObject and define they it draws itself and then add an instantiation of the Car class (the object) to the Scene. If I want a second car, you just instantiate another and put it wherever you like, by setting some kind of coordinate function. If this is a program where what is drawn depends on user input, everything must be done programatically and hence it does not depend on anything other than the code written.
How do you achieve this in Android? As far as I can muster the only object which you can define the way it is drawn is a View. However I have not been able to simply take my custom view (that draws a rectangle in my case) and instantiate two of them a put them in the screen where I want them, and do this in a programtic simple way....
Thank you for any advice.
Well if I want to draw lets say 10 rectangles then I wont instantiate my custom View 10 times. Instead I will add logic in my custom View to be able to draw 10 or more rectangles. Anyway if you want to draw again what was drawn in a View then you can call setDrawingCacheEnabled(true); on your View and then call getDrawingCache() to get Bitmap to draw it somewhere else.
Its almost same in android also,
All the widgets are inherited from class View, by extending this class you can actually create whatever you want limiting by only yours imagination, you have access to canvas here, use it along with touch controls exposed from class itself to override all the behaviours you want as per your need,.
http://developer.android.com/reference/android/view/View.html
http://developer.android.com/reference/android/graphics/Canvas.html
I'm using GoogleMaps in my Android app, and I want to display an animated radar image on the map.
I have an array of 6 Bitmaps. When the user hits play, the map loops through displaying each of those images on the map.
This is working, but when transitioning between the images, if I don't call GoogleMap.clear(), the images just get continually stacked on top of each other.
If I do call GoogleMap.clear(), I get a horrible blink. I want one image to remain on the map until the next one is displayed.
Is there a good way to do this?
Is there maybe a double-buffering option for GoogleMaps?
Oh, actually, what I ended up doing was extending the GoogleMap class and overriding the onDraw function to my liking.
I'm trying to draw (IE GLSurfaceView) from a Service and so that it runs in the background.
I know this is possible because the app Transparant Screen gives a perfect example of this.
However, i have no idea how to accomplish this.
So far, i created a activity and a service and some Opengl draw methods.
I also made the GlSurfaceview and activity transparant, but ofcourse touches won't be redirected to the layer under (child).
I don't think it has been designed to be used that way,
however you can reach activity from service quiet easily (using a singleton) and then you should be able to draw into a canvas or drawable and then invalidate the view to draw your offline one ...
Note I am answering on a slightly different context, by using a 2D widget view.
I need to check my own to make sure it is the best of the worse cases... I'll may update this post later
I won't create wallpaper-application but have one problem.
Please tell me how add ImageView or another element in android wallpaper-application to create frame animation?
I can't say for sure that live wallpapers can't use activities, but If you want to have an animation, you can always draw your objects on a Canvas or using OpenGL. For detailed example, see this:
http://www.pushing-pixels.org/2010/02/01/live-wallpapers-with-android-sdk-2-1.html
I'm quite new to android and i want to make some animation (simple game later) like i did on windows (all programatically).
So I have questions what classes should be responsible for.
Activity
It's a base class for whole logic like updating variables (computing move etc.)
Should I create a new Thread on onCreate and run it onResume ? (I need continuous computing for moving objects)
View
Only for drawing animation
onDraw method for clearing Canvas (how to do this quickly? drawRect is efficent ? ) and drawing objects.
Should I invalidate that view or just call onDraw 30 times per second?
Regards
razor
Take a look at this http://developer.android.com/resources/samples/AccelerometerPlay/index.html