SpriteKit は初めてです。UIImageView または SpriteNode を介して画像を表示する必要があります (ゲームの背景画像です)。ただし、ユーザーが背景にズームインしてパンできるようにする必要があります。SpriteKit を使用せずにこれを簡単に達成しましたが、ノードがズームとパンを受け入れるようにする方法がわかりません。ストーリーボードで UIScrollView を使用すると、シーンに追加されたすべてのスプライトが子にならず、ズームまたはパンしません。
それは可能ですか、正しい方向に私を向けることができますか?
編集:
私はあなたの答えに少し混乱していますが、これが私がしたことです:
私のルートView Controller .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 を追加し、UIScrollView を SKView の上に追加します。
私があなたを正しく理解していれば、myRootViewController.m に移動し、viewDidLoad メソッドで SKView と UIScrollView (myScene.m で初期化される) を、ここで viewDidLoad メソッドで初期化された SKView にサブビューとして追加する必要がありますか? その部分のやり方がわかりません。