我是SpriteKit的新手。我需要通过UIImageView或SpriteNode显示一个图像(这是一个游戏的背景图像)。然而,我需要用户能够放大到背景和周围的潘。在不使用SpriteKit的情况下,我很容易就完成了这一任务,但无法弄清楚如何使节点接受缩放和平移。如果我在故事板中使用UIScrollView,在我的场景中添加的所有精灵都不会变成孩子,也不会放大或平移。
你能给我指明正确的方向吗?
编辑:
我对你的回答有点困惑,但我所做的是:
根视图控制器中的 .m:
- (void)viewDidLoad
{
[super viewDidLoad];
SKView * showDesigner = (SKView *)self.view;
SKScene * scene = [iMarchMyScene sceneWithSize:showDesigner.bounds.size];
scene.scaleMode = SKSceneScaleModeAspectFill;
[showDesigner presentScene:scene];
}在我的场景中的:.m: (您的步骤被注释)
-(id)initWithSize:(CGSize)size {
if (self = [super initWithSize:size]) {
//create SKView (step 1)
SKView *skview_field = [[SKView alloc]initWithFrame:(CGRectMake(0, 0, size.width, size.height))];
//create UIScrollView with same dimensions as your SpriteKit view (step 2)
UIScrollView* uiscrollview_field = [[UIScrollView alloc]initWithFrame:skview_field.frame];
//initialize the field (field is the game's background node)
SKSpriteNode *field = [SKSpriteNode spriteNodeWithImageNamed:@"Field"];
field.position = CGPointMake(CGRectGetMidX(self.frame), (CGRectGetMidY(self.frame)));
field.size = CGSizeMake(self.size.width, self.size.height / 3);
//create a UIView (called scrollViewContent) with dimensions of background node (step 3)
UIView* scrollViewContent = [[UIView alloc]initWithFrame:field.frame];
//set UIScrollView contentSize with same dimensions as your scrollViewContent and add a scrollContentview as your UISCrollView subview (step 4)
[uiscrollview_field setContentSize:(CGSizeMake(scrollViewContent.frame.size.width, scrollViewContent.frame.size.height))];
scrollViewContent.frame = field.frame;
[uiscrollview_field addSubview:scrollViewContent];
//[self addChild:field]; -- my original code
//.....does a bunch of other inits
return self;
}下面是我迷路的地方:第5步:现在,在根目录视图中添加SKView,在SKView上添加UIScrollView。
如果我正确地理解了您,我需要转到myRootViewController.m和viewDidLoad方法中,将SKView和UIScrollView (在myScene.m中初始化)作为子视图添加到在viewDidLoad方法中初始化的SKView中?我不知道该怎么做。
https://stackoverflow.com/questions/19082251
复制相似问题