0
votes

I am newbie in IOS Gaming, and i need to create a game using Sprite Kit framework for functionality similar to angry bird pulley system, and also wants to find the distance the object is travelled from the pulley to its landing.

Can anyone help me out with this, i would be thankfull for it. Thanks in advance.

1
When you say "pulley" do you mean slingshot? As for distance, that's purely relative to your game design. 1 inch one the screen can be 1 inch or 1 mile. That part is up to you to decide.sangony
yes I mean slingshot, and also I don't even know how to calculate distance even relative to screen as wellsKhan

1 Answers

1
votes

One way you could code a slingshot effect would to use a starting point on the screen at let's say (x=100,y=100). You would display a SpriteNode of a slingshot with the Y centered at the (100,100).

The next step would be to use touchesBegan:withEvent: in the area of the slingshot to let your code know the player is looking to shoot the slingshot.

You would use touchesMoved:withEvent: to track how far back (how much tension) the player is pulling back from the slingshot.

The release would be triggtouchesEnded:withEvent. Based on how far the touch began (x=100) and how far back is was released (for example x=30), you can apply force like this:

float forceUsed = startTouchX - endTouchX;
[_projectile.physicsBody applyForce:CGVectorMake(forceUsed, 0)];

If you are looking to angle the shot you would also have to track Y and use that variable instead of the 0 above.

As for calculating distance between 2 points on the screen, it boils down to x and y coordinates. Subtract objectA.position.x from objectB.position.x

Things can get a lot more complex of course but that all depends on what you want to do in your code. Hope this helps.

P.S. The touches above are all part of the UIResponder Class.