首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >applyImpulse不触发

applyImpulse不触发
EN

Stack Overflow用户
提问于 2014-05-05 13:29:13
回答 1查看 125关注 0票数 0

我在initWithSize方法中将重力定义为0,然后在touchesBegan中将其设置为-5,所以当您触摸屏幕时,应用程序将启动问题,在touchesBegan方法中,我也实现了一个applyImpulse,但它没有触发。只有重力才会被触发。这意味着搬运工就会掉到按钮上。

为什么applyImpulse没有被触发?

代码语言:javascript
复制
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {


    self.physicsWorld.gravity = CGVectorMake( 0.0, -5.0 );
    mover.physicsBody.restitution = 0.0;
    mover.physicsBody.velocity = CGVectorMake(0, 0);
    [mover.physicsBody applyImpulse:CGVectorMake(0, 15)];

}

搬运工方法:

代码语言:javascript
复制
-(void)addMover:(CGSize) size {


    SKTexture* lolTexture1 = [SKTexture textureWithImage:[UIImage imageNamed:@"lol1"]];
    lolTexture1.filteringMode = SKTextureFilteringNearest;

    SKTexture* lolTexture2 = [SKTexture textureWithImage:[UIImage imageNamed:@"lol2"]];
    lolTexture2.filteringMode = SKTextureFilteringNearest;
    SKTexture* lolTexture3 = [SKTexture textureWithImage:[UIImage imageNamed:@"lol3"]];
    lolTexture3.filteringMode = SKTextureFilteringNearest;
    SKTexture* lolTexture4 = [SKTexture textureWithImage:[UIImage imageNamed:@"lol4"]];
    lolTexture4.filteringMode = SKTextureFilteringNearest;
    SKTexture* lolTexture5 = [SKTexture textureWithImage:[UIImage imageNamed:@"lol5"]];
    lolTexture5.filteringMode = SKTextureFilteringNearest;
    SKTexture* lolTexture6 = [SKTexture textureWithImage:[UIImage imageNamed:@"lol6"]];
    lolTexture6.filteringMode = SKTextureFilteringNearest;
    SKAction *flap = [SKAction repeatActionForever:[SKAction animateWithTextures:@[lolTexture1, lolTexture2, lolTexture3, lolTexture4, lolTexture5, lolTexture6] timePerFrame:0.15]];

    SKSpriteNode *mover = [SKSpriteNode spriteNodeWithTexture:lolTexture1];
    [mover setScale:1.0];

    mover.position = CGPointMake(self.frame.size.width / 4, CGRectGetMidY(self.frame));

    [mover runAction:flap withKey:@"birdGo"];

    [self addChild:mover];

    self.physicsWorld.gravity = CGVectorMake( 0.0, 0 );

    mover.physicsBody = [SKPhysicsBody bodyWithCircleOfRadius:mover.frame.size.width/2-7];

}

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-05-05 16:23:56

在addMover之外声明mover,以便在touchesBegan方法中使用它。

SKSpriteNode *搬运机;

然后在addMover

mover = SKSpriteNode spriteNodeWithTexture:lolTexture1;

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23473747

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档