0

作業中のゲームをUIkitからcoocos2dに変換しています。UIKITを使用して、以下のコードを使用して、タッチ偶数をメソッドに渡します。Cocos2dで同等のものは何でしょうか?

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    // Save the position
    for (UITouch *touch in touches) {
        // Send to the dispatch method, which will make sure the appropriate subview is acted upon
        [self dispatchFirstTouchAtPoint:[touch locationInView:boardView] forEvent:nil];
    }
}

// Saves the first position for reference when the user lets go.
- (void) dispatchFirstTouchAtPoint:(CGPoint)touchPoint forEvent:(UIEvent *)event
{
    beginTouchPoint = touchPoint;
}

// Handles the continuation of a touch.
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
    for (UITouch *touch in touches) {
        // Send to the dispatch method, which will make sure the appropriate subview is acted upon
        [self dispatchTouchEndEvent:[touch view] toPosition:[touch locationInView:boardView]];
    }
}

-(void) dispatchTouchEndEvent:(UIView *)theView toPosition:(CGPoint)position
{   id  sender;
    int directionSwiped;
    int row,column;
    CGFloat xDelta = position.x - beginTouchPoint.x;
    CGFloat yDelta = position.y - beginTouchPoint.y;
        [self findSwipeDirectionWith: xDelta and: yDelta];

}

cocos2dを使用した場合と同等のものは何ですか?

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    // Save the position
    for (UITouch *touch in touches) {
        // Send to the dispatch method, which will make sure the appropriate subview is acted upon
        [self dispatchFirstTouchAtPoint:[touch locationInView:boardView] forEvent:nil];
    }
}

// Saves the first position for reference when the user lets go.
- (void) dispatchFirstTouchAtPoint:(CGPoint)touchPoint forEvent:(UIEvent *)event
{
    beginTouchPoint = touchPoint;
}

// Handles the continuation of a touch.
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
    for (UITouch *touch in touches) {
        // Send to the dispatch method, which will make sure the appropriate subview is acted upon
        [self dispatchTouchEndEvent:[touch view] toPosition:[touch locationInView:boardView]];
    }
}

-(void) dispatchTouchEndEvent:(UIView *)theView toPosition:(CGPoint)position
{   id  sender;
    int directionSwiped;
    int row,column;
    CGFloat xDelta = position.x - beginTouchPoint.x;
    CGFloat yDelta = position.y - beginTouchPoint.y;
        [self findSwipeDirectionWith: xDelta and: yDelta];

}

私は自分でこれを理解しようとしました、そして私はグーグルで何時間も過ごしました、しかし私は実行可能な解決策を思いつきませんでした。

4

1 に答える 1

1

私はそれを考え出した。私が忘れていたのは、次のことを追加することであることがわかりました。

self.isTouchEnabled = YES;

Layer の init メソッドに。

それを行った後、次のコードが機能しました(beginTouchPointとendTouchPointはクラスのプロパティです):

 -(void)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {

    UITouch* myTouch = [touches anyObject];     
    CGPoint location = [myTouch locationInView: [myTouch view]];
    beginTouchPoint = [[CCDirector sharedDirector]convertToGL:location];    
}

    // Handles the continuation of a touch.*
-(void) ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
    static BOOL isFirstTouch = YES;
    UITouch* myTouch = [touches anyObject];
    int row,column;
    int directionSwiped;
    CGPoint location = [myTouch locationInView: [myTouch view]];    
    endTouchPoint = [[CCDirector sharedDirector]convertToGL:location];
    CGFloat xDelta = endTouchPoint.x - beginTouchPoint.x;
    CGFloat yDelta = endTouchPoint.y - beginTouchPoint.y;
    [self findSwipeDirectionWith: xDelta and: yDelta];

}

于 2010-08-23T06:50:38.153 に答える