FIX Slider performance
* create hidden silderKnob
This commit is contained in:
parent
ba00702e67
commit
adf01db4bf
@ -12,12 +12,14 @@ import SpriteKit
|
|||||||
class SliderNode :SKNode {
|
class SliderNode :SKNode {
|
||||||
|
|
||||||
var sliderLine :SKShapeNode
|
var sliderLine :SKShapeNode
|
||||||
var sliderKnob :SliderKnob
|
var hiddenKnob :SliderKnob
|
||||||
|
var silderKnob :SKSpriteNode
|
||||||
var width: CGFloat
|
var width: CGFloat
|
||||||
|
|
||||||
var getValue: CGFloat{
|
var getValue: CGFloat{
|
||||||
get{
|
get{
|
||||||
return ((sliderKnob.position.x.rounded() - sliderKnob.min) / width)
|
silderKnob.position = hiddenKnob.position
|
||||||
|
return ((hiddenKnob.position.x.rounded() - hiddenKnob.min) / width)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -27,19 +29,30 @@ class SliderNode :SKNode {
|
|||||||
sliderLine.position = position
|
sliderLine.position = position
|
||||||
sliderLine.fillColor = SKColor.white
|
sliderLine.fillColor = SKColor.white
|
||||||
sliderLine.zPosition = 4
|
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()
|
|
||||||
|
|
||||||
|
|
||||||
|
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) {
|
required init?(coder aDecoder: NSCoder) {
|
||||||
fatalError("init(coder:) has not been implemented")
|
fatalError("init(coder:) has not been implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class SliderKnob: SKShapeNode {
|
class SliderKnob: SKShapeNode {
|
||||||
@ -60,6 +73,7 @@ class SliderKnob: SKShapeNode {
|
|||||||
}
|
}
|
||||||
if(self.position.x >= max){
|
if(self.position.x >= max){
|
||||||
self.position.x = max
|
self.position.x = max
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -88,8 +88,9 @@ class EntityManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if let sliderNode = entity.component(ofType: SliderComponent.self)?.sliderNode {
|
if let sliderNode = entity.component(ofType: SliderComponent.self)?.sliderNode {
|
||||||
scene.addChild(sliderNode.sliderKnob)
|
scene.addChild(sliderNode.hiddenKnob)
|
||||||
scene.addChild(sliderNode.sliderLine)
|
scene.addChild(sliderNode.sliderLine)
|
||||||
|
scene.addChild(sliderNode.silderKnob)
|
||||||
}
|
}
|
||||||
if let labelNode = entity.component(ofType: LabelComponent.self)?.labelNode {
|
if let labelNode = entity.component(ofType: LabelComponent.self)?.labelNode {
|
||||||
scene.addChild(labelNode)
|
scene.addChild(labelNode)
|
||||||
@ -102,8 +103,9 @@ class EntityManager {
|
|||||||
spriteNode.removeFromParent()
|
spriteNode.removeFromParent()
|
||||||
}
|
}
|
||||||
if let sliderNode = entity.component(ofType: SliderComponent.self)?.sliderNode {
|
if let sliderNode = entity.component(ofType: SliderComponent.self)?.sliderNode {
|
||||||
sliderNode.sliderKnob.removeFromParent()
|
sliderNode.hiddenKnob.removeFromParent()
|
||||||
sliderNode.sliderLine.removeFromParent()
|
sliderNode.sliderLine.removeFromParent()
|
||||||
|
sliderNode.silderKnob.removeFromParent()
|
||||||
}
|
}
|
||||||
if let modalButton = entity.component(ofType: ButtonComponent.self) {
|
if let modalButton = entity.component(ofType: ButtonComponent.self) {
|
||||||
modalButton.buttonNode.removeFromParent()
|
modalButton.buttonNode.removeFromParent()
|
||||||
@ -336,7 +338,7 @@ class EntityManager {
|
|||||||
|
|
||||||
if let slider = modal.component(ofType: SliderComponent.self) {
|
if let slider = modal.component(ofType: SliderComponent.self) {
|
||||||
slider.sliderNode.removeFromParent()
|
slider.sliderNode.removeFromParent()
|
||||||
slider.sliderNode.sliderKnob.removeFromParent()
|
slider.sliderNode.hiddenKnob.removeFromParent()
|
||||||
slider.sliderNode.sliderLine.removeFromParent()
|
slider.sliderNode.sliderLine.removeFromParent()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,6 +81,7 @@ class GameScene: SKScene{
|
|||||||
if GameCenterManager.sharedInstance.gameEnded && !gameEndEffects {
|
if GameCenterManager.sharedInstance.gameEnded && !gameEndEffects {
|
||||||
gameEnd()
|
gameEnd()
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func addAttackDetails(touchLocation: CGPoint){
|
func addAttackDetails(touchLocation: CGPoint){
|
||||||
|
Loading…
Reference in New Issue
Block a user