I have a sprite looking like a pencil. I want to draw a line when user touches this sprite.
I am able to draw the line on touch location & move the sprite accordingly. The problem is that the line is not drawing from tip of the pencil which lies at left bottom of the sprite.
I don't want to move the left bottom edge of sprite under the touch point because then user will not be able to see the tip but instead shift the coordinates to draw to the tip itself.
I tried setAnchorPoints but that's not helping. Anyone tried this or has better ideas please do share. Thanks.
You could draw the line at something like pencil.position.y - (pencil.sizeofthesprite.y / 2) and it should be fine.
Related
If I have a sprite node, just a white circle somewhere on the screen, how am I able to make it so when I drag, let's say downwards and slightly to the left, the circle sprite would launch upwards and to the right and then gradually come down, like a golf shot.
Another way of explaining the mechanic is the Angry Birds game, where you launch the birds of the slingshot, the birds move in the opposite direction of your drag and gradually come down.
For another live example of the mechanics of the circle, look at the app, Desert Golfing.
Thanks, and if you don't know what I mean just comment and I'll try to explain it better.
OPTIONAL: If you do know how to do the slingshot type mechanic for the circle, do you also know how to add an arrow to the screen so users know which way the circle will launch?
Ill try to break your problem down into small steps that you could then solve yourself:
Detect the swipe:
use a UIPanGestureRecognizer. You will be able to implement a method that is called whenever a user drags their finger in a certain direction.
Here are some good references:
- Pan Gesture Official Documentation
- A very useful question that can serve you as a guide
Detect the magnitude of the swipe in order to impart an impulse
Check out the second link above. What you have to do is in the method for the gesture recognizer you will detect certain flags such as when the user starts the pan or ends the pan. Then, you can check for the location at those moments. With the Pythagorean theorem you should be able to get the distance and use that as the magnitude.
Apply impulse:
Create a physics body for your sprite and then make sure that you have gravity set inside your physics world. This allows the sprite to move in a parabolic motion. Then, use applyImpulse: on your physics body with your magnitude.
Regarding the arrow, you can easily do some delegation from within your pan gesture handler that gets the magnitude of the swipe and projects a reflection that your arrow will then show. Your question is pretty loaded so going into more detail is impossible, but best of luck. Hope this helps!
I am working on a cocos2d-x based game on iOS platform.
In my game, I need to detect circular gesture over the bounding box of a particular sprite.
I have the solution to detect the circle when a touch event is ended at
http://blog.federicomestrone.com/2012/01/31/creating-custom-gesture-recognisers-for-ios/
But, it is required that the circle should be detected during onTouchMove and not onTouchEnded.
Also, I need to know the direction in which circle is being created, i.e. clockwise or anti-clockwise. and change of direction during finger move.
Another requirement is to count the number of circles completed while the finger is moving.
Need some help with this kind of circle gesture detection.
Thanks in advance.
During a touch move event you can determine the angle from the center of the sprite to the touch position using the following (pseudocode):
angle = atan2(touch.y - spriteCenter.y, touch.x - spriteCenter.x);
Then find the angular offset since the last measurement and add it to a running tally:
angleOffset = atan2(sin(angle-lastAngle), cos(angle-lastAngle));
angleRotated += angleOffset;
|angleRotated| will measure how many revolutions were made and in which direction they occurred.
You may also want to take the distance between the touch and the sprite into consideration to ensure the shape is circle-like.
I am trying to figure out how to drag a UIButton around a circle while maintaining its orientation and also pushing the rest of the buttons along the circle. Basically constrain it to the radius of a circle.
If you dragged A around the circle B would stay in front of it and also go around the circle. It is kind of like if you looked at a ferris wheel from the side
thanks in advance
In my app I wanted to position in the center of the screen a UIImage, with the shape of a circle. Then I wanted the user to be able to rotate the image buy touching one specific point on the circumference of the circle, and dragging, just like a wheel, but I have no idea where to start form.
I know I can use the touches began, moved, and ended, but how can I fix a point?
You can adjust the origin property of your UIView. This should force the rotation around that point.
I would like to draw a free hand polygon with one finger on top of a Mkmapview. I know how to draw a free hand polygon on a UIView and I know how to bring up a mkmapview.
I don't know if I can use the overlay function because I need to draw the polygon when my finger moved. I assume that this involves multitouch event and drawRect but i can not make it work when I put them together.
Thanks in advance if someone can help.