2011-07-15 61 views
0

我正在使用頂點助手來獲取我的精靈的邊緣。我在iPhone上使用Cocos2d + Box2d。我得到的問題是,我正在測試的設備上的調試繪製出現,但即使仔細跟蹤精靈的邊緣並使用相同的精靈,渲染或顯示的頂點也比我的精靈小。當在iPhone屏幕上呈現時小於精靈的頂點

確定這裏是問題的屏幕截圖!

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 

請誰能告訴我我該怎麼辦,什麼我做錯了嗎?

感謝

+0

請提供一些代碼和屏幕截圖。您的問題無法以當前形式回答 – Andrew

+0

@Andrew感謝您的糾正。我已經添加了有問題的代碼和圖片。乾杯! – Zaki

回答

0

當指定座標的頂點你正在用其除以一個「幻數」 100其實這是你的PixelToMetersRatio(PTM_RATIO科科斯例子)。你也使用box2d調試繪製。當創建調試繪圖類時,您必須在其構造函數中傳遞PTM_RATIO。我認爲你在那裏傳遞另一個數字(不是100)。它解決了問題嗎?

+0

感謝您的回覆,但現在我很困惑......我不太明白你在說什麼。 – Zaki

+0

@Zaki:請顯示您正在創建的代碼GLES_debugDraw – Andrew

+0

我已經顯示了GLESDebugDraw代碼。 PLease請參閱 – Zaki