带有Spritekit的卧式纺车

问题描述

我愿意用SpriteKit创建一个水平旋转的转盘,将其用作我的主角手机主页。 这样的东西,可以更好地解释我:一个在水平旋转时滚动元素的轮子。 What I'm looking for

我已经创建了一个名为Box的类来创建图标并委托它们的幻灯片,在此附加两个代码,以使其尽可能清晰,并帮助您完成我的工作。 这是我的Box类代码:

SELECT table_feature_value.id_feature_value FROM feature_value as table_feature_value

LEFT JOIN feature_product as table_feature_product ON table_feature_product.id_feature = table_feature_value.id_feature

LEFT JOIN product as table_product ON table_product.id_product = table_feature_product.id_product


WHERE ( table_feature_product.id_feature IS NULL OR table_product.id_product IS NULL )

这是我的GameScene类:

    import SpriteKit
    import GameplayKit
    
    
    protocol BoxDelegate: NSObjectProtocol {
        func boxSwiped(to: String)
    }

    class Box: SKSpriteNode {

    weak var boxDelegate: BoxDelegate!
    private var moveAmtX: CGFloat = 0
    private var moveAmtY: CGFloat = 0
    private let minimum_detect_distance: CGFloat = 50
    private var initialPosition: CGPoint = CGPoint.zero
    private var initialTouch: CGPoint = CGPoint.zero
    private var resettingSlider = false
    var rest: CGFloat = 0
    var clickable: Bool = false

    override init(texture: SKTexture?,color: UIColor,size: CGSize) {

        super.init(texture: texture,color: color,size: size)
        self.clickable = false

        self.isUserInteractionEnabled = true
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    func moveWithCamera() {
    }

    override func touchesBegan(_ touches: Set<UITouch>,with event: UIEvent?) {

        if let touch = touches.first as UITouch? {

            initialTouch = touch.location(in: self.scene!.view)
            moveAmtY = 0
            moveAmtX = 0
            initialPosition = self.position
            print(initialPosition)
        }
    }

    override func touchesMoved(_ touches: Set<UITouch>,with event: UIEvent?) {

        if let touch = touches.first as UITouch? {

            let movingPoint: CGPoint = touch.location(in: self.scene!.view)

            moveAmtX = movingPoint.x - initialTouch.x
            moveAmtY = movingPoint.y - initialTouch.y
            print(moveAmtX,moveAmtY)
            self.position.x = initialPosition.x + moveAmtX
            let minus = UIScreen.main.bounds.width/2 + ((UIScreen.main.bounds.width/2) - self.position.x)
            if (UIScreen.main.bounds.width/2)/self.position.x < 1 {
                rest = (UIScreen.main.bounds.width/2)/self.position.x
            } else {
                let theFloat = (UIScreen.main.bounds.width/2)/self.position.x
                rest = (UIScreen.main.bounds.width/2)/minus
            }
            self.xScale = rest
            self.yScale = rest
            
        }
    }

    override func touchesEnded(_ touches: Set<UITouch>,with event: UIEvent?) {

        var direction = ""
        if fabs(moveAmtX) > minimum_detect_distance {

            //must be moving side to side
            if moveAmtX < 0 {
                direction = "left"
            }
            else {
                direction = "right"
            }
        }
        else if fabs(moveAmtY) > minimum_detect_distance {

            //must be moving up and down
            if moveAmtY < 0 {
                direction = "up"
            }
            else {
                direction = "down"
            }
        }

        print("object \(self.name!) swiped " + direction)

        self.boxDelegate.boxSwiped(to: direction)
    }
}

感谢任何可以帮助我的人,我仍处于SpriteKit的起步阶段,我想知道优化代码的最佳方法:)

解决方法

为什么不使用带有三个独立面板的 SpriteKit 动画,您可以在其中将新联系人作为图像(精灵)添加到列表的同一位置的集合中。然后为每个面板滚动一个偏移量。每个联系人三个图像,一个左角,一个中心,一个直角。

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...