【问题标题】:iphone cocos2d chipmunk scale physicsSpriteiphone cocos2d 花栗鼠规模物理雪碧
【发布时间】:2012-08-10 06:23:34
【问题描述】:

在我的应用程序中,当触摸屏幕时,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;在更新方法中但不起作用。

【问题讨论】:

    标签: iphone objective-c cocos2d-iphone chipmunk


    【解决方案1】:

    来自文件CCPhysicsSprite.h

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

    如果不缩放空间,你真的无法缩放精灵。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多