我很难让游戏得分随着时间而不是游戏事件而增加。得分是在游戏开始时显示的SKlabelnode。我希望得分随着游戏时间的推移而增加,然后在游戏重启时重新开始回到0(即:玩家死亡)
得分标签保持为0,我尝试过多种代码
//score
var score = Int()
var highScore = Int()
let scoreLable = SKLabelNode()
scoreLable.position = CGPoint(x: self.frame.width / 1.1, y: self.frame.height / 1.1)
scoreLable.zPosition = 5
scoreLable.fontSize = 100
scoreLable.fontName = "AppleSDGothicNeo-bold"
scoreLable.text = "\(score)"
func ScoreAndHighScore(){
score = score+1
}
var scoreTimer = Timer(timeInterval: 5.0, target: self, selector: #selector(ScoreAndHighScore), userInfo: nil, repeats: true)
答案 0 :(得分:0)
每次分数值增加时,您都需要更新标签的文本。
func ScoreAndHighScore() {
score += 1
scoreLabel.text = "\(score)"
}
答案 1 :(得分:0)
我建议使用SKActions作为您的计时器而不是NSTimer。你可以这样做:
const UserIsAuthenticated = UserAuthWrapper({
authSelector: state => state.get('user').toJS(),
predicate: authData => !!authData.token,
redirectAction: routerActions.replace,
wrapperDisplayName: 'UserIsAuthenticated'
})
const Authenticated = UserIsAuthenticated(props => props.children)
const routes =
<Route path="/">
<IndexRoute component={UserIsAuthenticated(applyFrame(Catalog))} />
<Route path="login" component={Login} />
<Route component={applyFrame(Authenticated)}>
<Route path="catalog" component={Catalog}>
<Route path="overview" component={CatalogOverview} />
<Route path="form" component={CatalogForm} />
<Route path="confirmation" component={CatalogConfirmation} />
</Route>
<Route path="ive">
<IndexRoute component={Page} />
<Route path=":id" component={PageDetail} />
</Route>
</Route>
</Route>