ラベルのalpha値を1に設定してからアクションを実行すれば良さそうです。
以下は実装してみた結果です。
swift
1
2class GameScene: SKScene {
3
4 let myLabel = SKLabelNode(fontNamed:"Chalkduster")
5
6 override func didMoveToView(view: SKView) {
7 // ラベルの初期設定
8 myLabel.text = ""
9 myLabel.fontSize = 45
10 myLabel.position = CGPoint(x:CGRectGetMidX(self.frame), y:CGRectGetMidY(self.frame))
11 myLabel.alpha = 0
12 self.addChild(myLabel)
13
14 // ボタン1(正解)
15 let myButtonCorrect = UIButton()
16 myButtonCorrect.frame = CGRectMake(0,0,200,40)
17 myButtonCorrect.backgroundColor = UIColor.redColor();
18 myButtonCorrect.setTitle("1", forState: UIControlState.Normal)
19 myButtonCorrect.layer.position = CGPoint(x: self.view!.frame.width/2 - 100, y:CGRectGetMidY(self.frame) + 100)
20 myButtonCorrect.addTarget(self, action: "onClickMyButton:", forControlEvents: .TouchUpInside)
21 myButtonCorrect.tag = 1
22 self.view!.addSubview(myButtonCorrect);
23
24 // ボタン2(不正解)
25 let myButtonIncorrect = UIButton()
26 myButtonIncorrect.frame = CGRectMake(0,0,200,40)
27 myButtonIncorrect.backgroundColor = UIColor.blueColor();
28 myButtonIncorrect.setTitle("2", forState: UIControlState.Normal)
29 myButtonIncorrect.layer.position = CGPoint(x: self.view!.frame.width/2 + 100, y:CGRectGetMidY(self.frame) + 100)
30 myButtonIncorrect.addTarget(self, action: "onClickMyButton:", forControlEvents: .TouchUpInside)
31 myButtonIncorrect.tag = 2
32 self.view!.addSubview(myButtonIncorrect);
33
34 }
35
36 func onClickMyButton(sender : UIButton){
37 answerCheck(sender.tag)
38 }
39
40 func answerCheck(let answer: Int) {
41
42 let correctAnswer = 1 // 質問に合わせて変更する必要がある
43 let correct = (answer == correctAnswer)
44
45 if correct
46 {
47 myLabel.alpha = 1
48 let action = SKAction.fadeAlphaTo(0,duration: 0.5)
49 myLabel.text = "o"
50 myLabel.runAction(action)
51 }
52 else
53 {
54 myLabel.alpha = 1
55 let action = SKAction.fadeAlphaTo(0,duration: 0.5)
56 myLabel.text = "x"
57 myLabel.runAction(action)
58 }
59 }
60}
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/02/21 14:33