cuốn sách gpt4 ai đã làm

ios - 防止用户更改标签 - spriteKit

In lại Tác giả: Walker 123 更新时间:2023-11-28 07:17:23 25 4
mua khóa gpt4 Nike

我有一个标签,每 5 秒取一个不同的值(字符串值:“blue”、“pink”、“green”、“orange”)

我想警告用户标签将在 1 秒前更改。例如,在标签取另一个值之前,标签的背景颜色应为红色 1 秒。

每5秒调用一次颜色变化函数的代码

let timerFunc: NSTimer = NSTimer.scheduledTimerWithTimeInterval(5.0, target: self, selector: Selector("colorChange"), userInfo: nil, repeats: true)

随机改变标签值的代码

 func colorChange() {
let minRandomValue: UInt = 0
let maxRandomValue: UInt = 4
var numberRandom: UInt = UInt()

numberRandom = UInt(arc4random()) % (maxRandomValue - minRandomValue)

switch numberRandom {
case 0: couleur.text = "Blue";
case 1: couleur.text = "Green";
case 2: couleur.text = "Orange";
case 3: couleur.text = "Pink";
default: println("value problem")
}
}

稍后我会将 5 秒计时器延迟设为随机。谢谢。 Xcode 6.4, SDK 8.0

câu trả lời hay nhất

尝试以下...

1) 创建一个SKNode,2)创建一个红色的矩形SKSpriteNode并将其添加到SKNode,3)创建一个SKLabelNode并添加到SKNode中,4) 对自己运行以下操作

let changeColorWaitChangeBackground = SKAction.sequence([
SKAction.runBlock(self.changeColor),
SKAction.waitForDuration(4, withRange:2),
SKAction.runBlock(self.changeAlpha),
SKAction.waitForDuration(1),
])

在changeColor()中,设置颜色字符串,设置红色SKSpriteNode的alpha为0.0。

在changeAlpha()中,设置红色SKSpriteNode的alpha为1.0。

关于ios - 防止用户更改标签 - spriteKit,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24986680/

25 4 0
Walker 123
Hồ sơ

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá taxi Didi miễn phí
Phiếu giảm giá taxi Didi
Chứng chỉ ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com
Xem sitemap của VNExpress