CocosCreator-常见问题和解决/过时API-持续更新

目录

3.x

 ccc 3.x 弃用 cc 全局变量

类型“Vec2”上不存在属性“mul”。

类型“never”上不存在属性“instantiate”

类型node不存在width 

2.x

Sorry, cc.Director.getWinSize is deprecated. Please use cc.winSize instead

Sorry, cc.p is deprecated

v2.1.0以,“旋转”已被弃用,请改为设置“-angle”

Sorry, cc.Node.getPositionY is removed, please use y instead.

扫描二维码关注公众号,回复: 14713242 查看本文章

其他

设置刚体.y方向速度不生效

tiledMap地图在ccc里不显示图块资源图

使用tiledmap时发现图快拼接处有间隙


  • ccc常见问题
  • 持续更新

3.x

 ccc 3.x 弃用 cc 全局变量

import * as cc from 'cc';

类型“Vec2”上不存在属性“mul”。

 在3.x中,将2.x里的函数定义ccp***(如ccp,ccpAdd,ccpSub)相关的操作都封装到了这个Vec2的类

2.4文档:Vec2 · Cocos Creator

3.2文档:Vec2 | CocosCreatorAPI

// Vec2.sub向量减法, Vec2.mag返回该向量的长度
// let linelen = posBegin.sub(posEnd).mag();
let linelen = posBegin.subtract(posEnd).length();

// Vec2.add元素向量加法, Vec2.mul缩放向量,并返回新结果
// let midPos = posBegin.add(posEnd).mul(0.5);
let midPos = posBegin.add(posEnd).multiply(v2(0.5, 0.5));

类型“never”上不存在属性“instantiate”

// this.curGrNode = cc.instantiate(this.node);

import { instantiate, director } from 'cc';
// Instantiate node from prefab.
const node = instantiate(prefabAsset);

类型node不存在width 

需要先获取节点上的 UITransform 组件,再使用对应的接口

        const uiTransform = this.getComponent(UITransform);
        // 方法一
        uiTransform.setContentSize(200, 120);
        uiTransform.setAnchorPoint(0, 0.5);

        // 方法二
        uiTransform.width = 200;
        uiTransform.height = 120;
        uiTransform.anchorX = 0;
        uiTransform.anchorY = 0.5;

event.stopPropagation() 过时

event.stopPropagation();
        event.preventDefault();


// EventTouch 里属性可以设置, 停止传递当前事件
        event.propagationStopped = true
        event.propagationImmediateStopped = true

2.x

Sorry, cc.Director.getWinSize is deprecated. Please use cc.winSize instead

升级2.xjingg

cc.Director.getWinSize获取视图的大小,以点为单位。

Sorry, cc.p is deprecated

cocos creator 2.0的废除cc.p接口Sorry, cc.p is deprecated. Please use cc.v2 instead

cc.p(500, 500); 改为

cc.Vec2(500, 500);  或  cc.v2(500, 500);

v2.1.0以,“旋转”已被弃用,请改为设置“-angle”

cc.Node.rotation` is deprecated since v2.1.0, please set `-angle` instead. (`this.node.rotation = x` -> `this.node.angle = -x`)

Sorry, cc.Node.getPositionY is removed, please use y instead.

一起的还有Sorry, cc.Node.setPositionY is removed, please use y instead

修改:

api调整,全局替换 cc.Node.setPositionY 为 cc.Node.y;
全局替换 cc.Node.setPositionX 为 cc.Node.x;
 
 // if (btnStyle.getPositionY() == 0) {
      if (btnStyle.getPosition.y == 0) {
     
     

其他

设置刚体.y方向速度不生效

this.body = this.getComponent(cc.RigidBody);

var speed = this.body.linearVelocity;

speed.x = 500;

speed.y = 500;

this.body.linearVelocity = speed;

改为

var speed = this.body.linearVelocity;

this.body.linearVelocity = cc.v2(500, 500);

tiledMap地图在ccc里不显示图块资源图

使用tiledmap时发现图快拼接处有间隙

全局关闭抗锯齿


        // 全局关闭抗锯齿
        cc.view.enableAntiAlias(false);

在编辑器里把地图使用的贴图资源的Filter Mode设置为Point

通过脚本一键修改所有图片的.meta文件里的filter mode为point:

find . -name "*.meta" | xargs perl -pi -e 's|\bbilinear\b|point|g'

猜你喜欢

转载自blog.csdn.net/qq_44695727/article/details/124695011