Cocos2d iphone 试图让箭精灵正常飞行

Cocos2d iphone 试图让箭精灵正常飞行,cocos2d-iphone,spritebuilder,Cocos2d Iphone,Spritebuilder,我有下面的代码,我正试图让它在空中发射的箭正常工作 我想有一个吊索或弓箭效果,类似愤怒的小鸟 任何人都可以提出修改建议,或者直接向我提供一些反馈,告诉我如何使用我的代码来获得我想要的效果 #import "GLayer.h" @implementation GLayer{ CCPhysicsNode *_physicsNode; CCNode *_arrow; CCNode *_balloon; CGPoint origArrowPos; CGPo

我有下面的代码,我正试图让它在空中发射的箭正常工作

我想有一个吊索或弓箭效果,类似愤怒的小鸟

任何人都可以提出修改建议,或者直接向我提供一些反馈,告诉我如何使用我的代码来获得我想要的效果

#import "GLayer.h"

@implementation GLayer{

    CCPhysicsNode *_physicsNode;

    CCNode *_arrow;
    CCNode *_balloon;

    CGPoint origArrowPos;
    CGPoint origArrowHeadPos;

    CGPoint diffArrow;

    BOOL isLaunched;
    CCNode *_arrowHead;

}

// is called when CCB file has completed loading
- (void)didLoadFromCCB
{

    _physicsNode.collisionDelegate = self;

    // tell this scene to accept touches
    self.userInteractionEnabled = TRUE;

    origArrowPos = _arrow.position;
    origArrowHeadPos = _arrowHead.position;

}

# pragma mark - Touches

- (void)touchBegan:(UITouch *)touch withEvent:(UIEvent *)event
{
}

- (void)touchMoved:(UITouch *)touch withEvent:(UIEvent *)event
{

    CGPoint touchLocation = [touch locationInNode:self];
    if (isLaunched == NO){
        _arrow.position = touchLocation;
    }

}

-(void) touchEnded:(UITouch *)touch withEvent:(UIEvent *)event
{

    isLaunched = YES;

    _arrow.physicsBody.affectedByGravity = YES;
    _arrowHead.physicsBody.affectedByGravity = YES;

    CGPoint touchLocation = [touch locationInNode:self];
    CGPoint launchDirection = ccp(touchLocation.x, touchLocation.y);

    CGPoint force = ccpMult(launchDirection, (origArrowPos.x - touchLocation.x));
    [_arrow.physicsBody applyForce:force];

}

-(void) touchCancelled:(UITouch *)touch withEvent:(UIEvent *)event
{
}

# pragma mark - Collisions

-(BOOL)ccPhysicsCollisionBegin:(CCPhysicsCollisionPair *)pair arrow:(CCNode *)nodeA balloon:(CCNode *)nodeB{
    [self balloonRemoved:nodeA];
    return YES;
}

-(BOOL)ccPhysicsCollisionBegin:(CCPhysicsCollisionPair *)pair arrowhead:(CCNode *)nodeA balloon:(CCNode *)nodeB{
    [self balloonRemoved:nodeA];
    return YES;
}

- (void)balloonRemoved:(CCNode *)balloon {

    [balloon removeFromParent];
}


@end

通过makegameswithus教程,我再次一步一步地重新启动了who应用程序,一切似乎都更加顺利