Commit 66a90b69 by Matt

show touch area of catcher

parent c04468c7
......@@ -4,6 +4,7 @@ const gridsInX = 14
const gridsInY = 10
class Map extends egret.Sprite {
private grids:any = []
private touchArea: egret.Bitmap
public constructor() {
super();
this.init()
......@@ -11,7 +12,6 @@ class Map extends egret.Sprite {
// 初始化(给开始按钮绑定点击事件)
private init() {
console.log('Map.init')
for (let i = 0; i < gridsInY; i++) {
this.grids.push([])
for (let j = 0; j < gridsInX; j++) {
......@@ -22,21 +22,44 @@ class Map extends egret.Sprite {
this.addChild(grid)
}
}
if (Store.isCatcher()) {
const mask = new egret.Shape()
mask.x = 100
mask.y = 100
mask.graphics.lineStyle( 10, 0x00ff00 );
mask.graphics.beginFill( 0xff0000, 1);
mask.graphics.drawCircle( 0, 0, 50 );
mask.graphics.endFill();
mask.touchEnabled = false
this.mask = mask
this.touchArea = new egret.Bitmap()
this.touchArea.texture = RES.getRes('mask_jpg')
this.touchArea.alpha = 0
this.addChild(this.touchArea)
}
public getSurroundedGrids(x, y) {
const left = Math.max(x / gridWidth - 2)
const top = Math.max(y / gridHeight - 2)
const grids = []
for (let i = left; i < 5 + left; i++) {
for (let j = top; j < 5 + top; j++) {
if (i >= 0 && j >= 0 && i < gridsInX && j < gridsInY) {
grids.push(this.grids[j][i])
}
}
}
// put display object to this scene
return grids
}
public showSurroundedGrids(x, y) {
const surroundedGrids = this.getSurroundedGrids(x, y)
surroundedGrids.forEach(grid => {
grid.alpha = 1
})
this.touchArea.alpha = 1
this.touchArea.x = x - 2 * gridWidth
this.touchArea.y = y - 2 * gridHeight
setTimeout(() => {
surroundedGrids.forEach(grid => {
grid.alpha = 0
})
this.touchArea.alpha = 0
}, 1000);
}
public release() {
// 移除事件
}
}
\ No newline at end of file
......@@ -6,25 +6,22 @@ class MapGrid extends egret.Sprite {
this.init()
}
// 初始化(给开始按钮绑定点击事件)
private init() {
console.log('Map.init')
this.bg.texture = RES.getRes('grid_jpg')
this.addChild(this.bg)
this.bg.touchEnabled = true
this.bg.addEventListener(egret.TouchEvent.TOUCH_BEGIN, this.onTouchTap, this)
this.touchEnabled = true
if (Store.isCatcher()) {
this.alpha = 0
this.addEventListener(egret.TouchEvent.TOUCH_BEGIN, this.onTouchTap, this)
}
}
private onTouchTap() {
console.log(this, this.parent)
if (Store.isCatcher()) {
console.log(this, this.parent)
// const map = SceneManager.getInstance().gameScene.map
this.parent.showSurroundedGrids(this.x, this.y)
}
}
public release() {
// 移除事件
}
}
\ No newline at end of file
......@@ -15,7 +15,7 @@ class SceneManager extends egret.DisplayObjectContainer {
this.roomScene = new RoomScene();
this.gameScene = new GameScene();
// 默认添加开始场景
this.addChild(this.roomScene);
this.addChild(this.gameScene);
}
// 实例化单例获取方法
public static getInstance(): SceneManager {
......
......@@ -31,6 +31,6 @@ class Store {
static isCatcher() {
return true
return _state.role === 'ghost'
// return _state.role === 'ghost'
}
}
\ No newline at end of file
......@@ -26,7 +26,7 @@ class GameScene extends egret.Sprite {
this.map.y = 15
this.me.y = 15
this.addChild(this.map)
this.addChild(this.me)
this.map.addChild(this.me)
}
private onPositionChange(delta){
......
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