1
Bows rotates 360 Degree using touch and it fires arrow while touch ended.

Moving portion works perfectly but their need some correction while touch endes..
The problem is while i touch the bow,moving direction of arrow is opposite to bow such as 

在此处输入图像描述

当我以相反的方向旋转弓时,它工作正常,但只有当弓旋转时.. 箭应该从右向左发射,弓的位置应该是正确的。

我应该做些什么更正才能使它们一起成为可能。?!对不起我的英语不好..

我的代码如下..

-(void) ccTouchMoved:(UITouch *)touch withEvent:(UIEvent *)event
{
    CGPoint location = [touch locationInView:[touch view]];
    location = [[CCDirector sharedDirector] convertToGL:location];

    [self setArrowFromPt:location centerPt:windowCenter];
}

-(void) setArrowFromPt:(CGPoint)touchPt centerPt:(CGPoint)centerPt
{
    diff = ccpSub(touchPt, centerPt);
    NSLog(@"%@", NSStringFromCGPoint(diff));

    angle = ccpToAngle(diff);
    normalized = ccpNormalize(diff);

    float START_ANGLE = 0;
    float RADIUS = 100.0;

    imgArrow.position = ccpAdd(centerPt, ccpMult(normalized, RADIUS));
    cocosAngle = -CC_RADIANS_TO_DEGREES(angle);
    imgArrow.rotation = START_ANGLE + cocosAngle;
}

-(void) ccTouchEnded:(UITouch *)touch withEvent:(UIEvent *)event
{
    CGPoint location = [touch locationInView:[touch view]];
    location = [[CCDirector sharedDirector] convertToGL:location];

    cocosAngle =  -CC_RADIANS_TO_DEGREES(angle);
    curangle = imgArrow.rotation;
    CGFloat rotateDiff = cocosAngle - curangle;  
    CGFloat rotateSpeed = 180; 
    rotateDuration = fabs(rotateDiff / rotateSpeed);

    if (_nextProjectile != nil) return;
    _nextProjectile = [[CCSprite spriteWithFile:@"newarrow.png"] retain];
    _nextProjectile.anchorPoint = ccp(0,0);
    _nextProjectile.position = ccp(380,150);

    [imgArrow runAction:[CCSequence actions:
                       [CCRotateTo actionWithDuration:rotateDuration angle:cocosAngle],
                       [CCCallFunc actionWithTarget:self selector:@selector(finishShoot)],
                       nil]]; 

    ccTime delta = 1.0;
    CGPoint normalizedShootVector = ccpNormalize(diff);
    CGPoint overshotVector = ccpMult(normalizedShootVector, 420);
    CGPoint offscreenPoint = ccpAdd(_nextProjectile.position, overshotVector);

    [_nextProjectile runAction:[CCSequence actions:
                                [CCMoveTo actionWithDuration:delta position:offscreenPoint],
                                [CCCallFuncN actionWithTarget:self selector:@selector(spriteMoveFinished:)],
                                nil]];
    _nextProjectile.tag = 2;

}

任何帮助表示赞赏。提前致谢 !!

4

1 回答 1

0

因为我可以回答我的问题,

我通过纠正解决了我的问题

CGPoint overshotVector = ccpMult(normalizedShootVector, -420);

放置 - 标志,导致我的箭头从右到左方向投掷。

于 2013-04-13T13:22:14.753 回答