iphone cocos2d chipmunk scale physicsSprite

时间:2012-08-10 06:23:34

标签: iphone objective-c cocos2d-iphone chipmunk

在我的应用程序中,当触摸屏幕时,physicssprite将被添加到游戏层中。 所有physicsSprit都将被添加到NSMutableArray中。 当数组计数达到5时,我想同时缩小所有添加的physicsSprites。

我已经尝试但是没有工作。

请帮帮我。

//创建精灵

-(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;在更新方法但不起作用。

1 个答案:

答案 0 :(得分:0)

来自档案CCPhysicsSprite.h

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

如果没有用它缩放空间,你真的无法缩放精灵。