ios - 如何通过按下按钮更改播放器颜色?

标签 ios sprite-kit

我想创建一个按钮,如果我按下它,播放器的颜色会变成与按钮相同的颜色。

问题是当我点击屏幕时它会播放 Action ,我只想在玩家按下按钮时播放 Action (在本例中是另一个 SKSpriteNode)

 class GameScene: SKScene, SKPhysicsContactDelegate {

    var circuloPrincipal = SKSpriteNode(imageNamed: "circulo")

    var colorVerde: UIColor = UIColor(red: 0.3, green: 0.7, blue: 0.5, alpha: 0.9)

    var circuloVerde = SKSpriteNode(imageNamed: "fondoBaseBlanco.png")




 for touch in touches {
            let location = circuloVerde

            let circuloVer = circuloVerde

           circuloVerde.position = circuloVerde.position

        circuloPrincipal.color = colorVerde 

        //circulo principal = player
        //color verde = green color
        //circulo verde = button

        }
}

最佳答案

要获得按钮的颜色,请执行此操作。

-(IBAction)buttonTapped:(id)sender{
    UIButton *btn = (UIButton*)sender;
    UIColor *btnColor = btn.backgroundColor;
 // Now you can set this btnColor as the color of your player.
}

关于ios - 如何通过按下按钮更改播放器颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37915494/

相关文章:

ios - 使用 UIImageView 上的 UIViewAnimationOptionTransitionCrossDissolve 对 UIView transitionWithView 的多个并发调用闪烁

ios - selectionStyle none 时未调用 didDeSelectRowAtIndexPath

ios - 应用程序在第二点后卡住,Objective C

swift - 需要帮助理解便捷初始化器和 Swift 中实例变量解包之间的交互

ios - Xcode 如何复制 View Controller ?我有这个并发症好几天了

ios - Xcode 提交 : Couldn't communicate with helper application

ios - 如何从解析中获取缩略图,objective c

ios - Sprite Kit 创建 iAdBanner

ios - 根据用户触摸计算角度

sprite-kit - Sprite Kit 中的粘性物理体