Hot answers tagged

52

A perfectly straight line would also be the shortest possible line with a total length of sqrt((x1-x2)² + (y1-y2)²). A more scribbly line will be a less ideal connection and thus be inevitably longer. When you take all individual points of the path the user drew and sum up the distances between them, you can compare the total length with the ideal length. ...


31

This might not be the best way to implement this either, but I suggest a RMSD (root mean square deviation) could be better, than merely the distance method, in cases mentioned by Dancrumb (see first two lines below). RMSD = sqrt(mean(deviation^2)) Note: The sum of the absolute deviations (integral-like) might be better, as it does not average out positive ...


23

Existing answers do not take into account that the end points are arbitrary (rather than given). Thus, when measuring the straightness of the curve, it does not make sense to use the end points (for example, to calculate expected length, angle, position). A simple example would be a straight line with both ends kincked. If we measure using the distance from ...


16

There's a comprehensive question on UX about touchscreen button sizes. The recommended size depends highly on your game, but the minimum size is quoted as 9-12mm, about half an inch, and this is based on the size of fingers. Keep in mind that this is a guideline, and the cost of ignoring it is that your users will tap the wrong thing on occasion. Depending ...


8

I hope I am understanding your question correctly -- if not let me know. I believe the following is where you are unprojecting the coordinates: @Override public boolean mouseMoved(int screenX, int screenY) { worldCoordinates = camera.unproject(new Vector3(screenX, screenY, 0)); return true; } Because you are using a viewport, you must add the ...


7

There are pros and cons to both, but the decision is ultimately yours. You'll have to decide based on the style of your game and the type of game. Static position: Always in the same place, predictable. This means the user will always know where the indicator will be and allows them to avoid covering it up on their own. Kind of boring and requires some kind ...


7

In a word: Swiping. I played Pac-Man championship edition on my Android phone and what I thought really worked for it is that while there was an on screen joystick, you didn't actually have to touch it to move Pac-Man in the proper direction. If your finger fell off the joystick it didn't matter. All that mattered is in what direction you moved your finger. ...


6

