当前位置:网站首页>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. 暂未解决
边栏推荐
猜你喜欢

js数据类型、节流/防抖、点击事件委派优化、过渡动画

PRIMAL: Pathfinding via Reinforcement and Imitation Multi-Agent Learning 代码解析

How to carry out AI business diagnosis and quickly identify growth points for cost reduction and efficiency improvement?

Spss-一元回归实操

Big capital has begun to flee the crypto space?

五分钟入门文本处理三剑客grep awk sed

xss课堂内容复现

动手学深度学习_NiN

嵌入式分享合集28

C语言知识大全(一)——C语言概述,数据类型
随机推荐
Interviewer: How is the expired key in Redis deleted?
proe和creo的区别有哪些
Uniapp微信雪糕刺客单页小程序源码
After the tester with 10 years of service "naked resignation" from the big factory...
STP基本配置及802.1D生成树协议的改进
run command for node
matlab 画图
PRIMAL: Pathfinding via Reinforcement and Imitation Multi-Agent Learning 代码解析
ts集成和使用
项目难管理?先学会用好甘特图(内附操作方法及实用模板)
数据仓库(1)什么是数据仓库,数仓有什么特点
Data warehouse (1) What is data warehouse and what are the characteristics of data warehouse
深度解析:为什么跨链桥又双叒出事了?
Getting Started with Lattice Passwords
composition-api
路由中的meta、params传参的一些问题(可传不可传,为空,搭配,点击传递多次参数报错)
Spss-一元回归实操
Big capital has begun to flee the crypto space?
SPSS-System Clustering Hand Calculation Practice
Oreo域名授权验证系统v1.0.6公益开源版本网站源码