Cocos Creator 2.x升级至Cocos Creator 3.x

风别鹤 / 2024-02-29 / 原文

1.
导入类时,批量导入

2.
导入 override...关键字时,批量导入

3、
this.node.scale = 0.6
-->
this.node.setScale(0.6, 0.6);

4、
node.anchorX =
node.anchorY =
-->
.getComponent( UITransform )!.

5、
.getComponent( UIOpacity )!.opacity

6.
.on( 'touchend',
-->
.on( NodeEventType.TOUCH_END,

7、
public audioSource!: AudioSource;

this.audioSource = this.node.getComponent( AudioSource )!;

this.audioSource.playOneShot( this.audio_arr[ 1 ], 1 );

this.audioSource.clip = this.audio_arr[ 0 ];
this.audioSource.play();

this.audioSource.stop();

8、
children[i].getBoundingBox().contains(pos_start_bg3)
-->
.getComponent( UITransform )?.hitTest( pos_touch )

9、
this.node.convertToWorldSpaceAR(children[i].getPosition())
-->
children[i].getWorldPosition();