当前位置:网站首页>LayaBox---知识点
LayaBox---知识点
2022-08-04 21:00:00 【格拉格拉】
目录
5.代码发生变动,如新增公有变量。需手动切换鼠标选中物体,再选回来才会刷新。
6.定义的公有物体变量node 没有坐标属性,需进行类型转换
1.visualcode---配置model快捷模版
code---首选项---配置用户代码片段
2.定义在属性面板显示的变量
/** @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.获取脚本挂载物体组件
this.owner.getComponent(Laya.RigiBody);4.删除已挂载的脚本,还得在挂载物体上删除引用。
5.代码发生变动,如新增公有变量。需手动切换鼠标选中物体,再选回来才会刷新。
6.定义的公有物体变量node 没有坐标属性,需进行类型转换
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.Laya事件广播与接收
广播事件:
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.代码获取游戏内物体
//查找一级物体
Laya.stage.getChildByName("Player");
//查找本物体下的子物体
this.owner.getChildByName("子物体名");14.音乐音效播放
//播放音乐
Laya.soundManager.playMusic(“地址/music.mp3”,0); //0为无限循环
//单纯播放音效
Laya.SoundManager.playSound("sound/BallHit-01.mp3");
//播放完成后加事件
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!...

web漏洞扫描器-awvs

Oreo域名授权验证系统v1.0.6公益开源版本网站源码

使用百度EasyDL实现森林火灾预警识别

项目难管理?先学会用好甘特图(内附操作方法及实用模板)

【CAS:2306109-91-9 |胺-PEG4-脱硫生物素】价格

Interviewer: How is the expired key in Redis deleted?
![[TypeScript] In-depth study of TypeScript enumeration](/img/27/4836e59528bb5a51ffc1cf9961c6b6.png)
[TypeScript] In-depth study of TypeScript enumeration

拒绝服务攻击DDoS介绍与防范

Big capital has begun to flee the crypto space?
随机推荐
How to make good use of builder mode
vs Code 运行一个本地WEB服务器
【C语言】指针和数组的深入理解(第三期)
二叉搜索树解决硬木问题
手撕SparkSQL五大JOIN的底层机制
dotnet 启动 JIT 多核心编译提升启动性能
【2022牛客多校5 A题 Don‘t Starve】DP
【CAS:2306109-91-9 |胺-PEG4-脱硫生物素】价格
Apache服务器配置多个站点
3、IO流之字节流和字符流
Qt Designer生成的图形可以自适应窗口的大小变化
长时间序列遥感数据处理及在全球变化、物候提取、植被变绿与固碳分析、生物量估算与趋势分析等领域中的应用
PriorityQueue类的使用及底层原理
【数据挖掘】搜狐公司数据挖掘工程师笔试题
run command for node
两种白名单限流方案(redis lua限流,guava方案)
Web3安全风险令人生畏,应该如何应对?
composition-api
经验分享|盘点企业进行知识管理时的困惑类型
知识分享|如何设计有效的帮助中心,不妨来看看以下几点