나는 Cocos2d와 Chipmunk (SpaceManager를 통해)로 squishy 공을 만들려고 노력하고 있습니다. 여러 장의 직사각형을 함께 묶은 다음 스프링으로 중앙 몸체에 합칩니다. 어떻게 SpaceManager cpShape를 배열과 같은 형태로 저장할 수 있습니까?
그러나이 작업을 수행하기 위해
, 내가 내가 내가 다음 배열을 통해 루프 제약과 함께 그들을 모두 연결 수를 생성 한 후 배열에있는 모든 cpShapes를 저장할 필요가 있다고 생각.그러나 배열에 cpShapes를 넣으려고하면 "호환되지 않는 포인터 유형"이라는 오류가 발생합니다. 그래서 ... 나는 어레이가 아닌 다른 것을 사용해야한다. (세트를 시도해 보았는데, 그 중 하나도 작동하지 않았다.) 또는 호환이 가능하도록 모양에 뭔가를 할 필요가있다. 아니면 다른 접근이 필요해.
아이디어가 있으십니까?
- (void)addObject:(id)anObject
: 여기
는- (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
나는 아직까지 그것을 얻지 않았다. 나는 그들이 만들어지면 모양에 접근 할 수있는 방법이 필요하다고 생각한다. 그렇게하기 위해서, 나는 그것들을 배열 등으로 가져와야합니다. – gargantuan