微信坐标转换creator坐标

    //创建更多游戏按钮
    createMoreGameButton() {
        if (typeof (tt) == "undefined") { return };
        let sysInfo = tt.getSystemInfoSync()
        if (sysInfo.platform == "ios") return;

        let node = cc.find("Canvas/top/moreGamesButton");
        let rect = node.getBoundingBoxToWorld();
        let ratio = cc.view.getDevicePixelRatio();
        let scale = cc.view.getScaleX();
        let factor = scale / ratio;

        let url = this.urlStore.moreGamesButton;

        this.moreGamesButton = tt.createMoreGamesButton({
            type: "image",
            image: url,
            style: {
                left: rect.x * factor,
                top: sysInfo.windowHeight - (rect.y + rect.height) * factor,
                width: rect.width * factor,
                height: rect.height * factor,
                lineHeight: 40,
                backgroundColor: "#ff0000",
                textColor: "#ffffff",
                textAlign: "center",
                fontSize: 16,
                borderRadius: 0,
                borderWidth: 0,
                borderColor: "#ff0000"
            },
            appLaunchOptions: [
                {
                    appId: "tt80a9f6141f83bb61",
                    query: "foo=bar&baz=qux",
                    extraData: {}
                },
                {
                    appId: "tt007376ce9f59795b",
                    query: "foo=bar&baz=qux",
                    extraData: {}
                }
                // {...}
            ],
            onNavigateToMiniGame(res) {
                console.log("跳转其他小游戏", res);
            }
        });
    },
    //更多游戏按钮
    showMoreGamesButton() {
        // cc.log(this.showMoreGamesButton.caller);
        if (typeof (tt) == "undefined") return;
        let sysInfo = tt.getSystemInfoSync()
        if (sysInfo.platform == "ios") return;
        this.moreGamesButton.show();
    },
    hideMoreGamesButton() {
        if (typeof (tt) == "undefined") return;
        let sysInfo = tt.getSystemInfoSync()
        if (sysInfo.platform == "ios") return;
        this.moreGamesButton.hide();
    },
### Cocos Creator中的坐标系转换 在Cocos Creator中,节点的位置可以通过局部坐标和世界坐标的相互转换来操作。对于开发者而言,理解这两种坐标系统的区别及其转换机制至关重要。 #### 节点位置坐标转换实现原理 当涉及到不同层级节点之间的交互时,可能需要将一个节点的本地坐标转换成全局坐标或将全局坐标映射回某个特定父级下的相对位置[^1]。这种情况下可以利用`convertToNodeSpaceAR()` 和 `convertToWorldSpaceAR()` 方法完成相应的变换过程[^2]。 - **从世界坐标到节点空间坐标** 使用`cc.Node.prototype.convertToNodeSpaceAR(point)`函数可把屏幕上的触摸点或其他形式的世界坐标转变为相对于调用该方法的对象(即当前节点)来说的有效内部坐标值。 - **从节点空间坐标到世界坐标** 反之,则通过`cc.Node.prototype.convertToWorldSpaceAR(point)`接口获取指定子对象在其祖先链上所处的确切场景内定位信息。 ```javascript // 示例代码展示如何执行上述两种类型的转换 let worldPoint = nodeA.convertToWorldSpaceAR(cc.v2(0, 0)); console.log('World Point:', worldPoint); let localPoint = nodeB.convertToNodeSpaceAR(worldPoint); console.log('Local Point in Node B:', localPoint); ``` 这些API使得处理复杂的UI布局或是响应用户输入变得更加直观简便。 #### 锚点、缩放与旋转的影响 值得注意的是,在进行任何坐标计算之前应该考虑到锚点设置以及可能出现的缩放或旋转变形情况。因为它们都会影响最终得到的结果。具体来讲: - 如果设置了非默认的Anchor Points (锚点),那么即使是在同一个物理位置也会显示出不同的视觉效果; - 当存在Scale Factor (缩放因子) 或 Rotation Angle (旋转角度) 的时候,同样会影响实际渲染出来的尺寸大小及方向。 因此建议开发人员务必熟悉并合理运用好这些属性以确保预期的行为表现能够正确无误地呈现给玩家体验。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值