我正在嘗試用Cocos2d和Chipmunk(通過SpaceManager)創建一個柔軟的球,使用一系列全部鏈接在一起的Rects,然後將彈簧連接到中央機構。如何將SpaceManager cpShape存儲在類似數組的東西中?
但爲了做到這一點,我想我需要所有的cpShapes存儲在數組中,我創造了他們,所以我可以再遍歷數組將它們一起與約束鏈接後。
但是,當我嘗試將cpShapes放入數組中時,出現錯誤,告訴我它是「不兼容的指針類型」。所以......我要麼需要使用除數組之外的其他東西(我試過一組,也不管用),或者我需要對形狀做些什麼來使其兼容......但是什麼?或者我需要另一個aproach。
任何想法?
下面的代碼到目前爲止它應該是有關...
- (id) init
{
if ((self = [super init])) {
SpaceManager * spaceMgr = [[SpaceManager alloc] init];
[spaceMgr addWindowContainmentWithFriction:1.0 elasticity:1.0 inset:cpv(5, 5)];
// This is a layer that draws all the chipmunk shapes
ChipmunkDrawingLayer *debug = [[ChipmunkDrawingLayer node] initWithSpace:spaceMgr.space];
[self addChild:debug];
int ballPeices = 10; // the number of peices I want my ball to be composed of
int ballRadius = 100;
float circum = M_PI * (ballRadius * 2);
float peiceSize = circum/ballPeices;
float angleIncrement = 360/ballPeices;
CGPoint origin = ccp(240, 160);
float currentAngleIncrement = 0;
NSMutableArray *peiceArray = [NSMutableArray arrayWithCapacity:ballPeices];
for (int i = 0; i < ballPeices; i++) {
float angleIncrementInRadians = CC_DEGREES_TO_RADIANS(currentAngleIncrement);
float xp = origin.x + ballRadius * cos(angleIncrementInRadians);
float yp = origin.y + ballRadius * sin(angleIncrementInRadians);
// This is wrong, I need to figure out what's going on here.
float peiceRotation = atan2(origin.y - yp, origin.x - xp);
cpShape *currentPeice = [spaceMgr addRectAt:ccp(xp, yp) mass:1 width:peiceSize height:10 rotation:peiceRotation];
currentAngleIncrement += angleIncrement;
[peiceArray addObject:currentPeice]; //!! incompatible pointer type
}
spaceMgr.constantDt = 0.9/55.0;
spaceMgr.gravity = ccp(0,-980);
spaceMgr.damping = 1.0;
}
return self;
}
你在哪裏添加彈簧約束?我沒有看到它 – slf 2010-07-07 17:04:59
我還沒有得到那麼多。我想我需要一種方法來創建它們後訪問這些形狀。要做到這一點,我需要讓他們進入數組或其他東西。 – gargantuan 2010-07-07 19:50:12