頂点ヘルパーを使用してスプライトのエッジを取得しています。私は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