[LayaAir 1.0]重复背景,全方向地图拖动Demo

UI创建4个image  var分别: map0,map1,map2,map3
背景图宽高 1800
class WorldPage extends ui.WorldPageUI{
constructor (x,y) {
super()
this.maxX = 149850
this.maxY = 97500
this.offsetX = x * 150
this.offsetY = y * 150
this.downMouseX = 0
this.downMouseY = 0
Laya.loader.load(['bg/world_bg.jpg'])
Laya.stage.on(Laya.Event.MOUSE_DOWN,this,this.mouseDown)
Laya.stage.on(Laya.Event.MOUSE_UP,this,this.mouseUp)
this.moveMap(this.offsetX,this.offsetY)
}

moveMap(x,y){
let X = -x00
let Y = -y00
this.map0.x = X
this.map0.y = Y
this.map3.x = X + 1800
this.map3.y = Y + 1800
if(X < -540){
this.map1.x = X + 1800
this.map1.y = Y
}else{
this.map1.x = X - 1800
this.map1.y = Y
}
if(Y > -260){
this.map2.x = X
this.map2.y = Y - 1800
}else{
this.map2.x = X
this.map2.y = Y + 1800
}
}

mouseDown(){
this.downMouseX = Laya.stage.mouseX
this.downMouseY = Laya.stage.mouseY
Laya.stage.on(Laya.Event.MOUSE_MOVE,this,this.mouseMove)
}

mouseMove(){
let x = this.offsetX - (Laya.stage.mouseX - this.downMouseX)
let y = this.offsetY - (Laya.stage.mouseY - this.downMouseY)
this.moveMap(x>0?(x<this.maxX?x:this.maxX):0,y>0?(y<this.maxY?y:this.maxY):0)
}

mouseUp(){
let x = this.offsetX - (Laya.stage.mouseX - this.downMouseX)
let y = this.offsetY - (Laya.stage.mouseY - this.downMouseY)
this.offsetX = x>0?(x<this.maxX?x:this.maxX):0
this.offsetY = y>0?(y<this.maxY?y:this.maxY):0
Laya.stage.off(Laya.Event.MOUSE_MOVE,this,this.mouseMove)
}
}
QQ图片20181220160451.png
已邀请:

bpmf_d

赞同来自:

感谢分享~

要回复问题请先

商务合作
商务合作