我无法在文档中找到它。
我有一个CC3Node(myNode),我的图层有touchDown和amp;的回调。到目前为止,touchMoved事件都有效。我正试图在屏幕上拖动myNode,最好是使用屏幕坐标。
如何设置myNode相对于屏幕(图层)坐标的位置?
答案 0 :(得分: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];
}