FIX Slider performance
* create hidden silderKnob
This commit is contained in:
parent
ba00702e67
commit
adf01db4bf
@ -11,57 +11,71 @@ import SpriteKit
|
||||
|
||||
class SliderNode :SKNode {
|
||||
|
||||
var sliderLine :SKShapeNode
|
||||
var sliderKnob :SliderKnob
|
||||
var width: CGFloat
|
||||
var sliderLine :SKShapeNode
|
||||
var hiddenKnob :SliderKnob
|
||||
var silderKnob :SKSpriteNode
|
||||
var width: CGFloat
|
||||
|
||||
var getValue: CGFloat{
|
||||
get{
|
||||
return ((sliderKnob.position.x.rounded() - sliderKnob.min) / width)
|
||||
}
|
||||
}
|
||||
var getValue: CGFloat{
|
||||
get{
|
||||
silderKnob.position = hiddenKnob.position
|
||||
return ((hiddenKnob.position.x.rounded() - hiddenKnob.min) / width)
|
||||
}
|
||||
}
|
||||
|
||||
init(width: CGFloat, position: CGPoint) {
|
||||
self.width = width
|
||||
sliderLine = SKShapeNode(rectOf: CGSize(width: width, height: 8))
|
||||
sliderLine.position = position
|
||||
sliderLine.fillColor = SKColor.white
|
||||
init(width: CGFloat, position: CGPoint) {
|
||||
self.width = width
|
||||
sliderLine = SKShapeNode(rectOf: CGSize(width: width, height: 8))
|
||||
sliderLine.position = position
|
||||
sliderLine.fillColor = SKColor.white
|
||||
sliderLine.zPosition = 4
|
||||
sliderKnob = SliderKnob(circleOfRadius: 20)
|
||||
sliderKnob.min = position.x - width / 2
|
||||
sliderKnob.max = position.x + width / 2
|
||||
sliderKnob.fillColor = SKColor.red
|
||||
sliderKnob.zPosition = sliderLine.zPosition + 1
|
||||
sliderKnob.position = CGPoint(x: sliderLine.position.x, y: sliderLine.position.y + 1)
|
||||
super.init()
|
||||
|
||||
}
|
||||
|
||||
required init?(coder aDecoder: NSCoder) {
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
}
|
||||
hiddenKnob = SliderKnob(circleOfRadius: 60)
|
||||
hiddenKnob.min = position.x - width / 2
|
||||
hiddenKnob.max = position.x + width / 2
|
||||
hiddenKnob.fillColor = SKColor.red
|
||||
hiddenKnob.alpha = 0.001
|
||||
hiddenKnob.zPosition = sliderLine.zPosition + 1
|
||||
hiddenKnob.position = CGPoint(x: sliderLine.position.x, y: sliderLine.position.y + 1)
|
||||
|
||||
silderKnob = SKSpriteNode(texture: SKTexture(imageNamed: "yellow_boxTick"))
|
||||
silderKnob.position = hiddenKnob.position
|
||||
silderKnob.zPosition = hiddenKnob.zPosition - 1
|
||||
silderKnob.size = CGSize(width: 50, height: 50)
|
||||
|
||||
super.init()
|
||||
self.name = "slider"
|
||||
}
|
||||
|
||||
required init?(coder aDecoder: NSCoder) {
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
class SliderKnob: SKShapeNode {
|
||||
var min = CGFloat()
|
||||
var max = CGFloat()
|
||||
var min = CGFloat()
|
||||
var max = CGFloat()
|
||||
|
||||
override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
|
||||
override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
|
||||
|
||||
for touch in touches {
|
||||
let touchLocation = touch.location(in: self.scene!)
|
||||
for touch in touches {
|
||||
let touchLocation = touch.location(in: self.scene!)
|
||||
|
||||
if self.position.x >= min - 1 && self.position.x <= max + 1{
|
||||
self.position.x = touchLocation.x
|
||||
}
|
||||
if self.position.x >= min - 1 && self.position.x <= max + 1{
|
||||
self.position.x = touchLocation.x
|
||||
}
|
||||
|
||||
if(self.position.x <= min){
|
||||
self.position.x = min
|
||||
}
|
||||
if(self.position.x >= max){
|
||||
self.position.x = max
|
||||
}
|
||||
}
|
||||
}
|
||||
if(self.position.x <= min){
|
||||
self.position.x = min
|
||||
}
|
||||
if(self.position.x >= max){
|
||||
self.position.x = max
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -88,8 +88,9 @@ class EntityManager {
|
||||
}
|
||||
}
|
||||
if let sliderNode = entity.component(ofType: SliderComponent.self)?.sliderNode {
|
||||
scene.addChild(sliderNode.sliderKnob)
|
||||
scene.addChild(sliderNode.hiddenKnob)
|
||||
scene.addChild(sliderNode.sliderLine)
|
||||
scene.addChild(sliderNode.silderKnob)
|
||||
}
|
||||
if let labelNode = entity.component(ofType: LabelComponent.self)?.labelNode {
|
||||
scene.addChild(labelNode)
|
||||
@ -102,8 +103,9 @@ class EntityManager {
|
||||
spriteNode.removeFromParent()
|
||||
}
|
||||
if let sliderNode = entity.component(ofType: SliderComponent.self)?.sliderNode {
|
||||
sliderNode.sliderKnob.removeFromParent()
|
||||
sliderNode.hiddenKnob.removeFromParent()
|
||||
sliderNode.sliderLine.removeFromParent()
|
||||
sliderNode.silderKnob.removeFromParent()
|
||||
}
|
||||
if let modalButton = entity.component(ofType: ButtonComponent.self) {
|
||||
modalButton.buttonNode.removeFromParent()
|
||||
@ -336,7 +338,7 @@ class EntityManager {
|
||||
|
||||
if let slider = modal.component(ofType: SliderComponent.self) {
|
||||
slider.sliderNode.removeFromParent()
|
||||
slider.sliderNode.sliderKnob.removeFromParent()
|
||||
slider.sliderNode.hiddenKnob.removeFromParent()
|
||||
slider.sliderNode.sliderLine.removeFromParent()
|
||||
}
|
||||
|
||||
|
@ -81,6 +81,7 @@ class GameScene: SKScene{
|
||||
if GameCenterManager.sharedInstance.gameEnded && !gameEndEffects {
|
||||
gameEnd()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func addAttackDetails(touchLocation: CGPoint){
|
||||
|
Loading…
Reference in New Issue
Block a user