gpt4 book ai didi

ios - 我有一个纹理作为我的背景,但它导致另一个纹理不出现在 Spritekit 中?

转载 作者:行者123 更新时间:2023-11-29 03:13:28 24 4
gpt4 key购买 nike

我将这段代码作为移动背景的背景:

    SKTexture* bgTexture = [SKTexture textureWithImageNamed:@"nightbackground"];
bgTexture.filteringMode = SKTextureFilteringNearest;

SKAction* movebgSprite = [SKAction moveByX:-bgTexture.size.width*2 y:0 duration:0.1 * bgTexture.size.width*2];
SKAction* resetbgSprite = [SKAction moveByX:bgTexture.size.width*2 y:0 duration:0];
SKAction* movebgSpritesForever = [SKAction repeatActionForever:[SKAction sequence:@[movebgSprite, resetbgSprite]]];

for( int i = 0; i < 2 + self.frame.size.width / ( bgTexture.size.width * 2 ); ++i ) {
SKSpriteNode* sprite = [SKSpriteNode spriteNodeWithTexture:bgTexture];
sprite.position = CGPointMake(self.size.width/2, self.size.height/2);
[sprite runAction:movebgSpritesForever];
[self addChild:sprite];

我添加此代码必须重生管道:

SKTexture* _pipeTexture1 = [SKTexture textureWithImageNamed:@"Pipe1"];
_pipeTexture1.filteringMode = SKTextureFilteringNearest;
SKTexture* _pipeTexture2 = [SKTexture textureWithImageNamed:@"Pipe2"];
_pipeTexture2.filteringMode = SKTextureFilteringNearest;

SKNode* pipePair = [SKNode node];
pipePair.position = CGPointMake( self.frame.size.width + _pipeTexture1.size.width * 2, 0 );
pipePair.zPosition = -10;

CGFloat y = arc4random() % (NSInteger)( self.frame.size.height / 3 );

SKSpriteNode* pipe1 = [SKSpriteNode spriteNodeWithTexture:_pipeTexture1];
[pipe1 setScale:2];
pipe1.position = CGPointMake( 0, y );
pipe1.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:pipe1.size];
pipe1.physicsBody.dynamic = NO; [pipePair addChild:pipe1];

SKSpriteNode* pipe2 = [SKSpriteNode spriteNodeWithTexture:_pipeTexture2];
[pipe2 setScale:2];
pipe2.position = CGPointMake( 0, y + pipe1.size.height + kVerticalPipeGap );
pipe2.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:pipe2.size];
pipe2.physicsBody.dynamic = NO; [pipePair addChild:pipe2];

SKAction* movePipes = [SKAction repeatActionForever:[SKAction moveByX:-1 y:0 duration:0.02]];
[pipePair runAction:movePipes];

[self addChild:pipePair];

出于某种原因,当我添加这段代码时,两条管道没有出现,但确实有什么东西把我的角色推回去了。它只是不显示出来。如果我删除后台代码,管道会出现并且它会再次工作吗?有什么问题吗?

最佳答案

大概是这样的:

pipePair.zPosition = -10;

当添加你的背景 Sprite 时,你没有指定任何 zPosition 这意味着它们将获得默认的 0.0,它在 -10 的任何东西前面都是可见的。您的角色被推回,因为即使 Sprite 在视觉上被覆盖,物理体仍在相互作用。

pipePair.zPosition = 10; // (or any other positive value)

应该可以解决您的问题。

关于ios - 我有一个纹理作为我的背景,但它导致另一个纹理不出现在 Spritekit 中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21959509/

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