标签:业务逻辑 handle shp 坦克大战 href 加载 listener 大战 ble
用了几天开发游戏,现在回头整理下知识
首先附上源码,下载地址
http://www.521100.net/forum.php?mod=viewthread&tid=26&extra=page%3D1
1.Egret 主循环,用于实现业务逻辑更新游戏进度
egret.lifecycle.addLifecycleListener((context) => { context.onUpdate = () => { if(!this.init) { return; } if(this.player1) { this.player1.move(); } this.doEnemyAI(); this.handleBullet(); } })
2.碰撞检测
this.player1.hitTestPoint(bullet.x, bullet.y)
3.随机数的生成
public randomNum(minNum:number,maxNum:number){ switch(arguments.length){ case 1: return Math.random()*minNum+1; case 2: return Math.random()*(maxNum-minNum+1)+minNum; default: return 0; } }
4.点击事件处理
开启
bg.touchEnabled = true; bg.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onBgTouch, this);
处理方法
/* 响应背景的点击事件 */ private onBgTouch(e) { let x = e.stageX; let y = e.stageY; this.player1.targetX = parseInt(x); this.player1.targetY = parseInt(y) ; }
5.画一个图形,圆形
var shp:egret.Shape = new egret.Shape(); shp.graphics.beginFill( 0xffff00, 1); shp.graphics.drawCircle(0, 0, 5); shp.graphics.endFill(); this.addChild(shp);
6.加载一个图片
private createBitmapByName(name: string) { let result = new egret.Bitmap(); let texture: egret.Texture = RES.getRes(name); result.texture = texture; return result; }
标签:业务逻辑 handle shp 坦克大战 href 加载 listener 大战 ble
原文地址:https://www.cnblogs.com/woaitech/p/12242448.html