【发布时间】:2014-01-21 15:21:27
【问题描述】:
我正在为 iOS 开发一个 SpriteKit 游戏,我正在通过阅读 Ray Wenderlich 教程(Space Shooter SpriteKit)来学习构建游戏
但是我想让应用程序处于纵向模式,因此我想让背景从上到下移动。
#pragma mark - TBD - Game Backgrounds
//1
NSArray *parallaxBackgroundNames = @[@"bg_galaxy.png", @"bg_planetsunrise.png",
@"bg_spacialanomaly.png", @"bg_spacialanomaly2.png"];
CGSize planetSizes = CGSizeMake(200.0, 200.0);
//2
_parallaxNodeBackgrounds = [[FMMParallaxNode alloc] initWithBackgrounds:parallaxBackgroundNames
size:planetSizes
pointsPerSecondSpeed:10.0];
//3
_parallaxNodeBackgrounds.position = CGPointMake(size.width/2.0, size.height/2.0);
//4
[_parallaxNodeBackgrounds randomizeNodesPositions];
//5
[self addChild:_parallaxNodeBackgrounds];
//6
NSArray *parallaxBackground2Names = @[@"bg_front_spacedust.png",@"bg_front_spacedust.png"];
_parallaxSpaceDust = [[FMMParallaxNode alloc] initWithBackgrounds:parallaxBackground2Names
size:size
pointsPerSecondSpeed:25.0];
_parallaxSpaceDust.position = CGPointMake(0,0);
[self addChild:_parallaxSpaceDust];
编辑:
我可以从上到下移动,但移动不顺畅。
#pragma mark - TBD - Game Backgrounds
for (int i = 0; i < 2; i++) {
SKSpriteNode * bg = [SKSpriteNode spriteNodeWithImageNamed:@"background"];
bg.anchorPoint = CGPointZero;
bg.position = CGPointMake(0, i * bg.size.height);
bg.name = @"background";
[self addChild:bg];
}
-(void)update:(NSTimeInterval)currentTime {
[self enumerateChildNodesWithName:@"background" usingBlock: ^(SKNode *node, BOOL *stop) {
SKSpriteNode *bg = (SKSpriteNode *) node;
bg.position = CGPointMake(bg.position.x, bg.position.y-5);
if (bg.position.y <= -bg.size.height) {
bg.position = CGPointMake(bg.position.x , bg.position.y + bg.size.height * 2);
}
}];
}
【问题讨论】:
-
所以用户不会为你编写代码。首先尝试自己实现它,如果遇到困难,请告诉我们您尝试了什么以及您未能理解特定问题或任务的地方。
-
我成功地从上到下制作了它,但它的移动不如 Ray 教程中的横向模式那么流畅。我会更新代码
标签: ios sprite-kit