我有以下代码,我试图在空中发射箭头时正常工作。
我想要一个吊带或弓箭效果,类似于愤怒的小鸟。
任何人都可以建议进行更改,或者直接向我提供一些反馈,告诉我如何使用我的代码来实现我的效果。
#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
答案 0 :(得分:0)
我已经通过makegameswithus教程再次重新启动了who应用程序,这一切似乎都工作得更顺畅。