我正在尝试在花栗鼠中创建一个不断增长的圆圈,当您触摸并按住某个位置时,该圆圈开始增长。我在花栗鼠中没有找到任何具体的帮助功能,想知道是否有人对如何做到这一点有任何建议、提示或技巧。
一种方法是创建一个比前一个大一点的圆圈,并在每个更新圆圈中销毁旧的圆圈。也许有更简单的方法,有人有什么想法吗?
谢谢
更新:目前我使用以下方法:
在我的 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),所以我想这个解决方案还可以。