I am creating a random spinner element for my iOS app in Swift using SpriteKit, but currently my method is not very efficient, and I am pretty sure that it may not be the best way to achieve what I am aiming for. The process that I am doing now is essentially.- When loading a scene, swipe through a list of 13 different elements (stored in JSON)- create a group of nodes displaying the corresponding data- Add each group of nodes to the second group of nodes, slightly moving them along the x axis, creating a long line SKNode (elements for the counter)- Moving this group along the x axis to give the impression that it rotates through objects
But this method takes about 6 seconds to even load the scene (and the delay is adding the nodes to a much larger node: group.addChild(spinnerItem)and since I'm only new to Swift. I am sure there is a better way that I do this, so any help / advice is appreciated to improve this code, because it seriously needs to improve performance!
group.addChild(spinnerItem)
Here is the didMove function ...
override func didMove(to view: SKView) { var xPos = CGFloat(self.frame.width + 150) var eventWeapon = weapon() for n in 0...13{ eventWeapon = getWeapon(caseName: "chromaCase", weaponID: n) print(eventWeapon) let texture = createSpinnerItem(wName: "\(eventWeapon.name)", wSkin: "\(eventWeapon.skin)", wColor: "\(eventWeapon.color)") let spinnerItem = SKSpriteNode(texture: texture) spinnerItem.position = CGPoint(x: xPos, y: self.frame.height / 2) group.addChild(spinnerItem) xPos = xPos + 300 * 1.2 } self.addChild(group) group.run(SKAction.moveBy(x: -5000, y: 0, duration: 2)) }
and the function createSpinnerItemused in this ...
createSpinnerItem
func createSpinnerItem(wName: String, wSkin: String, wColor: String) -> SKTexture { let object = SKNode() let bGround = SKShapeNode(rectOf: CGSize(width: 300, height: 300)) bGround.fillColor = color.offWhite bGround.strokeColor = color.gray bGround.lineWidth = 5 object.addChild(bGround) let titleBG = SKShapeNode(rectOf: CGSize(width: 300, height: 100)) if wColor == "blue"{ titleBG.fillColor = color.CSGOblue } if wColor == "red"{ titleBG.fillColor = color.CSGOred } if wColor == "pink"{ titleBG.fillColor = color.CSGOpink } if wColor == "purple"{ titleBG.fillColor = color.CSGOpurple } titleBG.strokeColor = color.gray titleBG.lineWidth = 5 titleBG.position = CGPoint(x: 0, y: -150 + 50) object.addChild(titleBG) let weaponName = SKLabelNode() weaponName.text = wName weaponName.fontColor = color.white weaponName.fontSize = 40 weaponName.fontName = "Avenir-Regular" weaponName.verticalAlignmentMode = .center weaponName.position = CGPoint(x: 0, y: -150 + 70) object.addChild(weaponName) let weaponSkin = SKLabelNode() weaponSkin.text = wSkin weaponSkin.fontColor = color.white weaponSkin.fontSize = 20 weaponSkin.fontName = "Avenir-Regular" weaponSkin.verticalAlignmentMode = .center weaponSkin.position = CGPoint(x: 0, y: -150 + 30) object.addChild(weaponSkin) return object }
, , - , "" , . 6 - , , . , , . , KnightOfDragon .
, , , SK SO. , . , , , , , . ? , , . JSON . , , , , , . , , , didMove viewDidLoad. , , , . , , , , . , - - .
didMove
viewDidLoad
, , , . , , . - .
, SKNode , (, addChild ). SKAction, . .
SKNode
addChild
SKAction
Source: https://habr.com/ru/post/1659988/More articles:LLMNR (Local Multicast Name Resolution) Java Responder - javaPowerShell crashes with `if ($? = $ False)` - powershellPhoenix programming: undefined function page_path / 2 - elixirFind the longest route in a 2D array - algorithmhttps://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1659987/another-git-process-seems-to-be-running-and-thus-cant-commit&usg=ALkJrhhI3u13ZYyu3q-YrBAtsKg6adhIMQWhat is the purpose of `binding` from` VkVertexInputBindingDescription`? - c ++How is ggplot2 plus defined? - operatorsHow to handle 2 to 1 ratio in MVC? - c #How could this assembly be possible? - catom control command stops working after restart - shellAll Articles