【问题标题】:How to make a physical wall using cocos2d / chipmunk?如何使用 cocos2d / 花栗鼠制作物理墙?
【发布时间】:2014-07-22 16:30:27
【问题描述】:

如何使用 cocos2d / 花栗鼠制作物理墙?所以那个精灵就不能穿过另一个精灵(墙)?对不起,如果它已经在某个地方得到了回答,我找不到任何适合初学者的信息。

【问题讨论】:

    标签: cocos2d-iphone game-physics chipmunk


    【解决方案1】:

    这是来自 cocos2d/chipmunk 模板。您的精灵应该在花栗鼠身上,以便在您的更新方法中将精灵的位置更改为身体的位置。

    CGSize s = [[CCDirector sharedDirector] winSize];
    
    _space = cpSpaceNew();
    
    cpSpaceSetGravity( _space, cpv(0, -100) );
    
    //
    // rogue shapes
    // We have to free them manually
    //
    // bottom
    _walls[0] = cpSegmentShapeNew( _space->staticBody, cpv(0,0), cpv(s.width,0), 0.0f);
    
    // top
    _walls[1] = cpSegmentShapeNew( _space->staticBody, cpv(0,s.height), cpv(s.width,s.height), 0.0f);
    
    // left
    _walls[2] = cpSegmentShapeNew( _space->staticBody, cpv(0,0), cpv(0,s.height), 0.0f);
    
    // right
    _walls[3] = cpSegmentShapeNew( _space->staticBody, cpv(s.width,0), cpv(s.width,s.height), 0.0f);
    
    for( int i=0;i<4;i++) {
        cpShapeSetElasticity( _walls[i], 1.0f );
        cpShapeSetFriction( _walls[i], 1.0f );
        cpSpaceAddStaticShape(_space, _walls[i] );
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多