gpt4 book ai didi

swift - SKAction 淡出、更改文本、淡入

转载 作者:行者123 更新时间:2023-11-28 08:36:00 24 4
gpt4 key购买 nike

我正在为一款游戏制作介绍独白。我想知道如何在包含文本更改的序列中使用 SKActions。

我现在有

monologue.runAction(SKAction.fadeOutWithDuriation(1.5))
monologue.text = "text2"
//*wait for tap* (coded in)
monologue.runAction(SKAction.fadeInWithDuriation(1.5))

最佳答案

extension SKNode
{
func runAction( action: SKAction!, withKey: String!, optionalCompletion: dispatch_block_t? )
{
if let completion = optionalCompletion
{
let completionAction = SKAction.runBlock( completion )
let compositeAction = SKAction.sequence([ action, completionAction ])
runAction( compositeAction, withKey: withKey )
}
else
{
runAction( action, withKey: withKey )
}
}
}

代码:

var isMonologueReady : Bool = false //global var

monologue.name = "monologue"
self.isMonologueReady = false
let fadeOut = SKAction.fadeOutWithDuration(1.5)
let wait = SKAction.waitForDuration(1.5)
let changeText = SKAction.runBlock({monologue.text = "text2"})
let changeMytext = SKAction.group([wait,changeText])
let actionSequence = SKAction.sequence([fadeOut,changeMytext])
monologue.runAction(actionSequence,withKey:"monologueSequence",optionalCompletion: {
self.isMonologueReady = true
})

override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
/* Called when a touch begins */

let touch = touches.first
let positionInScene = touch!.locationInNode(self)

let touchedNode = self.nodeAtPoint(positionInScene)
print (touchedNode.name)
if let name = touchedNode.name
{
if name == "monologue" && self.isMonologueReady
{
let fadeIn = SKAction.fadeInWithDuration(1.5)
monologue.runAction(fadeIn,withKey:"monologueFadeIn")
}
}
}

解释:

创建所有基本操作后,您可以选择必须按顺序一起运行的操作。正如您在这段代码中看到的,waitchangeText 是成组启动的(并行模式,一起..),在您可以看到 SKAction 基于 fadeOut 和名为 changeMytextSKAction.group 的序列。最后,在点击之后,如果 actionSequence 终止( bool 值为 true),那么可以运行 fadeIn

关于swift - SKAction 淡出、更改文本、淡入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37675299/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com