ScrollView in SpriteKit

I found several other questions and answers similar to this, but none of them are perfect for me.

My vision is to have a horizontal scrollable view at the bottom of the screen, where I can scroll through what will look like cards in my hand. Ideally, I could ultimately make the map in the middle a little larger and give it a highlighted view to show the user which map is selected. It would be even better if I could understand how to save the scroll size by resizing for the number of sprites (maps) in the view.

Anyway, I'm still very new to Xcode and Swift, so it's hard for me to take what I find and change. But I hope to learn quickly.

I still understand that UIScrollView can overlay the scene and with moving spritenode I could scroll the view. The view then converts the coordinates somehow into a SpriteKit scene to move the sprites that will look as if they are visible. I think it works. Any help would be great. I'm pretty stuck. <3

+4
source share
1 answer

You must make your own logic, which takes place in touchesMoved(), using the global / member variable.

Unfortunately, a lot of gamedev and SK are mathematics and logic. You have to come up with your problems and solutions. There is no manual, because the possibilities in programming and Swift are endless :)


:

, touch , " ", .

, , 0,0 ( , ). , 25, 0... " " + 25x.

delta , moveBy ... , X +25, ( , ). deltaX -25, .

, update() touchesMoved(), deltaX.

, ... , :

for touch in touches {
   myGlobalDeltaX = myDeltaXFunc(currentTouch: touch)
   myMoveFunc(cards: allTheCards, byDeltaX: myGlobalDeltaX)

- Delta, , .
- myMoveFunc - , , .moveBy .


:

, , touchesEnded() update() , / node ... -

// `self` here refers to your GameScene class' instance, which is just an `SKScene` object
let centerX = self.frame.midX
let centerY = self.frame.midY
let center = CGPoint(x: centerX, y: centerY)

let centerNode = self.nodes(at: center)

, centerX centerY , , :) , .

centerNode, , , "" .

let selectedCard = centerNode
mySelectionFunc(middleCard: selectedCard)

, , . , .

mySelectionFunc(middleCard: self.nodes(at: CGPoint(x: self.frame.x, y: self.frame.y)))

, !

+2

Source: https://habr.com/ru/post/1660243/


All Articles