精灵及其身体对力的作用方式不同

发布于 2025-01-01 21:42:36 字数 726 浏览 0 评论 0原文

所以我创建了一个身体并用精灵填充它。问题是,如果我对主体施加力,精灵就会高于主体(我可以从 debug_draw 中看到)。知道为什么会发生这种情况吗?

更新

- (void)tick:(ccTime) dt {

    _world->Step(dt, 10, 10);

    for(b2Body *b = _world->GetBodyList(); b; b=b->GetNext()) {    
        if (b->GetUserData() != NULL) {
            CCSprite *playerData = (CCSprite *)b->GetUserData();
            playerData.position = ccp(b->GetPosition().x * PTM_RATIO,
                                    b->GetPosition().y * PTM_RATIO);
            playerData.rotation = -1 * CC_RADIANS_TO_DEGREES(b->GetAngle());
        }        
    }

}

以下是我在 init 方法中的调用方式:

[self schedule:@selector(tick:)];

So I created a body and filled it with a sprite. The problem is that if I apply a force on the body, the sprite goes higher than the body (which I can see from debug_draw). Any idea why this is happening?

UPDATE

- (void)tick:(ccTime) dt {

    _world->Step(dt, 10, 10);

    for(b2Body *b = _world->GetBodyList(); b; b=b->GetNext()) {    
        if (b->GetUserData() != NULL) {
            CCSprite *playerData = (CCSprite *)b->GetUserData();
            playerData.position = ccp(b->GetPosition().x * PTM_RATIO,
                                    b->GetPosition().y * PTM_RATIO);
            playerData.rotation = -1 * CC_RADIANS_TO_DEGREES(b->GetAngle());
        }        
    }

}

And here's how I call this in my init method:

[self schedule:@selector(tick:)];

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

_失温 2025-01-08 21:42:36

获取 User_Data 的 for 循环时不时地重复,因此更新生物的位置会很困难..请在 tick 方法中移动精灵位置....

-(void) moveCreature
{
    // Please use the position to set the directions. This is used to fall from upside down in Portrait mode
    [spriteCreature setPosition:ccp(spriteCreature.position.x,spriteCreature.position.y-5)];

}

现在在 init 方法中安排精灵

-(id) init
{
    if((self = [super init])) 
    {
        // Create your World and other stuffs 
        [self schedule:@selector(moveCreature)];

    }
return self;
}

上面东西会带着精灵进入体内然后掉下来......

The for loop which gets the User_Data is kept on repeating now and then so to update the position of the creature would be difficult.. Please move the sprites position in the tick method....

-(void) moveCreature
{
    // Please use the position to set the directions. This is used to fall from upside down in Portrait mode
    [spriteCreature setPosition:ccp(spriteCreature.position.x,spriteCreature.position.y-5)];

}

Now in the init method schedule the sprite

-(id) init
{
    if((self = [super init])) 
    {
        // Create your World and other stuffs 
        [self schedule:@selector(moveCreature)];

    }
return self;
}

The above stuff would carry the sprite in the body n fall down...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文