Whats the best way to create a dart board game on Android. Is it possible to determine where a dart hit and in which area it is using a canvas or do I need to use a diffenrent approach?
Edit
Sorry I dont think I have explained my problem very well.
In svg in html5 I can create a dart board using shapes and assign an id to each shape. When a dart lands on a shape the code knows which shape it has landed on, gets its id and calculates the score. e.g id="20" id="60" id="40" for all 20 areas on a dart board.
How would I do this on the Android?
You've got the right idea. A simple approach would be to display a custom DartBoardView in an activity. The view would use an overridden onDraw to draw a dart board image and any darts the user has "thrown." The view would then use View.onTouchEvent to handle user touch events and translate those into new darts.
New answer based on your update:
You're going to have to do the hit detection manually. A touch event will give you an x-y coordinate with the upper left of the view as origin. Calculating points would go as follows:
Offset the given coords so they line up with the center of your board (i.e. touching the middle of your board would give (100, 150), translate that to (0,0)).
Get the angle of the touch to find which numbered section of the board was hit. Something like double touchAngle = Math.atan2(y,x). Might need to convert from radians to degrees here.
Map the angle to a base point value (if angle > 9 && angle < 27, base points = 7)
Multiply the base point value by 2 or 3 if the distance of the touch (distance = Math.sqrt(x^2 + y^2)) from center is a particular length away to account for the multiplier rings.
Related
I'm working with Android Mobile SDK. How can I set Tilt value for default current position indicator (green circle), so when user change tilt for entire map (by doing two fingers swipe), position indicator follows as well.
Or (if it can't be done with default marker), how can I achive it with custom marker resource)? // I can illustrate it by following screens. On second image circle stays the same, instead of transformed into isometric view itself.
You probably want to use a 3d object model and create a LocalMesh + MapLocalModel Object to display it in 3d.
Either create a flat rectangle and alter the pitch / yaw / roll according to the camera which may look awkward or use a 3d mesh and to follow the camera pitch / yaw /roll to make it look like there is depth to the object.
We are creating an app which is used for calculating measurements of any a window/door using Project tango Device. For that we need to follow below mentioned steps:
1. Capture Image (normal 2D image). Store this image.
2. Also capture point cloud while capturing the Image. Store the point cloud in a PCD file.
3. Indicate the position of the window/door in the image displayed on a canvas by drawing a rectangle on the image. See Image.
4. As the rectangle is drawn automatically calculate width and height of the window/door using the stored PointCloud data.
We have managed to do 1, 2 and 3.
For 4 we have two issues:
A. Determine the Points in the PointCloud corresponding to the drawn rectangle i.e. the window/door. We believe that this involves determining the plane in which the window/door is located e.g. Assuming that the axis along the depth (i.e. from the camera to the object) is Z-axis then we need to determine the value(s) of Z that correspond to the plane in which the window/door is located in PointCloud. How can this be done? Please can someone suggest a feasible and an efficient way of doing so?
B. Once we determine the sub-PointCloud corresponding to the drawn rectangle find the distance between the minimum and maximum points along the X & Y axis to determine the width and height respectively. How can this be done?
Any help with demo code or app reference is appreciated.enter image description here
enter image description here
find contour of the point cloud. Use iterative ransac to fit lines to the contour. Intersect the lines and get the corner points
for 3d, compute the surface normals. Then compute the curvature which is a differential of the surface normal. These are corner points.
PCL (Point Cloud Library) has all of these functions.
My android app is to use GPS to help layout a sports field, like a football field. You enter the dimensions of the rectangle, tell the app which corner you want to start with and which corner you want to go to next. The app will tell you when you have walked far enough. Once you have laid down the first two corners, the app will then direct you to the next corner (logic in the app make sure you only select corners that make sense). This is where the trouble comes in. You may be going clockwise or counter-clockwise. I need to know which way to turn for the third point. I know how far I need to go, and I know how to figure out a right angle, but I don't know how to figure out if I went the right way.
I was thinking about forcing the user to go one way or the other, but the problem is that often times a field is laid out with an obstacle on one side (a street, cornfield, fence, whatever). In that case, you will usually want to start at the obstacle and work your way out.
So, to put the question one other way, given two points, A & B (lat & long), how can I calculate the third point that is at right angle to the segment AB and in the right direction? For example, if the user says they want to start with corner 2 and then corner 8, how do I calculate the gps coordinates for corner 7?
I realize that this is possibly/probably more of a geometry question than an android question, but it may be that there is a specific android solution.
I agree with you that this is not an Android question, but a geometry question. Nothing by default in Android to program this I'm afraid.
Great link that I use to remember how I have to calculate distances on the survace of the earth is http://www.movable-type.co.uk/scripts/latlong.html.
Calculate bearing between given corners (for your example, between 2 and 8)
Calculate bearing for next corner you want to know (bearing between 2 and 8 + 90 degrees)
Find destination point given distance and bearing from start point (start point is 8, use bearing calculated at step 2 and I assume you know the dimensions of the field)
I am developing a mobile game for iOS and Android with Starling. I am very new to this framework. I need to add a sprite to the screen and then have the initial point on the screen that was touched be anchor point 1 and then the user will drag there finger which will adjust the second anchor point until they release their finger from the screen. Imagine several nodes that need connected by a line and you can picture what I am trying to do. The problem is that I can change the pivot to be at the beginning of the line but I dont know how to make the other anchor point work. I also cannot use anything other than a sprite as the line is animated by a sprite sheet. Any help that can be provided is greatly helpful, I have been thinking about this for a while now and can't seem to figure it out. Code is helpful and preferred but just giving me an outline of the concept would help as I can probably figure out code. Thanks!
I don't know actionscript but I'm sure if it is for android the touch event has 3 phases (generally): touch down, touch move, touch up.
You say you only have a sprite so define some variables:
initX, initY, finalX and finalY. All floats (or ints if you cast them). And a couple of booleans: set1 and set2 all false
On touch down you ask if set1== false if so, set initX=eventX and initY=eventY (eventX and eventY would be here the X and Y of the touch event). Then set set1=true
On touch move you do the same as above, with set2. if set2==false, set finalX=eventX and finalY=eventY, then set2=true.
and you draw your sprite from (initX,initY) to (finalX,finalY) or if you're using width/height then finalX-initX for the width, finalY-initY for height.
I hope this helped. I didn't even know starling existed but since it's actionscript it must be pretty close to java in its syntax
I want to show the movement of a car in a road . I have a textfile containing the positions and I built the movement by updating the position of a car every second .lets say the plain is (200,200) . now what should I do for positions that are outside this screen ? how could I follow my car there ?
should I set up a camera or something?
by the way my app is 2D.
From my experience, there is no actual concept of setting up a camera in 2D programming, but I could be wrong. You'll have to do this yourself, create a camera class etc.....
What I think will end up happening is that the car will stay centered on the screen and everything under it will be moving instead. Depends on what you're trying to achieve.
So if your car is moving northeast at 20 km/h, don't actually move the car, make everything under the car move southwest at 20km/h (or how many pixels per frame this comes out to)
This is if you want to follow the car. If you want to center the "camera" on the car whenever it goes out of bounds you'll probably have to move the landscape and the car towards the center of the screen.
EDIT: I'm assuming that the car will be the main focus?? So it should always be at the center of the screen.
All objects in the game should have a velocity and a position. The position tells you where the object currently is and the velocity tells you how many x's and how many y's it should be moving per frame. So every frame you would say position = position + velocity.
The non-car objects can move off the screen as they wish without having the camera follow them, so let them go. Keep the car centered and adjust all the other objects' velocities based on the car's.
Ex:
Car's velocity (3, 0) ---> means it's moving right in the straight line at 3 pixels per frame
Object 1 velocity (4, 0) ---> means it's also moving right in a straight line but 4 pixels per frame
The velocity of object 1 will have to adjust itself according the the car's velocity. So say:
object1.position = object1.position + (object1.velocity - car.velocity)
Object 1's new velocity is (1, 0), so it's moving faster than the car by one.
If the car gains speed to let's say (5, 0) then object one will appear to be moving backwards by 1.