2.x 升到3.x记录一下常用的API变化

常规node属性

node.x            ->         node.position.x

node.y             ->        node.postion.y

node.color        ->         node.getComponent(Sprite).color 

node.opacity      ->         node.getComponent(UIOpacity).opacity

node.width         ->        node.getComponent(UITransform).width

node.height       ->         node.getComponent(UITransform).height

node.anchorX     ->          node.getComponent(UITransform).anchorX

node.anchorY     ->          node.getComponent(UITransform).anchorY

  

 removeFromParent不能传参了

原removeFromParent(true)和removeFromParent(false), 现在不能传参了

removeFromParent(true)和removeFromParent(false)  ->  removeFromParent()

  

计时器Scheduler的enableFroTarget

Scheduler.enableForTarget的对象必须继承自接口ISchedulable,继承ISchedulable接口的有System、CCObject。

cc.director.getScheduler().enableForTarget(this);        ->         Scheduler.enableForTarget(this);
 
 macro不能自动导入,只能鼠标移到macro上然后点击修复
sheduler.schedule(()=>{}, this, 1, macro.REPEAT_FOREVER); 
 

SpriteFrame

纹理、原始大小等接口都变了

spriteFrame.getTexture()    ->    spriteFrame.texture
spriteFrame.getOriginalSize()    ->    spriteFrame.originalSize
 
let newSp = new cc.SpriteFrame(texture, cc.rect(0, 0, texture.width, texture.height));     ->     let newSp = new SpriteFrame();
newSp.setRect(cc.rect(j * width, i * height, width, height));                                     newSp.texture = texture;
                                                                                                  newSp.rect = rect(j * width, i * height, width, height);

  

鼠标事件getLocation
EventTouch         
e.getLocation         ->        e.getUILocation
3.0EventTouch的getLocation获取的位置已经不正确了,需要使用getUILocation
 

按钮吞噬事件  

(this.node as any)._touchListener.setSwallowTouches(false)       ->       this.topBg.eventProcessor.touchListener.setSwallowTouches(false)

  

调试面板

 Framerate          帧率,一般为60,表示每秒钟刷新60次

Draw call            通知GPU渲染的过程称为一次Draw Call

Frame time         每帧时间,1秒/60次 = 16.67毫秒
Instance Count   实例数量?
Triangle              三角面数量?
Game Logic       游戏逻辑耗时
Physics              物理引擎耗时
Renderer           渲染耗时
GFX Texture Mem  纹理缓存   一张512x512的32位图占用内存  8位=1字节,32位=4字节, 512x512x4 = 1048576字节,  1024字节=1KB, 1024KB=1M,  1048576/1024/1024 = 1M
GFX Buffer Mem     ?
 
 获取屏幕尺寸
cc.WinSize   ->    view.getFrameSize()
 
 Camera的Visiblity属性
如果是新建的node,node默认Layer是default,而Camera没有勾选可见default的话,那么节点不会显示。

 EventTarget

 原来2.x的on、off、emit这些接口没有了,3.x变成了addEventListener之类的....
 
 保留cc的用法
3.x版本cc.Node改成了Node,没有了前缀'cc'。
import { _decorator, Component, Node } from 'cc';
const { ccclass, property } = _decorator;

@ccclass('MainScene')
export class MainScene extends Component {
    start () {
        let node:Node = new Node();
    }
}

导致代码提示的时候,眼神不好可能会选错,例如下面有2个Animation的提示。  

 

使用 import * as cc from "cc"; 可以继续使用cc.Node来访问

import * as cc from "cc";

const { ccclass, property } = cc._decorator;

@ccclass('MainScene')
export class MainScene extends cc.Component {

    start() {
        let node: cc.Node = new cc.Node();
    }
}

  

 
 
 
 
 
原文地址:https://www.cnblogs.com/gamedaybyday/p/15320036.html