The ACTION_MOVE event provides data for multiple fingers. You can use event.getPointerCount() to find out how many fingers are touching the screen. Then you can loop through the pointers to get data for each one. Example: case MotionEvent.ACTION_MOVE: int count = event.getPointerCount(); for (int i = 0; i < count; i++) { x[i] = event....


5

I can't tell you about cocos2d specifically, but in general, tap vs. drag is the same input recognition problem as mouse click vs. drag. The standard way to handle this is to note when a mousedown (or touch) happens, and store where it happened, for later reference. Watch for mousemoved (or touchmoved) events to see if it moves around. If it moves to a ...


5

Your code is only looking at the Single Touch portion of the event. You will only ever receive information about the first finger to hit the screen. If you lift that finger, your event will jump over to the second finger that is down, right? You need to implement MotionEvent.ACTION_MASK to get the multi-touch parts. Something like: int action = ...


4

What exactly "doesn't work" about the multi-touch? The second touch provides no apparent effect at all, or it provides some input but the inputs don't work properly? Many Android phones, even newer ones, may not have "true" multi-touch. These phones have hardware limitations that effectively let them mimic pinching and rotating gestures, but don't ...


4

You can use atan2 to find the angle of rotation. If (tx, ty) is your touch coordinate and (x,y) is the center of your rotation you can call double rot = Math.atan2(ty-y, tx-x); //first y then x rot is an angle in radians [-pi, pi] just rotate your triangle using it EDIT Implementation. Assuming that you have setted up opengl so that screen coordinates ...


4

What if you treated a half of the screen like a virtual track ball where the position/speed of your character is directly tied to that of the ball? Swiping and releasing would set your character into constant motion (and cause the trackball to spin). Holding your finger on the screen would be like holding the trackball so that you could make small ...


4

You check for input in your Update method. Update is where you'll respond to input, move entities around, do collision detection, update counters, update and data that needs updating. Draw is where you draw everything... Initialize is where you set initialize whatever data structures you're using. LoadContent is where you load save states, load textures/...


4

I figured out the solution. The problem was that Listeners would work only after we set a bound to our Actor. I hadn't set any bounds, so it was not taking the touches. Now I set the bounds in the draw() method(so that it will get updated each time the actor moves) and it is working like a charm. @Override public void draw(Batch batch, float parentAlpha) { ...


3

As Byte56 said, the decision is yours. But my personal opinion is that an floating HUD game is better. I think something like this: is better if you don't need the extra space around the user's finger that's occupied by the GUI. Then you can make it adapt depending on some variables, like it becoming smaller when an enemy is hit, ...


3

You may split the arrow into a shaft and a head. Then you just enlarge the shaft and add the head later on. This will prevent your arrowhead from being stretched and if you pick a shaft image which will not show any signs of strechting (i.e. a rectangle) the whole process will be hidden.


3

Seriously, Google that stuff: http://docs.unity3d.com/Documentation/Manual/Input.html There is a complete manual on unity. Took me just one google search.


3

I think you need to translate screen to world space. Camera.ScreenToWorldPoint


3

Personally, I've found most "on screen joysticks" pretty lame, no matter how slickly they're implemented. Its a pretty clear case of taking a solution from a different technology (consoles/arcades) and trying to apply it to a new and rather different technology (multi-touch screens), and resulting in a mess. So, I'd add some more "cons" to your list that ...


3

If your hit test is really that simple, then instead of doing more complicated triangle intersection as Byte56 suggests you could do simple AABB-ray intersection test. The intersection test will tell you the point that was hit. This point in model space will lie on one of the faces (so one of X, Y, or Z will be +/-h, where h is the half-width of your cube)....


3

Do this in character controller script's Update() First of all you have to detect the user input via touch(begin/moved/ended) methods and then you have to calculate the gesture it ended up in like swipe-left. You can assign a bool to it like SwipeL = true; Now you have to add a condition in the methods where character movement is mapped with Input.GetKey("...


3

On Mobile you need to need pass Touch.fingerId as parameter into EventSystem.IsPointerOverGameObject(int pointerID), but it is still not perfect, as it fails on TouchPhase.Ended. See this code: public void Update() { foreach (Touch touch in Input.touches) { int pointerID = touch.fingerId; if (EventSystem.current....


3

This is a grid based system, right? Find your own points for the line and calculate the slope of the line. Now, using that calculation, determine valid points that the line would pass through, given some margin of error off the exact value. Through a short amount of trial-and-error testing, determine what good and bad amount of matching points would exist ...


3

A very easy and intuitive measure is the area between the best fitting straight line and the actual curve. Determining this is fairly straightforward: Use a least-squares fit on all points (this prevents the end-kink problem mentioned by Joel Bosveld). For all points on the curve, determine the distance to the line. This is also a standard problem. (linear ...


3

One option is to use a wake lock. Example from the docs: PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "My Tag"); wl.acquire(); // screen and CPU will stay awake during this section wl.release(); I've got this answer from this stack overflow post. For ...


3

Detecting swipe curvature Treat the finger swipe as a polyline. Approximate its curvature, and use that as a multiplier for how much to “curl” the resulting shot either left or right. Let's say a swipe path has no curvature if it goes linearly from the start (the circle), to the end, or curvature value 0. I'll emphasise other swipes' differences to this ...


3

When compiling for a traditional Windows / Mac / Linux desktop setup, no this won't work. I dug through the SFML code and it turns out that the sf::Touch implementation won't really work unless you're on a touch-based device: From https://github.com/SFML/SFML/blob/master/src/SFML/Window/Win32/InputImpl.cpp bool InputImpl::isTouchDown(unsigned int /*finger*...


3

The biggest issue is that you're attempting to detect both horizontal and vertical swipes in separate functions but at the same time. When one happens, the other might also happen (unless you swipe at a perfect angle). Swipe detection is a problem that's been solved before although the link you posted in the comments makes it look like vertical swipes ...


Only top voted, non community-wiki answers of a minimum length are eligible