回答編集履歴

1

サンプルソースをObjectiveCで書いてしまったのでSwiftに修正

2015/02/15 14:20

投稿

jollyjoester
jollyjoester

スコア1585

test CHANGED
@@ -8,61 +8,59 @@
8
8
 
9
9
  ```
10
10
 
11
- #import "SampleScene.h"
11
+ import SpriteKit
12
12
 
13
13
 
14
14
 
15
- @implementation SampleScene{
15
+ class GameScene: SKScene {
16
16
 
17
- BOOL isTouched;  //タッチされているかフラグ
17
+
18
18
 
19
- SKSpriteNode *someSprite; //動かしたいspriteをここに入れる
19
+ var isTouched: Bool = false
20
20
 
21
- }
21
+ var someSprite: SKSpriteNode! //動かしたいspriteを入れる
22
22
 
23
23
 
24
24
 
25
- // ごにょごにょ
25
+ //ごにょごにょ
26
26
 
27
27
 
28
28
 
29
- -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
29
+ override func touchesBegan(touches: NSSet, withEvent event: UIEvent) {
30
30
 
31
- {
31
+ if (//押されたのが対象のボタンだったら) {
32
32
 
33
- if (//タッチされたのが対象のUIButtonだったら) {
33
+ isTouched = true
34
34
 
35
- isTouched = YES;
35
+ }
36
36
 
37
37
  }
38
38
 
39
- }
39
+
40
40
 
41
+ override func touchesEnded(touches: NSSet, withEvent event: UIEvent) {
41
42
 
43
+ if (//押されたのが対象のボタンだったら) {
42
44
 
43
- -(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
45
+ isTouched = false
44
46
 
45
- {
47
+ }
46
-
47
- if (//タッチされたのが対象のUIButtonだったら) {
48
-
49
- isTouched = NO;
50
48
 
51
49
  }
52
50
 
53
- }
51
+
54
52
 
53
+ override func update(currentTime: CFTimeInterval) {
55
54
 
55
+ if isTouched {
56
56
 
57
- -(void)update:(CFTimeInterval)currentTime {
57
+ let x: CGFloat = someSprite.position.x
58
58
 
59
- if (isTouched == YES) {
59
+ let y: CGFloat = someSprite.position.y
60
60
 
61
- float x = someSprite.position.x;
61
+ someSprite.position = CGPointMake(x+5, y+5)
62
62
 
63
- float y = someSprite.position.y;
63
+ }
64
-
65
- someSprite.position = CGPointMake(x+5, y+5);
66
64
 
67
65
  }
68
66