Last active
November 6, 2018 09:19
-
-
Save Aermberry/f647eccbea2e0c87e19b1de6f333e356 to your computer and use it in GitHub Desktop.
egret
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Scene07 extends eui.Component implements eui.UIComponent { | |
private nextButton: eui.Button; | |
private pongLabel: eui.Label; | |
private pongLabel0: eui.Label; | |
private KongLabel: eui.Label; | |
private strongLabel: eui.Label | |
; | |
private DongLabel: eui.Label; | |
private DongLabel0: eui.Label; | |
private kongLebel: eui.Label; | |
private gongLabel: eui.Label; | |
private headerLabel: eui.Label; | |
private group00: eui.Group; | |
private redLineGroup: eui.Group; | |
private diplay: egret.tween.TweenGroup; | |
private arry: eui.Label[]; | |
private voiceList: string[] = ["08_pong_mp3", "08_pong_mp3", "08_kong_mp3", "08_strong_mp3", "08_dong_mp3", "08_dong_mp3", "08_kong_mp3", "08_gong_mp3"]; | |
public constructor() { | |
super(); | |
} | |
protected partAdded(partName: string, instance: any): void { | |
super.partAdded(partName, instance); | |
} | |
protected childrenCreated(): void { | |
super.childrenCreated(); | |
Base.onAsyncPlayBlackgroundMusic('08_startgame1a_mp3').then(() => { | |
this.changRedColor(this.pongLabel, this.pongLabel0, this.KongLabel, this.strongLabel, this.DongLabel, this.DongLabel0, this.kongLebel, this.gongLabel) | |
}); | |
this.diplay.play(0); | |
Base.onClickNextScene(this.nextButton, new Scene08()) | |
} | |
//changcolor&drawline | |
private async changRedColor(...restOfName: eui.Label[]): Promise<void> { | |
for (var i = 0; i < restOfName.length; i++) { | |
await lzlib.ThreadUtility.sleep(500); | |
restOfName[i].textColor = 0xd92e20; | |
restOfName[i].addEventListener(egret.TouchEvent.TOUCH_TAP, this.clickVoice.bind(this, this.voiceList[i]), this);// | |
(this.redLineGroup.$children[i] as eui.Label).visible = true; | |
} | |
this.playSound("08_startgame1b_mp3") | |
} | |
private async playSound(sound: string): Promise<void> { | |
this.headerLabel.visible = true; | |
await lzlib.SoundUtility.playSound(sound); | |
this.nextButton.visible = true; | |
} | |
private clickVoice(voice: string): void { | |
let current = voice; | |
var sound: egret.Sound = RES.getRes(current); | |
sound.play(0, 1); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Egret_Learning | |
## 第三方插件的引入与编译 | |
### egretProperties.json文件 | |
项目文件夹中有一个 **egretProperties.json** 文件,这个文件描述了当前项目的一些信息 | |
~~~javascript | |
{ | |
"engineVersion": "5.2.7", | |
"compilerVersion": "5.2.7", | |
"template": {}, | |
"target": { | |
"current": "web" | |
}, | |
"eui": { // UI 库 | |
"exmlRoot": [ | |
"resource/eui_skins" | |
], | |
"themes": [ | |
"resource/default.thm.json" | |
], | |
"exmlPublishPolicy": "commonjs" | |
}, | |
"modules": [ //modules 字段,这部分就是用来配置扩展模块和第三方库的 | |
{ | |
"name": "egret" | |
}, | |
{ | |
"name": "eui" | |
}, | |
{ | |
"name": "assetsmanager" | |
}, | |
{ | |
"name": "tween" | |
}, | |
{ | |
"name": "game" | |
}, | |
{ | |
"name": "promise" | |
}, | |
{ | |
"name": "mouse",//库名 | |
"path": "../egret-game-library-master/mouse/libsrc"//庫文件所在路徑 | |
}, | |
{ | |
"name": "lzlib",//库名 | |
"path": "../lzlib" //所在路径 | |
} | |
] | |
} | |
~~~ | |
在egretProperties.json文件填寫的文件路徑,會自動將庫文件添加到本地項目的lib中 | |
1.将第三方的库添加到libs文件夹下的modules文件夹下 | |
![Alt text](http://p9ut1e15i.bkt.clouddn.com/%E5%BA%93%E6%96%87%E4%BB%B6.png) | |
2.在egretProperties.json文件中注册第三方库名和所在的路径 | |
![Alt text](http://p9ut1e15i.bkt.clouddn.com/%E6%96%87%E4%BB%B6%E7%BB%93%E6%9E%84.png) | |
3.清除原有的编译文件,重新编译 | |
### 類名的更改與場景的對應關係 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ProGoScene extends eui.Component implements eui.UIComponent{ | |
private boomBtn:eui.Image; | |
private bgmSoundChannel:egret.SoundChannel; | |
private backBtn:eui.Image; | |
private proFactory:egret.MovieClipDataFactory; | |
private proMovieGroup:eui.Group; | |
private proMovieClip:egret.MovieClip; | |
public constructor(){ | |
super(); | |
} | |
protected childrenCreated():void | |
{ | |
super.childrenCreated(); | |
this.bgmSoundChannel = RES.getRes('select_difficulty_scene_bgm_mp3').play(0,-1); | |
mouse.enable(this.stage);//啓動鼠標手勢變化 | |
mouse.setButtonMode(this.boomBtn,true);//對boomBtn啓用手勢變化 | |
this.boomBtn.addEventListener(egret.TouchEvent.TOUCH_TAP, this.goEnterProGameScene, this); | |
this.boomBtn.addEventListener(mouse.MouseEvent.ROLL_OUT, ()=>this.boomBtn.source='black_boom_png', this); | |
this.boomBtn.addEventListener(mouse.MouseEvent.ROLL_OVER, ()=>this.boomBtn.source='red_boom_png', this); | |
this.backBtn.addEventListener(egret.TouchEvent.TOUCH_TAP, this.goStartScene, this); | |
this.proFactory = new egret.MovieClipDataFactory( RES.getRes('pro_go_scene_json') , RES.getRes('pro_go_scene_png')); | |
this.proMovieClip = new egret.MovieClip(this.proFactory.generateMovieClipData('pro_go_scene')); | |
this.proMovieGroup.addChild(this.proMovieClip); | |
this.proMovieClip.play(-1); | |
} | |
private goEnterProGameScene() { | |
this.bgmSoundChannel.stop(); | |
Main.instance.gotoScene(new PlayProGameScene()); | |
} | |
private goStartScene() { | |
this.bgmSoundChannel.stop(); | |
this.proMovieClip.stop(); | |
this.proMovieGroup.removeChild(this.proMovieClip); | |
Main.instance.gotoScene(new StartScene()); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Riddle6Scene extends eui.Component implements eui.UIComponent { | |
private bottle: eui.Image; | |
private umbrella: eui.Image; | |
private cash: eui.Image; | |
private isTrueImage: eui.Image; | |
private transparentBlock: eui.Rect; | |
private useGroup: eui.Group; | |
private bottleTipsGroup: eui.Group; | |
private moneyTipsGroup: eui.Group; | |
private useTipsGroup: eui.Group; | |
private goodsGroup: eui.Group; | |
public constructor() { | |
super(); | |
} | |
protected partAdded(partName: string, instance: any): void { | |
super.partAdded(partName, instance); | |
} | |
protected childrenCreated(): void { | |
super.childrenCreated(); | |
this.addshowTipsLabel(this.useGroup, this.useTipsGroup); | |
this.addshowTipsLabel(this.bottle, this.bottleTipsGroup); | |
this.addshowTipsLabel(this.cash, this.moneyTipsGroup); | |
this.isTrue(this.umbrella, this.isTrueImage); | |
} | |
public addshowTipsLabel( | |
object: eui.Group | eui.Image | eui.Button, | |
object2: eui.Group | eui.Image | eui.Button | |
): void { | |
object.addEventListener( | |
egret.TouchEvent.TOUCH_TAP, | |
() => { | |
this.showTipsLabel(object2); | |
}, | |
this | |
); | |
} | |
public async showTipsLabel( | |
object: eui.Group | eui.Image | eui.Button | |
): Promise<void> { | |
object.visible = true; | |
this.preventClick( | |
this.bottleTipsGroup, | |
this.moneyTipsGroup, | |
this.isTrueImage, | |
this.goodsGroup, | |
this.transparentBlock | |
); | |
await lzlib.ThreadUtility.sleep(5000); | |
object.visible = false; | |
} | |
public isTrue(btn: eui.Image | eui.Button, object: eui.Image) { | |
btn.addEventListener( | |
egret.TouchEvent.TOUCH_TAP, | |
() => { | |
this.isvisible(object); | |
}, | |
this | |
); | |
} | |
public async isvisible(object: eui.Image): Promise<void> { | |
object.visible = true; | |
await lzlib.ThreadUtility.sleep(1000); | |
object.visible && this.gotoNextScene(new StatueScene()); | |
} | |
public gotoNextScene(scene: eui.Component) { | |
Main.instance.gotoScene(scene); | |
} | |
private preventClick( | |
tips01Group: eui.Group, | |
tips02Group: eui.Group, | |
tips03: eui.Image, | |
optionGroup: eui.Group, | |
transparentBlock: eui.Rect | |
): void { | |
if (tips01Group.visible || tips02Group.visible || tips03.visible) { | |
const originIndex = optionGroup.getChildIndex(transparentBlock); | |
const currentIndex = optionGroup.$children.length - 1; | |
optionGroup.setChildIndex(transparentBlock, currentIndex); | |
setTimeout(() => { | |
optionGroup.setChildIndex(transparentBlock, originIndex); | |
}, 5000); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
str为要去除空格的字符串: | |
去除所有空格: | |
str = str.replace(/\s+/g, ""); | |
去除两头空格: | |
str = str.replace(/^\s+|\s+$/g, ""); | |
去除左空格: | |
str = str.replace(/^\s/, ''); | |
去除右空格: | |
str = str.replace(/(\s$)/g, ""); | |
SCRIPT LANGUAGE = "JavaScript" > | |
< | |
/SCRIPT> < | |
input type = "text" | |
value = " 前后都是空格 " | |
id = "space" > | |
< | |
input type = "button" | |
value = "去前后空格" | |
onclick = "javascript:document.getElementById('space').value=document.getElementById('space').value.Trim();document.getElementById('space').select();" > | |
< | |
input type = "button" | |
value = "去前空格" | |
onclick = "javascript:document.getElementById('space').value=document.getElementById('space').value.LTrim();document.getElementById('space').select();" > | |
< | |
input type = "button" | |
value = "去后空格" | |
onclick = "javascript:document.getElementById('space').value=document.getElementById('space').value.RTrim();document.getElementById('space').select();" > | |
< | |
input type = "button" | |
value = "还原" | |
onclick = "javascript:document.getElementById('space').value=' 前后都是空格 ';" > | |
< | |
a href = "http://www.yaoasnsi.com" | |
target = "_blank" > 访问yaosansi.com < /a> | |
去除所有空格: | |
str = str.replace(/\s+/g, ""); | |
去除两头空格: | |
str = str.replace(/^\s+|\s+$/g, ""); | |
去除空格(TimeSheet用过) | |
arg0 = arg0.replace(/\s+$|^\s+/g, ""); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Game01Scene extends eui.Component implements eui.UIComponent, GameView { | |
private tipsLineGroup: eui.Group; | |
private tipsDocumentGroup: eui.Group; | |
private DragGroup: eui.Group; | |
private DropGroup: eui.Group; | |
private nextButton: eui.Button; | |
private dropImage: eui.Image; | |
private Mask:eui.Rect; | |
private correctTipsLabel: eui.Label; | |
public constructor() { | |
super(); | |
} | |
protected partAdded(partName: string, instance: any): void { | |
super.partAdded(partName, instance); | |
} | |
protected childrenCreated(): void { | |
super.childrenCreated(); | |
// 啓用鼠標檢測 | |
mouse.enable(this.stage); | |
this.initDrag(); | |
this.nextButton.addEventListener(egret.TouchEvent.TOUCH_TAP,()=>this.gotoNextScene(new Game02Scene()),this); | |
} | |
public gotoNextScene(scene: eui.Component): void { | |
Main.instance.gotoScene(scene); | |
} | |
// Drag功能 | |
public initDrag(): void { | |
for (let children of this.DragGroup.$children) { | |
// 初始化實例化drag對象 | |
let drag = new lzlib.Drag(); | |
// 將drag對象添加到stage上 | |
this.stage.addChild(drag); | |
// drag對象對children啓用drag功能 | |
drag.enableDrag(children, false); | |
// 儅拖動到target範圍外時,觸發onDragCancel事件 | |
children.addEventListener(lzlib.LzDragEvent.CANCEL, this.onDragCancel, this); | |
} | |
this.initDropable(); | |
} | |
// Drop功能 | |
public initDropable(): void { | |
let drop = new lzlib.Drop(); | |
this.stage.addChild(drop); | |
drop.enableDrop(this.dropImage); | |
this.dropImage.addEventListener(lzlib.LzDragEvent.DROP, this.onLabelDrop, this); | |
} | |
// Drop配對功能 | |
public async onLabelDrop(e: lzlib.LzDragEvent): Promise<void> { | |
let targetComponent = this.dropImage.source | |
let dragComponent = (e.dragObject as eui.Image).source; | |
this.closeTipsLabel(); | |
if (targetComponent == dragComponent) { | |
e.preventDefault(); | |
this.dropImage.visible = true; | |
e.dragObject.visible = false; | |
this.correctTipsLabel.visible = true; | |
this.nextButton.visible = true; | |
this.closeTipsLabel(); | |
this.swapChildren(this.Mask,this.DragGroup); | |
} | |
else { | |
this.showTIpsLabel() | |
} | |
} | |
// Drop不配對功能 | |
public onDragCancel(): void { | |
this.showTIpsLabel(); | |
} | |
// 顯示提示 | |
public showTIpsLabel():void { | |
this.tipsLineGroup.visible = true; | |
this.tipsDocumentGroup.visible = true; | |
} | |
//關閉提示 | |
public closeTipsLabel():void { | |
this.tipsLineGroup.visible = false; | |
this.tipsDocumentGroup.visible = false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment