Danuubz wrote:How do you exit the application?
It sounds like you press 'HOME' button or maybe 'Back'. I would use System.exit(0) for this.
Croccy22 wrote:Thats ok but what if you want the user to be to press the home button but then return to your app by pressing the back button.
When people press the home button or recieve a call etc the code should call the pause function and then put the program into a wait loop. Then if people return to your app it should resume from where it left off. Android then has the ability to shut down any applications that are in the background if the space is needed.
So if you set the application to exit when it loses focus you would end up with people being kicked out of games because they recieved a phone call which I doubt they would be very happy about!
I think the problem is something along the lines that when a user launches an application it runs it from the start, recreates all the resources etc even though there is already a copy loaded into memory.
I guess we need some sort of routine that detects if the applicastion is already loaded when you launch it. And it it is it either kills that app or bring that app ot of the background and kills itself?
Am I making any sense or am I speaking c##p?
esteem wrote:its the way google does it in all of the examples, and its the way i have been doing it. i dont think there is another way. I didnt see it as a problem as it would be similar to saving a game state to file or something like that if you were developing a game for PC.
Croccy22 wrote:Hi guys,
Can someone give me a piece of sample code that does the following:
I see in the code above where it places your png on the screen. Thats fine.
What I want to do is have a png that is 150 pixels wide and 50 pixels high. This png will acually be three frames of animation each that are 50x50 pixels.
What I want to do is copy a 50x50 part of that image and place it on the screen. So I can then have one image which contains several frames of animation.
If someone could just give me a piece of sample code just to do this, a couple of lines will do.
It's common practice for animated sprites!ErnestoGuevara wrote:I can't see why you wouldn't put them in three separate files?
For doing the animation within one sprite you should use the src Rect to define each frame: first frame would be ((0,0),(50,0),(50,50),(0,50)), second frame would be ((50,0),(100,0),(100,50),(50,50)) and so on. I don't think defining a source rectangle is a lot slower than having 3 different files for each animation. As when you draw an image, it probably automatically assumes a Rect which contains the whole image, so defining a smaller Rect won't generate extra overhead, except of the passing of 2 Rect parameters, which won't be that much of a time hog.ErnestoGuevara wrote:Clipping the image will require extra processing power. But if you're determined, check out the canvas class's drawBitmap(Bitmap bitmap, Rect src, RectF dst, Paint paint).
True, but I don't think AnimationDrawable is very well suited for custom, 2D gaming, animation. I think it will use too much resources for that and will be too resticted. Thoug if you want to use some animated image in you normal layout (not a custom 2D game or something like that), then AnimationDrawable is the way to go.ErnestoGuevara wrote:You can also check out AnimationDrawable, which does frame-by-frame animations that are set up with xml.
Users browsing this forum: No registered users and 3 guests