2

我想使用手势来平移广告牌,我该怎么做,我已经修改了 DemoMashUp,如下所示:

 - (void)dragBy: (CGPoint) aMovement atVelocity: (CGPoint) aVelocity
{
     if (selectedNode == dieCube || selectedNode == texCubeSpinner) {
         [self rotate: ((SpinningNode*)selectedNode) fromSwipeVelocity: aVelocity];
     }

     if (selectedNode==marker) {
         [self moveSelectedNode:marker fromSwipeMovement:aMovement];
     }
 }

- (void)stopDragging
{
    selectedNode = nil;
}

 - (void)moveSelectedNode:(CC3Billboard*) aNode fromSwipeMovement: (CGPoint) swipeMovement
{
     aNode.location=cc3v(swipeMovement.x, swipeMovement.y, aNode.location.z);
}

但它不起作用,当我触摸广告牌时它消失了

4

1 回答 1

2

我制作了一个新方法 moveSelectedNode "DemoMashUpScene",如下所示:

   -(void) touchEvent: (uint) touchType at: (CGPoint) touchPoint {
    NSLog(@"\n\n*******************TOUCH EVEN CALLED************************\n\n");


    switch (touchType) {
        case kCCTouchBegan:
            [self pickNodeFromTouchEvent: touchType at: touchPoint];
            break;
        case kCCTouchMoved:

        if (selectedNode==marker||selectedNode==marker1||selectedNode==marker2||selectedNode==marker3||selectedNode==marker4||selectedNode==marker5)
            {


               [self moveSelectedNode:marker1 fromSwipeMovement:touchPoint];


            }
            break;
        case kCCTouchEnded:

            selectedNode = nil;
            break;
        default:
            break;
    }

    lastTouchEventPoint = touchPoint;
    lastTouchEventTime = now;
}

-(void) moveSelectedNode: (CC3Billboard*) aNode fromSwipeMovement: (CGPoint) swipeMovement {

    CC3Vector vector=    CC3VectorMake(swipeMovement.x * 3, swipeMovement.y * 3, 0);
    aNode.location=cc3v(aNode.location.x, aNode.location.y, 0.0);
    aNode.location=CC3VectorAdd(aNode.location,vector);    
    CCLOG(@"%@",aNode.name);
//    NSLog(@"\n\n ******MOVING****%f_____%f*****____%f",vector.x,vector.y,vector.z);


}
于 2013-04-10T15:03:42.583 回答