質問

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];

}

私はこれを自分で理解しようとしましたが、Googleで何時間も費やしましたが、実行可能なソリューションは考えていません。

役に立ちましたか?

解決

私はそれを考え出した。私は、私がやるのを忘れていたことが追加することであることを発見しました:

self.isTouchEnabled = YES;

レイヤーの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];

}

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top