首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >SpriteKit中的缩放和滚动

SpriteKit中的缩放和滚动
EN

Stack Overflow用户
提问于 2013-09-29 19:22:42
回答 5查看 14.2K关注 0票数 15

我是SpriteKit的新手。我需要通过UIImageView或SpriteNode显示一个图像(这是一个游戏的背景图像)。然而,我需要用户能够放大到背景和周围的潘。在不使用SpriteKit的情况下,我很容易就完成了这一任务,但无法弄清楚如何使节点接受缩放和平移。如果我在故事板中使用UIScrollView,在我的场景中添加的所有精灵都不会变成孩子,也不会放大或平移。

你能给我指明正确的方向吗?

编辑:

我对你的回答有点困惑,但我所做的是:

根视图控制器中的 .m:

代码语言:javascript
复制
- (void)viewDidLoad
{
    [super viewDidLoad];
    SKView * showDesigner = (SKView *)self.view;
    SKScene * scene = [iMarchMyScene sceneWithSize:showDesigner.bounds.size];
    scene.scaleMode = SKSceneScaleModeAspectFill;
    [showDesigner presentScene:scene];
}

在我的场景中的:.m: (您的步骤被注释)

代码语言:javascript
复制
-(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中?我不知道该怎么做。

EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19082251

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档