Commit ed387b38 by Shawn Wang

control update

parent c7c4ac86
{
"groups":[
{
"keys":"bg_jpg,egret_icon_png,description_json",
"name":"preload"
}],
"resources":[
{
"name":"bg_jpg",
"type":"image",
"url":"assets/bg.jpg"
},
{
"name":"egret_icon_png",
"type":"image",
"url":"assets/egret_icon.png"
},
{
"name":"description_json",
"type":"json",
"url":"config/description.json"
}]
"groups": [
{
"keys": "bg_jpg,egret_icon_png,description_json,control_jpg",
"name": "preload"
}
],
"resources": [
{
"name": "bg_jpg",
"type": "image",
"url": "assets/bg.jpg"
},
{
"name": "egret_icon_png",
"type": "image",
"url": "assets/egret_icon.png"
},
{
"name": "description_json",
"type": "json",
"url": "config/description.json"
},
{
"name": "control_jpg",
"type": "image",
"url": "assets/control.jpg"
}
]
}
\ No newline at end of file
......@@ -4,59 +4,78 @@ class Controller extends egret.Sprite {
this.init()
}
private speed = 10
private speedX = 0
private speedY = 0
private p1:egret.Point = new egret.Point();
private p2:egret.Point = new egret.Point();
private control = new egret.Shape();
private pointtt = new egret.Shape();
private controlCenter = new egret.Point(1100, 450)
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()
private left = new egret.Shape()
private right = new egret.Shape()
// 初始化(给开始按钮绑定点击事件)
private init() {
this.control.graphics.beginFill( 0xFF3866, 1);
this.control.graphics.drawCircle(1100, 450, 90);
this.control.graphics.endFill();
this.addChild( this.control );
this.panel.graphics.beginFill(0x353E5D, 1)
this.panel.graphics.drawRect(1008, 0, 326, 750)
this.panel.graphics.endFill()
this.addChild(this.panel)
this.pointtt.graphics.beginFill(0xFF0000, 1)
this.pointtt.graphics.drawCircle(1100, 450, 10)
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
this.touchEnabled = true
this.addEventListener(egret.TouchEvent.TOUCH_BEGIN, this.controlTouchBegin, this)
this.addEventListener(egret.TouchEvent.TOUCH_MOVE, this.controlTouchMove, this)
this.addEventListener(egret.TouchEvent.TOUCH_END, this.controlTouchEnd, this)
this.addEventListener(egret.Event.ENTER_FRAME,this.onEnterFrame,this)
}
let controlContainer = new egret.Sprite()
this.addChild(controlContainer)
controlContainer.x = 1040
controlContainer.y = 450
controlContainer.addChild(this.control)
private onEnterFrame(e: egret.Event){
if(this.touchEnd){
return
}
this.pointtt.x += this.speedX
this.pointtt.y += this.speedY
}
this.up.graphics.beginFill(0xFF00FF, 1)
this.up.graphics.drawRect(93, 0, 80, 80)
this.up.graphics.endFill()
this.up.touchEnabled = true
this.up.addEventListener(egret.TouchEvent.TOUCH_BEGIN, this.controlTouchBegin, this)
private touchEnd = false
private controlTouchBegin(e: egret.TouchEvent){
this.touchEnd = false
}
this.down.graphics.beginFill(0xFF00FF, 1)
this.down.graphics.drawRect(93, 186, 80, 80)
this.down.graphics.endFill()
this.down.touchEnabled = true
this.down.addEventListener(egret.TouchEvent.TOUCH_BEGIN, this.controlTouchBegin, this)
this.left.graphics.beginFill(0xFF00FF, 1)
this.left.graphics.drawRect(0, 93, 80, 80)
this.left.graphics.endFill()
this.left.touchEnabled = true
this.left.addEventListener(egret.TouchEvent.TOUCH_BEGIN, this.controlTouchBegin, this)
this.right.graphics.beginFill(0xFF00FF, 1)
this.right.graphics.drawRect(186, 93, 80, 80)
this.right.graphics.endFill()
this.right.touchEnabled = true
this.right.addEventListener(egret.TouchEvent.TOUCH_BEGIN, this.controlTouchBegin, this)
private controlTouchMove(e: egret.TouchEvent){
var angle = Math.atan2(e.stageY - this.controlCenter.y, e.stageX - this.controlCenter.x )
// console.error(e)
this.speedX = Math.cos(angle)*this.speed;
this.speedY = Math.sin(angle)*this.speed;
// console.error(this.speedX)
// console.error(e.stageX)
controlContainer.addChild(this.up)
controlContainer.addChild(this.down)
controlContainer.addChild(this.left)
controlContainer.addChild(this.right)
}
private controlTouchEnd(e: egret.TouchEvent){
this.touchEnd = true
// this.removeEventListener(egret.Event.ENTER_FRAME, this.onEnterFrame, this);
private delta = 72
private controlTouchBegin(e: egret.TouchEvent){
if(e.currentTarget === this.up){
this.pointtt.y += this.delta
}else if(e.currentTarget === this.down){
this.pointtt.y -= this.delta
}else if(e.currentTarget === this.left){
this.pointtt.x -= this.delta
}else if(e.currentTarget === this.right){
this.pointtt.x += this.delta
}
}
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