Touching nodes.....
Closed this issue · 17 comments
I really can't figure out how can I make it recognise when I touch a node in page1 for example .. I want to to make a line of command but when I try to do it it works with the whole page not just the node...
so can you explain how I make it recognise when I touch a node in some page of scroll view please?
Thanks : ]
Hey,
Thanks for using my helper.
I recently updated it so you should get the latest version as of today. In the sample project I included touching a node in the scrollView. See the GameScene.swift file.
Hope that helps
Alright I'll try it!... thanks btw for this awesome project :)
Thank you very much. Let me know how it goes.
It went just how it suppose to be!! thanks again..
Awesome, happy coding
Him I dont know, you would need to show me some more code of what you are trying to do.
Are you removing the collection view from the superView before you change scenes?
Well this is the code:
for touch in touches{
let location = touch.locationInNode(self)
let node = nodeAtPoint(location)
if (node == Skin2Shop && highscore >= 0) || (node == Skin2 && highscore >= 0) { // or check for spriteName -> if node.name == "SpriteName"
MovetoScene()
PlayerStringg = "PlayerSkin2"
PlayerStringDefault.setValue(PlayerStringg, forKey: "PlayerString")
PlayerStringDefault.synchronize()
}
else if (node == SkinMainUnLocked) || (node == SkinMain) { // or check for spriteName -> if node.name == "SpriteName"
MovetoScene()
PlayerStringg = "Player"
PlayerStringDefault.setValue(PlayerStringg, forKey: "PlayerString")
PlayerStringDefault.synchronize()
}
else if BackButton.containsPoint(location) && BackButton.hidden == false{
MovetoScene()
}
else {
}
and this is the function I used:
func MovetoScene(){
scene?.removeAllChildren()
scrollView.removeFromSuperview()
let gameScene:SKScene = GameScene(size: self.size)
scene!.view?.presentScene(gameScene, transition: transition)
}
Alrite, Thanks for that. I will play around with the sample project and see what happens. Ill get back to you soon.
Sorry for the inconvenience
Alright, and thanks a lot!
Just was able to replicate the same problem. It seems to be this line in the helper.
private unowned let: SKScene
change it too this
private let: SKScene
The scrollView property in your scene is weak anyway so you can get rid of it and still not have a strong reference.
I will update my helper again on github including scene transitions.
Let me know how it goes.
Hope this helps
YOU'RE MY HERO!
it went smoothly no crashes or anything! thanks so much..
I thought the problem in my codes so I changed them 1000 times :p but really THANKS!
My pleasure and sorry for this bug. I haven't check this helper in a while because I am actually using a similar helper at the moment but for UICollectionViews. Please dont hesitate to ask further questions.
Thank you for bringing this to my attention.
It's normal to have bugs..
Thanks and well do!
Unfortunately. I recently started learning about retain cycles in swift (strong and weak properties) and its still quite new to me. The code is based on old obj C code I found on stack overflow so I had to change it to swift. Obviously in a UIKit app doing a scrollView is much easier because you can use storyboards. I still wanted to use one for Spritekit which is why I made this helper, it is not the most elegant solution in the world because you have to do it in code and do the trickery with the MoveableNode, but it works for basic menus or maps.
Thanks again for your help and support.
Maybe it's not the best but at least you did it right?
and to be honest this is the best and most easy one I found in the internet.. :)
Yeah I couldn't find one either in swift and thats why I made it. To the best of my knowledge there isn't better alternative than doing something like this to get it to work in Spritekit.
The helper is best for smaller menus like a character select screen, basic level select screen etc.
If you have a massive menus than you probably want to use a CollectionView with reusable cells (using that for my game as the level select screen with 40+ levels). It makes it easier to add more stuff.