How would I do this?(Android Whack-A-Mole)

我怕爱的太早我们不能终老 提交于 2020-01-06 05:06:07

问题


I'm making a simple whack-a-mole game as my first mini-project for android. I'm not sure how to go about this. I know the basics of setting everything up and such but I'm not sure how to animate the moles and make it so that when the mole is in the up position it can be tapped and a point will be counted. I know I can do an image button and have a counter go up(counter++) but I need to be able to switch frames from the mole in the hole to the mole in the up position. I've been told to use a type of drawable called a selector or some sort of xml animation but I can't quite understand how to do it. If anyone could provide me with an example of some sort I'd be grateful, or if somebody could point me in the right direction. Thanks!


回答1:


Use a game engine. The two most popular (in my opinion) engines are AndEngine and LibGDX. The former is geared more towards beginners and is a complete engine whereas the latter is more of a framework for intermediate to advanced developers.




回答2:


I've created a simple whack a mole game before. I'll write this in a bullet format for easier viewing:

- First, you have to set a 3 cols and 4 rows table (depends on you).
- Place a picture of a hole in every cell, a total of 12 images.
- You have to place those images in an array.
- The logic is to create a timer and for every tick there's a for loop that reads the array.
- In each array, there's a random boolean generator.
- If it is true, change the picture in that array to a hole with a mole appearing
- If it is false, change the picture to a hole without a mole
- To sum it all up: Every tick, it will loop all the picture(array) and randomize each whether it's true or false. Depending on the value, the picture changes.


来源:https://stackoverflow.com/questions/10022105/how-would-i-do-thisandroid-whack-a-mole

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!