Dav*_*of5 4 objective-c ios sprite-kit
我一直试图想出一个"简单"的方法来为我的SpriteKit游戏提供一个可滚动的垂直列表.
我将使用它来实现我的游戏的商店/升级部分,所以我希望用户能够向下滚动列表以查看可能的不同升级.
我已经看过很多关于将UIScrollView集成到SpriteKit中的帖子,但是大多数帖子似乎都在滚动整个屏幕.
到目前为止我所拥有的是:
-(void) createSceneContents
{
[super createSceneContents];
_scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(10,100, 250, 200)];
_scrollView.contentSize = CGSizeMake(2000, 120);
_scrollView.scrollEnabled = YES;
_scrollView.showsHorizontalScrollIndicator = YES;
_scrollView.backgroundColor = [UIColor brownColor];
[self.view addSubview:_scrollView];
//Test sprites for scrolling and zooming
SKSpriteNode *greenTestSprite = [SKSpriteNode spriteNodeWithColor:[SKColor greenColor]
size:CGSizeMake(25, 25)];
[greenTestSprite setName:@"greenTestSprite"];
greenTestSprite.position = CGPointMake(25, 125);
[self addChild:greenTestSprite];
//[self addChild: [self newMenuNode]];
}
Run Code Online (Sandbox Code Playgroud)
我正在尝试思考最简单的方法是让我能够将绿色测试精灵添加到UIScrollView中.不能让我的头脑绕过其他人这样做的方式,因为他们似乎正在连接UIScrollView与SKView的滚动,使屏幕看起来像滚动.
我确信有一种更简单的方法可以做到这一点,但现在已经找了一段时间.
任何帮助,将不胜感激.
谢谢提前分配.
UIKit如果可能的话,我会避免使用组件.如果您拥有组件的UIView父级UIKit,则很难与您的SpriteKit组件进行交互SKView.子类化SKNode和使用手势识别器进行滚动的"ScrollingNode" 非常容易SKView.这是一个例子:
https://github.com/JenDobson/SpriteKitScrollingNode
另一个值得关注的好教程是http://www.raywenderlich.com/44270/sprite-kit-tutorial-how-to-drag-and-drop-sprites.在手势识别器上转到最后的部分.
| 归档时间: |
|
| 查看次数: |
2504 次 |
| 最近记录: |