gpt4 book ai didi

ios - 垂直滚动背景-Sprite Kit

转载 作者:行者123 更新时间:2023-12-01 16:42:47 25 4
gpt4 key购买 nike

我正在开发纵向模式的游戏,似乎无法使该背景在y轴上平滑滚动。它没有正确添加第二个背景,因此两个背景之间始终存在间隙。

这是代码:

static const float BG_VELOCITY = 100.0;

static inline CGPoint CGPointAdd(const CGPoint a, const CGPoint b)
{
return CGPointMake(a.x + b.x, a.y + b.y);
}

static inline CGPoint CGPointMultiplyScalar(const CGPoint a, const CGFloat b)
{
return CGPointMake(a.x * b, a.y * b);
}

方法:
    -(void)initalizingScrollingBackground
{
for (int i = 0; i < 2; i++) {
SKSpriteNode *bg = [SKSpriteNode spriteNodeWithImageNamed:@"bg"];
bg.zRotation = M_PI_2;
bg.position = CGPointMake(320, self.frame.origin.y);
bg.anchorPoint = CGPointZero;
bg.name = @"bg";
[self addChild:bg];

}

}

- (void)moveBg
{
[self enumerateChildNodesWithName:@"bg" usingBlock: ^(SKNode *node, BOOL *stop)
{
SKSpriteNode * bg = (SKSpriteNode *) node;
CGPoint bgVelocity = CGPointMake(0, -BG_VELOCITY);
CGPoint amtToMove = CGPointMultiplyScalar(bgVelocity,_dt);
bg.position = CGPointAdd(bg.position, amtToMove);

//Checks if bg node is completely scrolled of the screen, if yes then put it at the end of the other node
if (bg.position.y <= -bg.size.height)
{
bg.position = CGPointMake(bg.position.x,
bg.position.y + bg.size.height*2);
}

}];
}

我做错了,这是两个背景之间的空白。注意:如果必要,背景大小为 568 x 320

谢谢。

最佳答案

有一些问题。最大的事实是您的图像是在横向模式下制作的。只需在photoshop中编辑图像或预览以将其旋转90度,然后取出zRotation。这将解决您的身高难题。然后更改bg.position = CGPointMake(320,... etc to bg.position = CGPointMake (0, i * bg.size.height);
还将您的if语句更改为:

         if (bg.position.y <= -bg.size.height)
{
bg.position = CGPointMake(0, bg.position.y + bg.size.height*2);
}

并且您的代码将起作用。

关于ios - 垂直滚动背景-Sprite Kit,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22791914/

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