I have a silly little game that I made just for myself, but I am thinking of sharing it with friends as its not really ready for "prime time". The game involves the person making a move in 4 seconds.
In my game, everytime开发者_运维知识库 a level advances I want to disable all buttons and show a countdown like 3...2...1... and then all the buttons get enabled again.
Now there are two ways of doing this (that I can think of) send an intent and move to another activity where I can have a "splashy" 3,2,1 animation and then come back to the game activity... or
simply have some text in the same game screen activity that goes 3...2...1..go!
Which would you recommend?
I'm just scared that if I send the person to another activity, then after the animation they come back, and the game wouldnt have totally loaded but the timer will be running and thus the game will give them less time to make their move.
Thanks in advance!
Personally, I think you should display the countdown on the game screen. This isn't for performance reasons, but just because I think its a better user experience. If I need to react quickly, I like to be able to see the UI even if its disabled. I don't like being thrown onto a completely different screen once the game starts.
From a performance perspective, I think going to another activity should be ok. As long as there are no costly computations in your onResume()
method, returning to the game screen activity should be quick because it will still be on the activity stack below your countdown activity.
You could consider using an ActivityGroup to improve performance as well.
- Related: What is better - multiple activities or switching views manually?
I would be hesitant about switching to another activity, just because of overly-zealous task killers people have on their phones (of course, we know its unnecessary, but many people have them). If a task-killer killed you main game activity while the user was at a splash screen, your game would have to go through onCreate() again. Which is not good.
I would suggest keeping your buttons in something like ArrayList<Button>
and then you can go through and say
for(Button button : buttonArrayList) button.setClickable(false);
But I'm an Android beginner myself, so take my advise with caution.
精彩评论