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

1.
导入类时,批量导入

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

3、
.x .y
-->
.setPosition( block.position.x, block.position.y );

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

5、
node.anchorX =
node.anchorY =
node.width =
node.height =
node.getContentSize
-->
.getComponent( UITransform )!.

6、
.opacity
-->
.getComponent( UIOpacity )!.opacity

淡出
fadeOut
-->
tween( node.getComponent( UIOpacity ) ).to( 0.1, { opacity: 0 } ).start();

淡入
fadeIn
-->
tween( node.getComponent( UIOpacity ) ).to( 0.1, { opacity: 1 } ).start();

移动到目标位置。
moveTo( 0.2, cc.v2( 5, 5 ) )
-->
tween( node ).to( 0.2, { position: new Vec3( 5, 5, 0 ) } ).start();

移动指定的距离。
moveBy( 0.2, cc.v2( 5, 5 ) )
-->
const vec3:Vec3 = this.getPosition();
tween( node ).to( 0.2, { position: new Vec3( vec3.x + 5, vec3.y + 5, vec3.z ) } ).start();

缩放大小
cc.scaleTo(0.2, 1);
->
tween( this.node ).to( 0.2, {scale:new Vec3(1,1,1)} ).start();

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

8、
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();

9、
children[i].getBoundingBox().contains(pos_start_bg3)
-->
.getComponent( UITransform )?.hitTest( pos_touch, event.windowId )

10、
获取组件的世界坐标
this.node.convertToWorldSpaceAR(children[i].getPosition())
-->
children[i].getWorldPosition();

11、
世界坐标转化为容器内的坐标
this.getComponent( UITransform )!.convertToNodeSpaceAR( targetWorldPosition );

posted @ 2024-02-29 17:21  风别鹤  阅读(124)  评论(0编辑  收藏  举报