crashoverride777 / swifty-sk-scroll-view

A Swift library to add a UIScrollView to your SpriteKit scenes. This library is deprecated and no longer supported.
MIT License
60 stars 11 forks source link

Touching nodes..... #1

Closed mshll closed 8 years ago

mshll commented 8 years ago

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 : ]

crashoverride777 commented 8 years ago

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

mshll commented 8 years ago

Alright I'll try it!... thanks btw for this awesome project :)

crashoverride777 commented 8 years ago

Thank you very much. Let me know how it goes.

mshll commented 8 years ago

It went just how it suppose to be!! thanks again..

crashoverride777 commented 8 years ago

Awesome, happy coding

mshll commented 8 years ago

Hey again..

well I have another issue :3

I tried to press the node and it did a command and moved me to the main scene and everything went smoothly but! when I do it over and over repeatedly the app crash and this happen: screen shot 2016-03-19 at 3 42 03 pm

crashoverride777 commented 8 years ago

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?

mshll commented 8 years ago

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)

    }
crashoverride777 commented 8 years ago

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

mshll commented 8 years ago

Alright, and thanks a lot!

crashoverride777 commented 8 years ago

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

mshll commented 8 years ago

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!

crashoverride777 commented 8 years ago

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.

mshll commented 8 years ago

It's normal to have bugs.. Thanks and well do!

crashoverride777 commented 8 years ago

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.

mshll commented 8 years ago

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.. :)

crashoverride777 commented 8 years ago

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.