ios - SpriteKit - How can I catch the event when the touch moves over a sprite, but didn't actually begin on the sprite -
in spritekit, want catch event when touch moves on sprite, hasn't started on sprite, on piece of skscene.
i can catch touchesbegan inside skspritenode if touch starts on , dragged on it, not when touch started on node - b - , dragged on node - a. knows how catch one, because think doing wrong here.
try this: sorry swift.. can same thing in obj c
import spritekit class gamescene: skscene { let sprite = skspritenode(color: skcolor.redcolor(), size: cgsizemake(100, 100)) var startedoutsidesprite = true override init(size: cgsize) { super.init(size: size) sprite.position = cgpointmake(size.width/2, size.height/2) addchild(sprite) } override func touchesbegan(touches: set<uitouch>, withevent event: uievent?) { if let touch = touches.first { let location = touch.locationinnode(self) if !sprite.containspoint(location) { startedoutsidesprite = true } } } override func touchesmoved(touches: set<uitouch>, withevent event: uievent?) { if let touch = touches.first { let location = touch.locationinnode(self) if sprite.containspoint(location) && startedoutsidesprite { print("yayyy") // code here } } } override func touchesended(touches: set<uitouch>, withevent event: uievent?) { startedoutsidesprite = false } required init?(coder adecoder: nscoder) { fatalerror("init(coder:) has not been implemented") } }
Comments
Post a Comment