|
Sorry to say I'm befuddled by the first challenge, did the other 2 no problem, but I'm really not sure what your asking for.
TouchesEnded - happens when the user picks up their finger... Is this about event bubbling? Is the idea to cancel/handle the event so it doesn't run touches moved? ok hint plz. Or just explode the spaceship if they lift their finger? That seems rather punishing and unintuitive. The cheat to me, it seems to happen on touchesBegan/Moving, where it doesn't check that the user actually tapped the spaceship.. (a check nicely shown in Proj 14) I'm really at a loss at what I should be understanding in touchesEnded. At touchEnded, it's already moved the space ship... I could move the update to position code to Ended, but then it would only update on finger lifted i must be going down a blind alley, please help me back on track, thanks. |
|
Not sure how many hints do you want :-) But the key is to implement both |
|
huh, thanks will do that :D So there's no special "one-liner hack" for touchesEnded, i was missing? |
|
I ended up sticking with touchesMoved, using excepts from Paul's code for node in nodes(at:touch.location(in self)) { if node == player { //update player.position Is that bad from from a performance angle? The above code seemed clear & consise to me... Using touchesBegan/Ended seemed cluttered, and possibly bad for multitouch? if it had a bool touchedShip set on tBegan, update ship's position if touchedShip is true in tMoved, the set it to false in tEnded... but... how well would that handle leaving a finger on the screen, then add a new touch, or multi touch? I may be over thinking things... it just seemed to complicate things in this case. |
|
I think your approach is perfectly viable, what I did was a very similar thing:
That way, I can control when the ship can be moved and when not. So in my case, EDIT: Ah, now I remember. My first approach was identical to yours. However, I noticed that my finger was 'losing' the ship when I was moving it very fast. The above method got rid of all the problems. |
|
Hello everyone! I kept what Paul wrote on
I'm not really sure why but it works sometimes. I've done several tests and the times it doesn't work is because:
I also feel like all the Any insights? |
|
I use this formula to calculate distance between 2 CGPoint in touchMoved"var location = touch.position(in: self)" and "player.position": func CGPointDistanceSquared(from: CGPoint, to: CGPoint) -> CGFloat { return (from.x - to.x) (from.x - to.x) + (from.y - to.y) (from.y - to.y) } if it is > 5000 or some thing, you can modify it. it will return from touchMoved function. So that player can not cheat to lift finger then moved finger in a distance that too far the original one. |
|
i decided to use the logic if the touchesBegan location of the touch contains the rocket than move the rocket else don't move the rocket..
So keeping with paul's original code for touchesMoved(), i added touchesBegan that returns a boolean to detect if |
|
SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure your entire paywall view without any code changes or app updates.
Sponsor Hacking with Swift and reach the world's largest Swift community!
This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.
All interactions here are governed by our code of conduct.
Link copied to your pasteboard.