在iPhone屏幕上渲染时,顶点小于精灵

时间:2011-07-15 06:37:35

标签: cocos2d-iphone box2d

我使用顶点助手来获取精灵的边缘。我在iPhone上使用Cocos2d + Box2d。我得到的问题是我正在测试的设备上的调试绘图出现但是渲染或显示的顶点小于我的精灵,即使仔细地跟踪精灵的边缘并使用相同的精灵。

好的,这是问题的屏幕截图!

enter image description here

绿色三角形应该适合精灵的边缘。这也是我使用的代码:

这是GLESDebugDraw代码

    - (void)setupDebugDraw {
debugDraw = new GLESDebugDraw(PTM_RATIO* [[CCDirector   sharedDirector]    
contentScaleFactor]);
world->SetDebugDraw(debugDraw);
debugDraw->SetFlags(b2DebugDraw::e_shapeBit);

}

       #import "Box2DSprite.h"
    @interface Stalag :Box2DSprite {

b2World *world;
}
- (id)initWithWorld:(b2World *)world atLocation:(CGPoint)location;

@end

#import "Stalag.h"



@implementation Stalag
- (void)createBodyAtLocation:(CGPoint)location {
b2BodyDef bodyDef;
bodyDef.type = b2_staticBody;
bodyDef.position = b2Vec2(location.x/PTM_RATIO,
                          location.y/PTM_RATIO);
self.body = world->CreateBody(&bodyDef);
body->SetUserData(self);
b2PolygonShape shape;


int num = 8;
b2Vec2 verts[] = {
    b2Vec2(36.8f / 100.0, -79.2f / 100.0),
    b2Vec2(10.3f / 100.0, 33.2f / 100.0),
    b2Vec2(1.8f / 100.0, 80.6f / 100.0),
    b2Vec2(-4.6f / 100.0, 84.5f / 100.0),
    b2Vec2(-8.5f / 100.0, 80.3f / 100.0),
    b2Vec2(-22.6f / 100.0, 19.4f / 100.0),
    b2Vec2(-31.8f / 100.0, -45.6f / 100.0),
    b2Vec2(-37.5f / 100.0, -75.7f / 100.0)
};
shape.Set(verts, num);

b2FixtureDef fixtureDef;
fixtureDef.shape = &shape;
fixtureDef.density = 1000.0;
body->CreateFixture(&fixtureDef);
}
- (id)initWithWorld:(b2World *)theWorld atLocation:(CGPoint)location {
if ((self = [super init])) {
    world = theWorld;
    [self setDisplayFrame:[[CCSpriteFrameCache                              
sharedSpriteFrameCache]     spriteFrameByName:@"hill.png"]];
    gameObjectType = kStalagupType;
    [self createBodyAtLocation:location];
}
return self;
   }
    @end

任何人都可以告诉我我该做什么以及我做错了什么?

由于

1 个答案:

答案 0 :(得分:0)

指定顶点坐标时,将它除以“幻数”100.实际上它是您的PixelToMetersRatio(在cocos示例中为PTM_RATIO)。你也在使用box2d调试绘图。在创建调试绘图类时,必须在其构造函数中传递PTM_RATIO。我想你在那里传递另一个号码(不是100)。它能解决问题吗?