2011-08-23 117 views
1

我已经无法找到这在文档中。如何设置在层CC3Node的位置?

我有一个CC3Node(myNode),我的图层有touchDown的回调& touchMoved事件到目前为止,所有这些事件都起作用。我试图在屏幕上拖动myNode,最好使用屏幕坐标。

如何设置MYNODE的位置相对于屏幕(层)坐标?

回答

1

好吧,我终于跟踪下来,虽然件件有点多个职位散落。我最终的解决方案看起来是这样的:

MyWorld.m:

// Error checking and misc removed 
- (void) addBackgroundForProjection 
{ 
    // background plane supports touch events 
    background = [CC3PlaneNode nodeWithName: BACKGROUND_PROJECTION_PLANE_NAME]; 
    [background populateAsCenteredRectangleWithSize: CGSizeMake(10.0, 10.0) 
             withTexture: [CC3Texture textureFromFile: @"transparent1x1.png"] 
             invertTexture: YES]; 
    [background setIsOpaque: NO]; 
    [background retainVertexLocations]; 
    [background setLocation: cc3v(0, 0, 0.001)]; 

    [self addChild: background]; 
} 

// ... 

- (void) moveNode: (CC3Node*) node toScreenLocation: (CGPoint) point 
{ 
    // update node on screen 
    CC3Plane groundPlane = self.background.plane; 
    CC3Vector4 touchLoc = [self.activeCamera unprojectPoint: point ontoPlane: groundPlane]; 
    CC3Vector newLoc = cc3v(touchLoc.x,touchLoc.y,touchLoc.z); 
    [node setLocation: newLoc]; 
} 
+0

请接受这个答案,如果它帮助你。这使用户有相同的问题感兴趣的答案,然后只有人可以标记这个问题的重复。 – rptwsthi