4

I have developed many applications for desktop or web in java, but never for android.

What little I have practiced with was weird because I am used to SWING. Since it uses .xml files for applications I was wondering if you needed this also in games?

For example there is a a good example at http://developer.android.com/resources/samples/JetBoy/index.html. I was hoping someone could explain two things for me.

  1. How is the image drawn to the screen?
  2. How do you listen for user input? (Eg. Clicks, drawing, swiping, ect...)

I have made games on the desktop so you don't have to get in depth, but I found it hard to understand the code. (What I was suppose to do special for android.)


(Another way to put it:)

I guess basically what I am asking is how to I draw an image that will in turn listen to clicks and such without adding a button? Or do I need to add an invisible button? Then if I did have to add a button how would I listen for swiping and drawing?

Also I saw some methods like doDraw(), but did not see where they were putting the image so it would appear on the android device.

Zeveso
  • 1,274
  • 3
  • 21
  • 41

3 Answers3

4

JetBoy is rather complicated for a beginner, check these simple examples which are based on the same principles as JetBoy: How can I use the animation framework inside the canvas?

Everything is done by drawing bitmaps on the view's canvas and an event which detects when and where the sreen was touched.

Community
  • 1
  • 1
Lumis
  • 21,517
  • 8
  • 63
  • 67
2

I think this will tell you everything you need to know, in a comprehensive, 31 part series detailing the creation of Light Racer 3d for Android.

Jack
  • 9,156
  • 4
  • 50
  • 75
1

If you are not going to use any Game Engine ,
basically you extend android.view.SurfaceHolder
and then overide these methods,
public boolean onTouchEvent(MotionEvent event)
protected void onDraw(Canvas canvas)

go through these articles.It teaches everything you need from the scratch

Dinushan
  • 2,067
  • 6
  • 30
  • 47