新手踩坑

未解决

已解决

动作 action 怎么实现 cc.moveto 没有了

改成了cc.tween
         let action = cc.tween(this.node)

        action.to(duration,{

            position:new cc.Vec3(tempNextPoint.x,tempNextPoint.y,0),

        })

        let self = this

        action.call(function(){

            self.runNextPoint()

        })

可能用action习惯了 感觉不如ation 好用

点的运算改为 cc.Vec2.distance() 静态方法

导入TiledMap tmx之后图片后在编辑其中显示紫色地图

导入的png图片type需要改为spriteframe

导入tmx之后图片报错

tmx文件中图片路径使用了绝对路径

运行后不显示tmx地图

编辑器的camera 的visiblility 属性点开要勾选default  坑

tiledmap老版本需要前往源码github 下载 略坑

trim 导致空白区域被裁切图片位置错位

sprite默认trim 需要手动去掉trim选项勾选 同时修改sizemode

动态加载prefab

比如根据配置动态加载怪物 
//创建怪物
        let self = this;
        resources.load("monster", Prefab,function(errorMessage,loadedResource){
            if(errorMessage)
            {
                log(errorMessage)
            }
            if(loadedResource)
            {
                let monster  = instantiate(loadedResource)
                monster.setPosition(50,0);
                self.node.addChild(monster)
                //this.getGameManager:addMonster()
            }
       });

这样定义一个prefab 变量并通过拖拽在界面上赋值

	@property(Prefab)
    monster:Prefab | null=null;

那怎么生成node?
这么写不对

	var monster  = instantiate(this.monster)
       if (monster)
       {
            monster.setPosition(0,0);
            //monster.setZOrder(10);
            this.node.addChild(monster)
       }

这么写是对的实际可以创建出node 只是typescript检查不通过 所以报错
解决如下

 感谢 [玄朗Anto]
instantiate()根据传入参数类型不同分为两种,
若形如monster:Prefab|null = null;则须let monster = instantiate(this.monster!);可返回node类型。
亦可声明为:monster:Prefab = null!;或monster:Prefab = null as unknown as Prefab;
仅供参考。

typescript 怎么使用cc. 而不是这样导入一大堆

比如使用 想new cc.Vec2 而不是导入Vec2 使用new Vec2()

import  { _decorator, Component, Node,Prefab,TiledMap,TiledLayer,log,Vec2,resources,instantiate } from 'cc';
感谢 [xzben]
import * as cc from “cc”
1赞

import * as cc from “cc”

instantiate()根据传入参数类型不同分为两种,若形如monster:Prefab|null = null;则须let monster = instantiate(this.monster!);可返回node类型。亦可声明为:monster:Prefab = null!;或monster:Prefab = null as unknown as Prefab;仅供参考。

帖子超过四天不能编辑了?

怎么删帖?