【发布时间】:2014-05-02 03:25:59
【问题描述】:
使用 SpriteKit,我有一个场景 XYZMyScene,当我触摸屏幕时会呈现另一个场景 XYZMyOtherScene。在不抬起手指的情况下,我希望touchesMoved:withEvent: 在我移动手指时触发,但直到我首先抬起手指,然后触碰新场景并四处移动时它才会触发。
有没有可能在不先抬起手指的情况下让它开火?
下面是一些简单的复制代码:
// XYZMyScene.h
#import <SpriteKit/SpriteKit.h>
@interface XYZMyScene : SKScene
@end
// XYZMyScene.m
#import "XYZMyScene.h"
#import "XYZMyOtherScene.h"
@implementation XYZMyScene
-(id)initWithSize:(CGSize)size {
if (self = [super initWithSize:size]) {
self.backgroundColor = [SKColor orangeColor];
}
return self;
}
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
XYZMyOtherScene *otherScene = [[XYZMyOtherScene alloc] initWithSize:self.frame.size];
[self.view presentScene:otherScene];
}
@end
// XYZMyOtherScene.h
#import <SpriteKit/SpriteKit.h>
@interface XYZMyOtherScene : SKScene
@end
// XYZMyOtherScene.m
#import "XYZMyOtherScene.h"
@implementation XYZMyOtherScene
-(id)initWithSize:(CGSize)size {
if (self = [super initWithSize:size]) {
self.backgroundColor = [SKColor blueColor];
}
return self;
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
NSLog(@"moving!");
}
@end
【问题讨论】:
-
我建议您将 XYZMyScene 的元素移动到 XYZMyOtherScene 并处理来自同一场景的所有内容。
-
@akashg - 我不知道。听起来有点像它反驳了我所学到的关于分工和 OOP 的一切。必须有更好的解决方案...
-
嗯,根据我对 XYZMyScene 的了解,它并没有真正起到什么作用。
标签: ios cocoa-touch sprite-kit