[英]iphone cocos2d chipmunk scale physicsSprite
在我的應用程序中,當觸摸屏幕時,PhysicalSprite將被添加到游戲層中。 所有PhysicalSprite都將添加到NSMutableArray中。 當數組計數達到5時,我想同時按比例縮小所有添加的PhysicalSprites。
我已經嘗試過,但是沒有用。
請幫助我。
//創建精靈
-(void) addNewSpriteAtPosition:(CGPoint)pos
{
PhysicsSprite *sprite = [PhysicsSprite spriteWithFile:@"sprite.png"];
sprite.position = pos;
sprite.tag = 1;
[sprites addObject:sprite];
[self addChild: sprite];
int num = 4;
cpVect verts[] = {
cpv(-20,-20),
cpv(-20, 20),
cpv( 20, 20),
cpv( 20,-20),
};
cpBody *body = cpBodyNew(1.0f, cpMomentForPoly(1.0f, num, verts, CGPointZero));
cpBodySetPos( body, pos );
cpSpaceAddBody(space_, body);
cpShape* shape = cpPolyShapeNew(body, num, verts, CGPointZero);
cpShapeSetElasticity( shape, 0.5f );
cpShapeSetFriction( shape, 0.5f );
cpSpaceAddShape(space_, shape);
[sprite setPhysicsBody:body];
NSLog(@"array size :%i",[sprites count]);
}
- (void)ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
for( UITouch *touch in touches ) {
CGPoint location = [touch locationInView: [touch view]];
location = [[CCDirector sharedDirector] convertToGL: location];
//add sprite
[self addNewSpriteAtPosition: location];
}
//scale sprites
if([sprites count]>5){
//[self terminateGame];
for(int i=0;i<[sprites count];i++){
PhysicsSprite *PS = [PhysicsSprite spriteWithFile:
[sprites objectAtIndex:i]];
id mAction1 = [CCScaleTo actionWithDuration:0.5 scaleX:0.5 scaleY:0.5];
[PS runAction:mAction1];
}
}
}
我已經嘗試實現phisycsSprite.scale = 0.5; 在更新方法,但不起作用。
從文件CCPhysicsSprite.h
Features and Limitations:
- Scale and Skew properties are ignored.
如果不縮放精靈,您真的無法縮放精靈。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.