我正試圖在花栗鼠中創造一個不斷增長的圈子,當你在一個位置觸摸並握住你的手指時,它開始增長。我還沒有找到任何具體的幫助花栗鼠的功能,想知道如果任何人有任何建議,提示或技巧如何做到這一點。cocos2d和花栗鼠越來越多的圈子
一種方法是創建一個比前一個更大的圓,然後摧毀每個更新圓的舊圓。也許有一種更簡單的方法,任何人有任何想法?
感謝
UPDATE: 在使用下面的方法我的那一刻:
在我actionLayer類:
-(BOOL) ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event
{
CGPoint touchLocation = [touch locationInView: [touch view]];
CGPoint circleOrigin = [[CCDirector sharedDirector] convertToGL: touchLocation];
spriteObject = [[[CPHatchimal alloc] initWithSpace:space atLocation:circleOrigin] autorelease];
[sceneSpriteBatchNode addChild:spriteObject z:2];
return YES;
}
-(void) ccTouchEnded:(UITouch *)touch withEvent:(UIEvent *)event
{
[spriteObject setGrowCircle:NO];
}
在我的 「spriteObject」 類:
-(void) update:(ccTime)deltaTime {
if (growCircle) {
CGPoint location = ccp(circleOrigin.x, circleOrigin.y);
cpFloat r = ((cpCircleShape*) shape)->r;
r++;
NSString *spritName = [self getCurrentSpriteName];
[self setDisplayFrame:[[CCSpriteFrameCache sharedSpriteFrameCache]
spriteFrameByName:spritName]];
[self setScale:(0.01 * r)];
cpSpaceRemoveStaticShape(space, shape);
cpShapeFree(shape);
body = cpBodyNewStatic();
body->p = location;
shape = cpCircleShapeNew(body, radius, cpvzero);
shape->e = e;
shape->u = u;
shape->collision_type = collisionType;
shape->data = self;
cpSpaceAddStaticShape(space, shape);
}
}
目前我有很好的fps(約60),所以我顧ESS該解決方案是確定..
你的方式會在CPU上超載。但是,您可以使用通常的圓形精靈,並在觸摸時將其縮放。 現在,問題是你想要擴展多少? – gixdev