最近进入游戏公司,但最近行情大家应该也知道,游戏版号寒冬,总体趋势不太好,而目前app软件介于h5存在,出现一波下跌趋势,目前微信小游戏是很多公司必争的势头吗,故我这u3d程序员在面试之后转岗成一枚laya程序员
so,因为我之前是搞u3d的,所以目前公司里对我要求是搞laya
最后下面是我开发笔记
这段时间,我准备写一个走迷宫的game,这段时间就开始搜集素材,打算写出来。
先自己纠结移动怎么写。其实也就是改坐标,看了下官方案例,对于子弹移动是借助刚体,rigidbody这块和u3d区别不大,毕竟内部都需要依赖物理引擎,至于引擎怎么实现,不是我们这个游戏逻辑设计需要关注的 。
var rig: Laya.RigidBody = this.owner.getComponent(Laya.RigidBody);
rig.setVelocity({ x: 0, y: -10 });
这段是官网提供我们的设计子弹代码,不过这里我们并没有引用。laya坐标系和u3d坐标系是相反的,所以我们这里y为负值是向上发射
理解了这个,再根据u3d设计代码的办法,其实也是大同小异,u3d中会getcomponent<rigidbody>(),获取之后SetVelocity是一样的,只不过设置是一个new vector3()对象罢了,这里一个是3d引擎一个是2d引擎,这里就不讨论了,只是为了描述,当你有了一门引擎经验,另外一门引擎上手将会相当容易
于是我便设计这样的代码
private _started: boolean = false;
/**子弹和盒子所在的容器对象 */
private buttonup:Laya.Sprite;
private buttondown:Laya.Sprite;
private buttonleft:Laya.Sprite;
private buttonright:Laya.Sprite;
private player:Laya.Sprite;
private b:boolean[];
public moveX=0;
public mouseY=0;
constructor() { super(); }
onEnable(): void {
this.b=[true,true,true,true];
this.player=GameUI.instance.wanjia;
this.buttondown=GameUI.instance.down;
this.buttonleft=GameUI.instance.left;
this.buttonup=GameUI.instance.up;
this.buttonright=GameUI.instance.right;
this.player=GameUI.instance.wanjia;
this._time = Date.now();
this.buttondown.on(Laya.Event.MOUSE_DOWN,this,this.down);
this.buttonleft.on(Laya.Event.MOUSE_DOWN,this,this.left);
this.buttonup.on(Laya.Event.MOUSE_DOWN,this,this.up);
this.buttonright.on(Laya.Event.MOUSE_DOWN,this,this.right);
Laya.stage.on(Laya.Event.MOUSE_UP, this, this.realese);
}
onUpdate(): void {
let now = Date.now();
if(this.b[0]==false)
{
this.moveX=-0.5*(Laya.timer.delta);
}
if(this.b[1]==false)
{
this.moveX=0.5*(Laya.timer.delta);
} if(this.b[2]==false)
{
this.mouseY=-0.5*(Laya.timer.delta);
} if(this.b[3]==false)
{
this.mouseY=0.5*Laya.timer.delta;
}
if(this.b[0]==true&&this.b[1]==true)
{
this.moveX=0;
}
if(this.b[2]==true&&this.b[3]==true)
{
this.mouseY=0;
}
// console.log(this.b[0]+""+ this.b[1]+""+ this.b[2]+""+ this.b[3])
this.player.pos(this.player.x+this.moveX,this.player.y+this.mouseY);
//定义玩家坐标,加上movex,movey
}
realese():void{
this.b=[true,true,true,true];
}
up():void{
//GameUI.up();
//this.player.pos(this.player.x,this.player.y-10)
this.b[2]=false;
}
down():void{
this.b[3]=false;
//this.player.pos(this.player.x,this.player.y+10)
}
//...以下省略左右的代码