2012-08-10 39 views
1

在我的应用程序中,触摸屏幕时,physicssprite将被添加到游戏图层中。 所有物理sprites将被添加到一个NSMutableArray。 当数组数量达到5时,我想同时缩小所有添加的物理Sprites。iphone cocos2d花栗鼠尺度physicsSprite

我试过但没有& t工作。

请帮帮我。

//创建子画面

-(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]; 
     } 
    } 
} 

我已经tryed实施phisycsSprite.scale = 0.5;在更新方法但不起作用。

回答

0

从文件CCPhysicsSprite.h

Features and Limitations: 
    - Scale and Skew properties are ignored. 

你真的不能形成规模精灵没有用它缩放的空间。