当前位置:网站首页>LayaBox---TypeScript---Problems encountered at first contact
LayaBox---TypeScript---Problems encountered at first contact
2022-08-04 21:08:00 【Gragra】
目录
1.Drag and drop the image to the Hierarchy panel,F6执行,Not displayed in canvas
2.Public variables are defined in the script,Not displayed in the panel
3:选中物体,调整collider的x为负数时,运行时,物体消失.
问题5:Get the script mounted on the object through the object
问题7.Note that variables with the same name cannot be used even in different scripts
1.Drag and drop the image to the Hierarchy panel,F6执行,Not displayed in canvas
Tried a few times to find out The difference between the picture that is not displayed and the picture that is displayed is. Pictures that don't show are not set to‘不打包’.Try changing the image to unpacked,结果显示正常.
2.Public variables are defined in the script,Not displayed in the panel
/** @prop {name:intType, tips:"整数类型示例", type:Int, default:1000}*/
public intType: number = 1000;
/** @prop {name:numType, tips:"数字类型示例", type:Number, default:1000}*/
public numType: number = 1000;
/** @prop {name:strType, tips:"字符串类型示例", type:String, default:"hello laya"}*/
public strType: string = "hello laya";
/** @prop {name:boolType, tips:"布尔类型示例", type:Bool, default:true}*/
public boolType: boolean = true;
/** @prop {name:shoe,tips:"物体",type:Node,default:null}*/
public shoe = null;
// 更多参数说明请访问: https://ldc2.layabox.com/doc/?nav=zh-as-2-4-0Repeated research many times,最终发现问题出在layaAir IDE There is no automatic refresh mechanism,Objects not mounted by this script need to be manually selected,然后再回来,to refresh the newly defined variable properties.
very tightQ,Almost had to rewrite the blog as: LayaBoxFrom install to uninstall
3:选中物体,调整collider的x为负数时,运行时,物体消失.
It needs to be selected under the object in the hierarchy panelcollider组件,instead of selecting the object Then go to the properties panel to adjustcollider的位置.
4:Get object coordinates
NodeObjects of type have no coordinate properties,需要手动转为Laya.Sprite 或 3d的 Laya.Sprite3D
private own:Laya.Sprite = null;
this.own = this.owner as Laya.Sprite;
console.log(this.own.y);问题5:Get the script mounted on the object through the object
Scripts are mounted on topScene物体上,can't get the object.There is no way to get the script on the object

解决办法:Don't hook scripts to scene objects,Other sub-objects can be selected,Then you can get it.
/** @prop {name:score,tips:"物体",type:Node,default:null} */
score = null;
private scoreScript = null;
onAwake()
{
this.scoreScript = this.score.getComponent(ScorePanel);
}问题6:Variables exposed in the properties panel After panel assignment,In-code calls appear as null 或 undefined
Research for a long time did not find the reason and solution,Finally, replace it with code acquisition
private txt_timer:Laya.Text =null;
private txt_myScore:Laya.Text =null;
private txt_aiScore:Laya.Text =null;
onAwake()
{
this.txt_myScore = this.owner.getChildByName("txt_myScore") as Laya.Text;
this.txt_aiScore = this.owner.getChildByName("txt_aiScore") as Laya.Text;
this.txt_timer = this.owner.getChildByName("txt_timer") as Laya.Text;
}问题7.Note that variables with the same name cannot be used even in different scripts
问题8:如上,There is no problem getting the child objects under the script mounted object,You can't get other objects.
this.time_down = Laya.stage.getChildByName("txt_timeDown");调试结果 stage 下的child数量为0. 暂未解决
边栏推荐
猜你喜欢
随机推荐
2、字符集-编码-解码
win10 uwp 使用 WinDbg 调试
PRIMAL: Pathfinding via Reinforcement and Imitation Multi-Agent Learning 代码解析
SPSS-System Clustering Hand Calculation Practice
c语言小项目(三子棋游戏实现)
dotnet 删除只读文件
三种方式设置特定设备UWP XAML view
QT(42)-QT线程-线程调用槽函数
27.降维
【C语言】指针和数组的深入理解(第三期)
漫画 | 老板裁掉我两周后,又把我请回去,工资翻番!
win10 uwp use WinDbg to debug
Configure laravel queue method using fort app manager
Getting Started with Lattice Passwords
[Teach you to use the serial port idle interrupt of the STM32HAL library]
构建Buildroot根文件系统(I.MX6ULL)
如何最简单、通俗地理解爬虫的Scrapy框架?
js数据类型、节流/防抖、点击事件委派优化、过渡动画
拼多多开放平台订单信息查询接口【pdd.order.basic.list.get订单基础信息列表查询接口(根据成交时间)】代码对接教程
Zynq Fpga图像处理之AXI接口应用——axi_lite接口使用









