当前位置:网站首页>LayaBox---knowledge point
LayaBox---knowledge point
2022-08-04 21:09:00 【Gragra】
目录
2.Defines the variable displayed in the properties panel
3.Get the script to mount the object component
4.Remove mounted scripts,Also have to remove the reference on the mount object.
6.Defined public object variablesnode There are no coordinate properties,需进行类型转换
8.LayaEvent broadcasting and reception
13.The code gets the in-game object
1.visualcode---配置model快捷模版
code---首选项---配置用户代码片段
2.Defines the variable displayed in the properties 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-03.Get the script to mount the object component
this.owner.getComponent(Laya.RigiBody);4.Remove mounted scripts,Also have to remove the reference on the mount object.
5.代码发生变动,Such as adding public variables.You need to manually switch the mouse to select objects,Select it again to refresh.
6.Defined public object variablesnode There are no coordinate properties,需进行类型转换
2d:
public get gameObject():Laya.Sprite
{
return this.owner as Laya.Sprite;
}
3d:
public get gameObject():Laya.Sprite3D
{
return this.owner as Laya.Sprite3D;
}
-------------------------------------------------
public get transform():Laya.Transform
{
return this.gameObject.transform;
}7.Laya脚本参数说明
8.LayaEvent broadcasting and reception
广播事件:
Laya.stage.event("事件名");接收事件:
onAwake()
{
//添加监听
Laya.stage.on("事件名",this,this.reset);
}
private reset(){
//.....
}
onDestroy(){
//移除监听
Laya.stage.off("事件名",this,this.reset);
}9.插值
Laya.MathUtill.lerp(curObj.x,targetObj.x,Laya.timer.delta/1000 * speed);10.勾股定理 求距离
a*a + b*b = c*c;
c = Math.sqrt(a*a + b*b);11.随机值
private getRandom(min, max)
{
let value = max - min;
value = Math.random() * value;
return value + min;
}12.获取键盘按键
1.
onUpdate()
{
if (Laya.KeyBoardManager.hasKeyDown(Laya.Keyboard.A))
{
this.rig.setVelocity({ x: -10, y: this.rig.linearVelocity.y });
} else if (Laya.KeyBoardManager.hasKeyDown(Laya.Keyboard.D))
{
this.rig.setVelocity({ x: 10, y: this.rig.linearVelocity.y });
}
}
2.
onKeyDown(e)
{
//console.log(e.nativeEvent.key+".........2");
if (e.nativeEvent.key == " " && this.canJump)
{
this.canJump = false;
this.rig.setVelocity({ x: this.rig.linearVelocity.x, y: -13 });
}
}
3.
onKeyPress(e)
{
console.log(e.nativeEvent.key+".........1");
if(e.nativeEvent.key == "a")
{
}
}13.The code gets the in-game object
//Find primary objects
Laya.stage.getChildByName("Player");
//Find sub-objects under this object
this.owner.getChildByName("child object name");14.音乐音效播放
//播放音乐
Laya.soundManager.playMusic(“地址/music.mp3”,0); //0为无限循环
//Just play sound effects
Laya.SoundManager.playSound("sound/BallHit-01.mp3");
//Add an event after playback is complete
Laya.SoundManager.playSound("sound/startWistle.mp3",1,
new Laya.Handler(this,()=>{
Laya.stage.event("StartGame"); //广播--开始游戏
}));边栏推荐
猜你喜欢
![[Academic related] Tsinghua professor persuaded to quit his Ph.D.:I have seen too many doctoral students have mental breakdowns, mental imbalances, physical collapses, and nothing!...](/img/d8/a367c26b51d9dbaf53bf4fe2a13917.png)
[Academic related] Tsinghua professor persuaded to quit his Ph.D.:I have seen too many doctoral students have mental breakdowns, mental imbalances, physical collapses, and nothing!...

无代码平台字段设置:基础设置入门教程

Feign 与 OpenFeign

使用堡塔应用管理器配置laravel队列方法
![[2022 Hangzhou Electric Multi-School 5 1003 Slipper] Multiple Super Source Points + Shortest Path](/img/78/054329dec6a6faea5e9d583b6a8da5.png)
[2022 Hangzhou Electric Multi-School 5 1003 Slipper] Multiple Super Source Points + Shortest Path

c语言小项目(三子棋游戏实现)

Web3时代的战争

Uniapp微信雪糕刺客单页小程序源码

构建Buildroot根文件系统(I.MX6ULL)

SAP ABAP OData 服务如何支持 $select 有选择性地仅读取部分模型字段值试读版
随机推荐
[AGC] Build Service 1 - Cloud Function Example
C#之app.config、exe.config和vshost.exe.config作用区别
【AGC】构建服务1-云函数示例
知识分享|如何设计有效的帮助中心,不妨来看看以下几点
【2022牛客多校5 A题 Don‘t Starve】DP
Dotnet using WMI software acquisition system installation
dotnet 使用 lz4net 压缩 Stream 或文件
[2022 Hangzhou Electric Multi-School 5 1003 Slipper] Multiple Super Source Points + Shortest Path
后缀式的计算
【2022杭电多校5 1012题 Buy Figurines】STL的运用
密码学系列之:PEM和PKCS7,PKCS8,PKCS12
ts集成和使用
ADB 安装 + 打驱动全教程
如何用好建造者模式
C语言小笔记+题
Interviewer: How is the expired key in Redis deleted?
【C语言】指针和数组的深入理解(第三期)
【学术相关】清华教授发文劝退读博:我见过太多博士生精神崩溃、心态失衡、身体垮掉、一事无成!...
明明加了唯一索引,为什么还是产生了重复数据?
【一起学Rust | 进阶篇 | Service Manager库】Rust专用跨平台服务管理库