gpt4 book ai didi

ios - 使对象粘在屏幕顶部 SpriteKit

转载 作者:行者123 更新时间:2023-11-29 02:30:58 24 4
gpt4 key购买 nike

如何停止从屏幕底部移动到顶部的对象。并且对象应该粘在顶部。这是该对象的代码:

    SKSpriteNode* ball = [SKSpriteNode spriteNodeWithImageNamed: @"ball.png"];
ball.name = ballCategoryName;
ball.position = CGPointMake(self.frame.size.width/3, self.frame.size.height/3);
[self addChild:ball];

ball.physicsBody = [SKPhysicsBody bodyWithCircleOfRadius:ball.frame.size.width/2];

ball.physicsBody.friction = 1.0f;

ball.physicsBody.restitution = 1.0f;

ball.physicsBody.linearDamping = 0.0f;

ball.physicsBody.allowsRotation = YES;


[ball.physicsBody applyImpulse:CGVectorMake(0.0f, -10.0f)];

最佳答案

- (void) checkPosition
{
if (ball.position.y > self.height.size) {
ball.position.y = ball.position.y - 1;
}
}

- (void)update:(NSTimeInterval)currentTime
{
[self checkPosition]; //update tests rough 60 times per sec.
}

关于ios - 使对象粘在屏幕顶部 SpriteKit,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26882391/

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