2011-03-01 15 views
0

此代碼由場景中的精靈使用,以便拖動它們。我在嘗試弄清楚如何將此代碼轉換爲與cocos2d-mac模板兼容時遇到問題。我感謝任何幫助。有人可以幫助我轉換這個cocos2d-iphone特定的代碼,以與cocos2d-mac模板兼容嗎?

//////////////////////////////////////////////////// 
/////properties for touches moved 
- (void)ccTouchMoved:(UITouch *)touch withEvent:(UIEvent *)event {  
    CGPoint touchLocation = [self convertTouchToNodeSpace:touch]; 

    CGPoint oldTouchLocation = [touch previousLocationInView:touch.view]; 
    oldTouchLocation = [[CCDirector sharedDirector] convertToGL:oldTouchLocation]; 
    oldTouchLocation = [self convertToNodeSpace:oldTouchLocation]; 

    CGPoint translation = ccpSub(touchLocation, oldTouchLocation);  
    [self panForTranslation:translation];  
} 

回答

1

添加「CGPoint oldMouseLocation_;」 ivar進入你的班級。

#ifdef __IPHONE_OS_VERSION_MAX_ALLOWED 

- (void)ccTouchMoved:(UITouch *)touch withEvent:(UIEvent *)event {  
    /* snip */ 
} 

#elif defined(__MAC_OS_X_VERSION_MAX_ALLOWED) 

- (BOOL)ccMouseDragged:(NSEvent *)event { 
    CGPoint point = [[CCDirector sharedDirector] convertEventToGL:event]; 
    CGPoint mouseLocation = [self convertToNodeSpace:point]; 

    CGPoint translation = ccpSub(mouseLocation, oldMouseLocation_);  
    [self panForTranslation:translation];  

    oldMouseLocation_ = mouseLocation; 
} 

#endif 
+0

我收到「oldMouseLocation」範圍中未聲明。謝謝你這一點,但你認爲你能幫助我這個錯誤。 – Jeff 2011-03-03 15:07:14

+0

對不起,我固定它。 – 2011-03-03 19:24:53

相關問題