Explanation of JetBoy example for dev.android.com? - java

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.
How is the image drawn to the screen?
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.

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.

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.

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

Related

How can I allow the user to draw freely on the screen

how do I can make the user to draw somthing by touch the screen?
in what method I use?
Does I use canvs?
Thanks (:
Yes, you will need to use the HTML canvas object. I recommend also looking into a graphics library to make things more simple. Fabric.js is a good one (http://fabricjs.com).
Here is a global drawing web app I made using node.js. Feel free to check it out.
http://node.paulkr.com
https://github.com/paulkr/pennitdown

How to make a button that draws over any screen?

Apps like Floating Toucher or Link Bubble proves how useful a floating button can be. And no, I'm not talking about FABs as per Material Design guidelines here, I meant a literally 'floating' button that draw over any screen in the system that can be dragged around and clicked.
Take a look at these examples:
(source: boatmob.com)
Now, I tried to Google a way to do this but I'm afraid I'm still at lost here. How can these apps draw over screens outside their own?
I've come across this SO question which more or less asking about a similar question. But to be honest, I wasn't able to gain much information from it. Said question mainly addressed how to intercept a touch for a floating view; Not how to specifically make one.
I really hope that somebody out there could enlighten me on this. Thanks in advance for your time!
If you are talking about an activity's view (not Widgets), 'floating' on screen, like Facebook ChatHeads. Then you should create a background service and attach a view with it. Though it is not recommend by Android.
See below links
What APIs in Android is Facebook using to create Chat Heads?
http://www.piwai.info/chatheads-basics/

Making a game menu using Canvas?

I am already familiar with JButtons, JLabels and such, but I want to start making a game a very "colorful" menu. Is there a way to do this using Canvas (like adding a mouse listener and make some buttons in PhotoShop and detect if the mouse hovers over and clicks the button), or is there a better way?
Since you're already familiar with JButtons, you may find it easier (and more practical) simply to extend the existing JButton and modify its appearance, so that it looks like an image rather than the traditional grey button.
Amongst other things, it means you get all the standard button behaviour for free, including special cases, and in exchange all you have to do is override a couple of methods.
Have a read through the accepted answer for the following question, which explains pretty much exactly how to do that:
Creating a custom button in Java

ImageView, selecting a certain part Android

My vision is this-- I have an image of a human body(like an anatomy chart), and I want the user to be able to click a certain part of it and be able to communicate the body part they have clicked on, as in translating it to text... I wonder if this could be possible, and how? Any sample code/redirection to a tutorial would be helpful, or maybe just a practical idea...
A very simple approach is just to add an ImageView to you layout.
Override onTouchEvent in the activity to capture touches and then translate the coordinates to texts.

Get input from keyboard with Canvas

I want to create an Upwords application for desktop and so I think that the game table should be displayed as canvas. In the beginning of the game I want to ask the user to make some input about the players that will play, but I don't have any ideas. Could you please help me on that?
Also, if there are better implementation ideas than to use canvas, I would be grateful to hear you.
Thanks in advance.
No it's not my first GUI application but I have very little experience.I think it's a good idea to make my own class but I was't sure because I want to use GUI builder(deadline issues) and in the past I had some problems on this.I will try it.For the input I thought about JDialog but I have to simulate a mobile environment so the prompt must be shown on the "screen"(the canvas on our case).
You have a pretty broad question, and I'm guessing this is your first (or one of your first) graphical programs in java. Instead of using AWT components (like Canvas), I would strongly, strongly recommend using Swing, or really, any other graphical library. I would start by looking at the documentation for javax.swing.JFrame. You will probably end up creating a custom component (extending JComponent?) and overriding its paintComponent() method to provide the custom graphics of your 'game table'.
As far as user input at the start of your game, you may want to look at a dialog box. Look at the documentation for javax.swing.JOptionPane which can create a wide variety of simple dialog boxes for gathering user input, taking care of the keyboard input automagically.
There are plenty of java Swing 'Hello World' type programs out there that can help show you how to create a basic Swing app. The Java Tutorials is a good place to start.
Good luck!

Categories

Resources