2009-11-18 51 views
0

我正在開發一些使用多點觸摸iPhone(科科斯)的遊戲。任何人都可以教我如何從頭開始。我不確定從哪裏開始或有哪些資源可以提供幫助。我非常感謝幫助。椰子多點觸控遊戲

@implementation GameScene 

- (id)init 
{ 
    if (self = [super init]) 
    { 
     Sprite *background = [Sprite spriteWithFile:@"unzip.png"]; 

     background.position = CGPointMake(240,160); 
     [self addChild:background]; 

     Label *aboutContent = [Label labelWithString:@"Welcome to the game" fontName:@"Helvetica" fontSize:30]; 
     aboutContent.position = CGPointMake(240,160); 
     [self addChild:aboutContent]; 
    } 
    return self; 
} 
@end 

我有這段代碼。這導入圖像。只需要玩家可以觸摸中心的2點A和B,並將它們在彼此相反的兩側移動。任何人都可以給我一些例子。?

回答

2

Monocle Studios有a whitepaper: introduction to cocos2d iphone。 非常好的地方開始。

觸摸可以通過任何圖層檢測設置isTouchEnabled屬性爲YES。

任何其他CocosNode類後代可以實現協議TargetedTouchDelegateStandardTouchDelegate,然後用觸摸調度員註冊自己:

[[TouchDispatcher sharedDispatcher] addTargetedDelegate:self 
            priority: 0 swallowsTouches:YES]; 

然後,必須實現:

  • - (BOOL)ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event
  • - (void)ccTouchMoved:(UITouch *)touch withEvent:(UIEvent *)event
  • - (void)ccTouchEnded:(UITouch *)touch withEvent:(UIEvent *)event

在那個對象中。

希望有所幫助。