当前位置:网站首页>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. 暂未解决
边栏推荐
猜你喜欢
随机推荐
[Data Mining] Written Exam Questions for Sohu Data Mining Engineers
【C语言】指针和数组的深入理解(第三期)
构建Buildroot根文件系统(I.MX6ULL)
深度解析:为什么跨链桥又双叒出事了?
【编程思想】
stm32mp157系统移植 | 移植ST官方5.10内核到小熊派开发板
【学术相关】清华教授发文劝退读博:我见过太多博士生精神崩溃、心态失衡、身体垮掉、一事无成!...
How to make good use of builder mode
LayaBox---TypeScript---结构
[2022 Hangzhou Electric Power Multi-School 5 1012 Questions Buy Figurines] Application of STL
宝塔实测-搭建中小型民宿酒店管理源码
LayaBox---TypeScript---首次接触遇到的问题
使用堡塔应用管理器配置laravel队列方法
Three ways to set a specific device UWP XAML view
香港暂停进口俄罗斯部分地区禽肉及禽类产品
LayaBox---TypeScript---Example
Debug locally and start the local server in vs code
面试官:Redis中过期的key是怎么被删除的?
[2022 Hangzhou Electric Multi-School 5 1003 Slipper] Multiple Super Source Points + Shortest Path
dotnet compress Stream or file using lz4net