我无法在文档中找到这个。
我有一个 CC3Node (myNode),我的图层有 touchDown 和 touchMoved 事件的回调,到目前为止所有这些都有效。我正在尝试在屏幕上拖动 myNode,最好使用屏幕坐标。
如何设置 myNode 相对于屏幕(层)坐标的位置?
我无法在文档中找到这个。
我有一个 CC3Node (myNode),我的图层有 touchDown 和 touchMoved 事件的回调,到目前为止所有这些都有效。我正在尝试在屏幕上拖动 myNode,最好使用屏幕坐标。
如何设置 myNode 相对于屏幕(层)坐标的位置?
好的,我终于找到了这个,尽管这些碎片有点分散在多个帖子中。我的最终解决方案如下所示:
我的世界.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];
}