当前位置:网站首页>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-0
Repeated 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. 暂未解决
边栏推荐
- vs Code runs a local web server
- 如何用好建造者模式
- 【2022杭电多校5 1012题 Buy Figurines】STL的运用
- LayaBox---TypeScript---首次接触遇到的问题
- Configure laravel queue method using fort app manager
- PowerCLi 导入License到vCenter 7
- Interviewer: How is the expired key in Redis deleted?
- How to make good use of builder mode
- Comic | Two weeks after the boss laid me off, he hired me back and doubled my salary!
- 路由中的meta、params传参的一些问题(可传不可传,为空,搭配,点击传递多次参数报错)
猜你喜欢
随机推荐
stm32mp157系统移植 | 移植ST官方5.10内核到小熊派开发板
[Data Mining] Written Exam Questions for Sohu Data Mining Engineers
【Programming Ideas】
遇到MapStruct后,再也不手写PO,DTO,VO对象之间的转换了
SPSS-System Clustering Hand Calculation Practice
推荐系统_刘老师
After the tester with 10 years of service "naked resignation" from the big factory...
PRIMAL: Pathfinding via Reinforcement and Imitation Multi-Agent Learning 代码解析
【C语言】指针和数组的深入理解(第三期)
Using Baidu EasyDL to realize forest fire early warning and identification
【2022杭电多校5 1003 Slipper】多个超级源点+最短路
[AGC] Build Service 1 - Cloud Function Example
How to understand the crawler's Scrapy framework in the simplest and most popular way?
【AGC】构建服务1-云函数示例
【2022杭电多校5 1012题 Buy Figurines】STL的运用
Web3时代的战争
adb控制常用命令
Cryptography Series: PEM and PKCS7, PKCS8, PKCS12
顺序队列
xss课堂内容复现