0

特定の地点の周りの回転についての簡単な例を見たことがありません。私はこのようなことを試しましたが、うまくいきません:

//CCNode *node is declared
//In a function of a subclass of CCSprite
- (void)moveWithCicrlce
{
anchorNode = [CCNode node];
anchorNode.position = ccpSub(self.position, circleCenter);
anchorNode.anchorPoint = circleCenter;
[anchorNode runAction:[CCRotateBy actionWithDuration:1 angle:90]];
[self runAction:[CCRepeatForever actionWithAction:[CCSequence actions:[CCCallFunc actionWithTarget:self selector:@selector(rotate)], [CCDelayTime actionWithDuration:0.1], nil]]];
}

- (void)rotate
{
self.position = ccpAdd(anchorNode.position, anchorNode.anchorPoint);
}
4

2 に答える 2

2

半径(Pからの距離)が100の特定の点P(50,50)を中心にノード(スプライトなど)を回転させる方法は次のとおりです。

CCNode* center = [CCNode node];
center.position = CGPointMake(50, 50);
[self addChild:center];

// node to be rotated is added to center node
CCSprite* rotateMe = [CCSprite spriteWithFile:@"image.png"];
[center addChild:rotateMe];

// offset rotateMe from center by 100 points to the right
rotateMe.position = CGPointMake(100, 0);

// perform rotation of rotateMe around center by rotating center
id rotate = [CCRotateBy actionWithDuration:10 rotation:360];
[center runAction:rotate];
于 2012-05-21T08:48:34.813 に答える
0

私のおおよその解決策:

@interface Bomb : NSObject {
    CCSprite *center;
}

...

@end

およびいくつかの方法:

- (void)explode
{
    BombBullet *bullet = [BombBullet spriteWithFile:@"explosion03.png"];
    [[[CCDirector sharedDirector] runningScene] addChild:bullet];

    center = [CCSprite spriteWithTexture:bullet.texture];
    center.position = explosionPoint;
    center.anchorPoint = ccp(-0.5, -0.5);
    center.visible = NO;
    [[[CCDirector sharedDirector] runningScene] addChild:center];
    [center runAction:[CCRotateBy actionWithDuration:1 angle:360]];

    CCCallFunc *updateAction = [CCCallFuncN actionWithTarget:self selector:@selector(update:)];
    [bullet runAction:[CCRepeatForever actionWithAction:[CCSequence actions:updateAction, [CCDelayTime actionWithDuration:0.01], nil]]];
}

- (void)update:(id)sender
{
    BombBullet *bombBullet = (BombBullet *)sender;
    bombBullet.rotation = center.rotation;
    bombBullet.position = ccpAdd(center.position, center.anchorPointInPoints);
    bombBullet.position = ccpAdd(bombBullet.position, ccp(-bombBullet.contentSize.width / 2, -bombBullet.contentSize.height / 2));
    bombBullet.position = ccpRotateByAngle(bombBullet.position, center.position, bombBullet.rotation);
}

もちろん、スプライト削除を追加する必要があります。

于 2012-05-28T07:14:51.710 に答える