我正在使用頂點助手來獲取我的精靈的邊緣。我在iPhone上使用Cocos2d + Box2d。我得到的問題是,我正在測試的設備上的調試繪製出現,但即使仔細跟蹤精靈的邊緣並使用相同的精靈,渲染或顯示的頂點也比我的精靈小。當在iPhone屏幕上呈現時小於精靈的頂點
確定這裏是問題的屏幕截圖!
綠色三角形應該適合與子畫面的邊緣。另外這是我使用的代碼:
這是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
請誰能告訴我我該怎麼辦,什麼我做錯了嗎?
感謝
請提供一些代碼和屏幕截圖。您的問題無法以當前形式回答 – Andrew
@Andrew感謝您的糾正。我已經添加了有問題的代碼和圖片。乾杯! – Zaki