如何设置CC3Node在层中的位置?

发布于 2024-12-01 06:21:55 字数 171 浏览 1 评论 0原文

我在文档中找不到这个。

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

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

I've not been able to find this in the docs.

I've got a CC3Node (myNode) and my layer has the callbacks for touchDown & touchMoved events all of which works, so far. I'm trying to drag myNode around the screen, preferably using screen coordinates.

How do I set myNode's location relative to screen (layer) coordinates?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

醉态萌生 2024-12-08 06:21:55

好吧,我终于找到了这个,尽管这些碎片有点分散在多个帖子中。我的最终解决方案如下所示:

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

Ok, I finally tracked this down, although the pieces were a bit scattered around in multiple posts. My final solution looked something like this:

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];
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文