gpt4 book ai didi

iphone - 如何在从右到左的位置(视差)连续移动 Sprite?

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:11:31 25 4
gpt4 key购买 nike

我的问题是:我需要从右到左连续移动我的 Sprite (方向是横向) 我已经搜索并找到了 Ray 的教程(感谢他)但图像似乎并没有连续滚动我的代码是

-(id) init
{
// always call "super" init
if( (self=[super init])) {

CGSize screenSize = [CCDirector sharedDirector].winSize;

// 1) Create the CCParallaxNode
backgroundNode = [CCParallaxNode node];
[self addChild:backgroundNode z:-1];

// 2) Create the sprites we'll add to the CCParallaxNode
Back = [CCSprite spriteWithFile:@"bg_front_spacedust.png"];
Back.rotation = -90;
Back1 = [CCSprite spriteWithFile:@"bg_front_spacedust.png"];
Back1.rotation = -90;

// 3) Determine relative movement speeds for space dust and background
CGPoint dustSpeed = ccp(0.1, 0.1);

// 4) Add children to CCParallaxNode
[backgroundNode addChild:Back z:0 parallaxRatio:dustSpeed positionOffset:ccp(screenSize.width/2, screenSize.height/2)];
[backgroundNode addChild:Back1 z:1 parallaxRatio:dustSpeed positionOffset:ccp(screenSize.width,0)];

// 5) Enable updates
[self scheduleUpdate];
}
return self;
}

- (void)update:(ccTime)dt {

// 1) Update background position
CGPoint backgroundScrollVel = ccp(0,-1000);
backgroundNode.position = ccpAdd(backgroundNode.position, ccpMult(backgroundScrollVel, dt));

// 2) Check for background elements moving offscreen
NSArray *spaceDusts = [NSArray arrayWithObjects:Back, Back1, nil];
for (CCSprite *spaceDust in spaceDusts) {
if ([backgroundNode convertToWorldSpace:spaceDust.position].x < -spaceDust.contentSize.width) {
[backgroundNode incrementOffset:ccp(2*spaceDust.contentSize.width,0) forChild:spaceDust];
}
}
}

图像尺寸为 1024 X 320
谁能指导我解决这个问题
提前致谢

最佳答案

您可以在此处找到有关视差的分步指南: http://www.raywenderlich.com/3611/how-to-make-a-space-shooter-iphone-game只需滚动一点,直到找到添加视差滚动部分。

但我建议您通读整个教程。真的很不错。

关于iphone - 如何在从右到左的位置(视差)连续移动 Sprite?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18308780/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com