我使用这种方法初始化我的精灵:
-(id)initAttackerWithType:(ShapeType)type withPosition:(CGPoint)pos world:(b2World*)world andEnergy:(float)energy {
if(([self initWithTexture:[[CCTextureCache sharedTextureCache]addImage:@"circle.png"]])){
self.tag=type;
self.color= type == Enemy ? ccc3(255, 0, 0) : ccc3(0, 255, 0);
self.scale=energy *.22/PTM_RATIO; //scale depending on energy
// 0.22 gets the sprite scale to synchronize with shape radius
self.position=pos;
b2BodyDef bodyDef;
bodyDef.type = b2_dynamicBody;
bodyDef.position.Set(pos.x/PTM_RATIO, pos.y/PTM_RATIO);
_body = world->CreateBody(&bodyDef);
b2CircleShape dynamicCircle;
dynamicCircle.m_radius=energy/PTM_RATIO; //radius depending on energy
b2FixtureDef fixtureDef;
fixtureDef.shape = &dynamicCircle;
fixtureDef.density = 1.0f;
fixtureDef.friction = 0;
fixtureDef.restitution = 1;
_body->CreateFixture(&fixtureDef);
fixtureDef.userData=self;
_body->SetUserData(self);
}else self = nil;
return self ? self : nil;
}
关于力学,碰撞的一切都运作良好。唯一的问题是精灵比例不会根据能量而改变。不要误会我的意思,它应该按原样添加到屏幕上,但仅限于 1 级。
当我记录规模时,它会以应有的规模记录,但实际图像不是。
我敢肯定,我忽略了一些简单易行的事情,但我不知道是什么。