-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathDemoScript.ts
71 lines (56 loc) · 1.78 KB
/
DemoScript.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import { _decorator, Label, Component, game, log, AudioSource } from 'cc';
import { CCPokiSDK } from '../poki-api/PokiPlatform';
const { ccclass, property } = _decorator;
@ccclass('DemoScript')
export class DemoScript extends Component {
@property({type:Label})
outputLabel: Label
audioSource:AudioSource = null
start () {
game.on(CCPokiSDK.EVENT_REWARD_BREAK_DONE, this.onRewardBreakDone, this)
game.on(CCPokiSDK.EVENT_COMMERCIAL_BREAK_DONE, this.onCommercialBreakDone, this)
game.on(CCPokiSDK.EVENT_SHRABLE_URL_READY, this.onSharableLinkReady, this)
this.audioSource = this.getComponent(AudioSource)
}
onShareableLinkClicked(evnt){
CCPokiSDK.shareableURL({"difficulty":"easy", "lives":3})
}
onSharableLinkReady(){
const url = arguments[0]
log("SharableURL:", url)
this.outputLabel.string = url
}
onRewardBreakClicked(evnt){
//pause the game music.
this.audioSource.pause()
CCPokiSDK.gameplayStop()
CCPokiSDK.rewardBreak()
}
onRewardBreakDone(){
let success = arguments[0]
if(success){
this.outputLabel.string = "Reward video success."
log("Revive Player")
CCPokiSDK.gameplayStart()
}else{
log("Game End Screen")
}
//resume playing the background music.
this.audioSource.play()
}
onCommercialBreakClicked(evnt){
//pause the game music.
this.audioSource.pause()
CCPokiSDK.gameplayStop()
CCPokiSDK.commercialBreak()
}
onCommercialBreakDone(){
/**
* TODO:
* 1) Resume Game
* 2) Resume Music / Audio
*/
CCPokiSDK.gameplayStart()
this.audioSource.play()
}
}