1

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

我已经尝试过,但不起作用。

请帮助我。

//创建精灵

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

4

1 回答 1

0

从文件CCPhysicsSprite.h

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

如果不使用它缩放空间,您真的无法缩放精灵。

于 2013-02-26T16:17:31.240 回答