I need to create a simple game in which one object moves on the screen based on touch (mouse) events. In other words I want to be able to drag it on an Android machine's screen.
Looking everywhere there are many great examples of "ball" type games in which a ball is bouncing on the screen, responding to gravity and even colliding with other objects, static or dynamic. But nothing that actually has an object that I can touch and move on the screen.
Can anyone point me in the right direction?
Related
I want to create some kind of a tower defense map using a background image which is fourth as large as the screen of the device (twice horizontal, twice vertical).
my question is, how can I do this best. I'm new to Android, just got some Java basics , and want ti try out some stuff.
I want the user to scroll over the entire map using their finger and want him to zoom in via 2 finger pinch, and of course the objects (towers, sprites) should stay were they are.
I've been searching for hours for now and only found answers like " use Scrollview". I just want a food for thought to get in the right way, maybe with some examples.
You can use ImageView and set appropriate onTouchListener where you will detect pinch-to-zoom gesture using GestureDetector and change view coordinates when user drags the finger.
I am trying to learn some more about gestures and graphics in Android, so I am trying to make a sort of game where you start with a ball (just a red circle) in the middle of the screen, and if you swipe in a direction, the ball will be launched in that direction, bouncing of the screen etc. Now, I have succeeded in detecting when somebody swipes in a certain direction, and currently I just display the direction on the screen. My question is: how do I continue? How can I draw the ball, make the user able to move it and make it bounce off the sides of the screen? I think I need to use onDraw somehow, but I'm not sure.
There's a guy with similar problem, he has managed to get circles going around the screen and bouncing from the edges, you may use his code as a basis for your drawing and animation routines: Moving circles in android
This is for learning purpose. I have a small block that should respond to touch. IF i touch top of the screen it should move forward and right if i touch the right side of the screen.Could someone help me with the code and also what topic should i read to learn about this.
What part are you having trouble with, detecting where someone touched, drawing an object or moving an object?
Regardless I would start with some Android tutorials that walk you through creating an app with an object on it, once you have done that the rest should become obvious--it's just getting started that's hard.
Detect touch: How do I detect touch input on the Android
Moving Ojbects: http://obviam.net/index.php/moving-images-on-the-screen-with-androi/
I am recently getting into Android programming and want to make a simple game using 2D canvas drawing. I have checked out the Lunar Lander example and read up on some gestures, but it looks like I can only detect if a gesture occurred. I am looking to do a little more complicated detection on a swipe:
I want to make a simple game where a user can drag their finger through one or more objects on the screen and I want to be able to detect the objects that they went over in their path. They may start going vertically, then horizontally, then vertically again, such that at the end of a contiguous swipe they have selected 4 elements.
1) Are there APIs that expose the functionality of getting the full path of a swipe like this?
2) Since I am drawing on a Canvas, I don't think I will be able to access things like "onMouseOver" for the items in my game. I will have to instead detect if the swipe was within the bounding box of my sprites. Am I thinking about this correctly?
If I have overlooked an obvious post, I apologize. Thank you in advance!
I decided to implement the
public boolean onTouchEvent(MotionEvent event)
handler in my code for my game. Instead of getting the full path, I do a check to see which tile the user is over each time the onTouchEvent fires. I previously thought this event fired only once on the first touch, but it fires as long as you are moving along the surface of the screen, even if you haven't retouched.
i am trying to do this:
1) user long touches the screen,
2) a circle/ball pops up (centered around the user's finger) and grows in size as long as the user is touching the screen
3) once the user lets go of the finger, the ball (now in its final size) will bounce around.
i think i have the bouncing around figure out from the DivideAndConquer example, but i am not sure how to animate the ball's growth. i looked at various view flipper examples such as this:
http://www.inter-fuser.com/2009/08/android-animations-3d-flip.html
but it seems like view flipper is best for swapping two static pictures. i wasn't able to find a good view animator example other than the flippers. also, i would prefer to use images as opposed to just a circle. can someone point me in the right direction?
thanks.
Here are two simple tutorials to help you get started with drawing basic animations including touch input: balls bouncing randomly around the screen and basic drag and drop.
In brief: You're right, ViewFlipper is really not suited for this. You want to draw on a Canvas by making your own custom View. This is the basic framework for 2D graphics. Canvases let you draw image files, solid colors and other things to the screen, while applying transformations ot them at the same time. Handling the user input (i.e. the finger on the screen) is done via the onTouchEvent(...) method, which lets you do something when the finger touches the screen, moves on the screen or lifts off. Have a play with those two tutorials, they should give you the basics.
If you're using a bitmap on a canvas to draw it
http://developer.android.com/reference/android/graphics/Canvas.html#drawBitmap(android.graphics.Bitmap, android.graphics.Matrix, android.graphics.Paint)
Use a scale matrix, the identity multiplied by the scalar of the size you want the image to be.