Commit 10ba22f7 by Shawn Wang

control refactor

parent 659607b4
fe/resource/assets/control.jpg

22.9 KB | W: | H:

fe/resource/assets/control.jpg

30.1 KB | W: | H:

fe/resource/assets/control.jpg
fe/resource/assets/control.jpg
fe/resource/assets/control.jpg
fe/resource/assets/control.jpg
  • 2-up
  • Swipe
  • Onion skin
......@@ -6,7 +6,6 @@ class Controller extends egret.Sprite {
private control = new egret.Bitmap()
private panel = new egret.Shape()
private pointtt = new egret.Shape()
private up = new egret.Shape()
private down = new egret.Shape()
......@@ -21,11 +20,6 @@ class Controller extends egret.Sprite {
this.panel.graphics.endFill()
this.addChild(this.panel)
this.pointtt.graphics.beginFill(0xFF0000, 1)
this.pointtt.graphics.drawCircle(667, 375, 15)
this.pointtt.graphics.endFill()
this.addChild(this.pointtt)
let texture: egret.Texture = RES.getRes("control_jpg")
this.control.texture = texture
......@@ -65,17 +59,19 @@ class Controller extends egret.Sprite {
controlContainer.addChild(this.right)
}
private delta = 72
private controlTouchBegin(e: egret.TouchEvent){
const delta = {x:0, y: 0}
if(e.currentTarget === this.up){
this.pointtt.y += this.delta
delta.y -= 1
}else if(e.currentTarget === this.down){
this.pointtt.y -= this.delta
delta.y += 1
}else if(e.currentTarget === this.left){
this.pointtt.x -= this.delta
delta.x -= 1
}else if(e.currentTarget === this.right){
this.pointtt.x += this.delta
delta.x += 1
}
this.dispatchEventWith("position_change", false, delta)
}
public release() {
......
class GameScene extends egret.Sprite {
private controller
private controller: egret.Sprite
public constructor() {
super();
this.init()
}
private pointtt = new egret.Shape()
// 初始化(给开始按钮绑定点击事件)
private init() {
// put display object to this scene
this.controller = new Controller()
this.addChild(this.controller)
this.controller.addEventListener("position_change", this.onPositionChange, this)
this.pointtt.graphics.beginFill(0xFF0000, 1)
this.pointtt.graphics.drawCircle(667, 375, 15)
this.pointtt.graphics.endFill()
this.addChild(this.pointtt)
}
private step = 72
private onPositionChange(delta){
this.pointtt.x += this.step * delta.data.x
this.pointtt.y += this.step * delta.data.y
}
public release() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment