File tree 11 files changed +5140
-0
lines changed
11 files changed +5140
-0
lines changed Original file line number Diff line number Diff line change
1
+ node_modules
2
+ .parcel-cache
3
+ dist
Original file line number Diff line number Diff line change
1
+ import Phaser from 'phaser'
2
+
3
+ import { PokiPlugin } from '../lib'
4
+
5
+ import LoadingScene from './scenes/loading'
6
+
7
+ const config = {
8
+ parent : 'game' ,
9
+ backgroundColor : '#f0f5fc' ,
10
+
11
+ plugins : {
12
+ global : [
13
+ {
14
+ key : 'poki' ,
15
+ plugin : PokiPlugin ,
16
+ start : true ,
17
+ data : {
18
+ loadingScene : 'LoadingScene' ,
19
+ gameplayScene : 'PlayScene' ,
20
+ autoCommercialBreak : true
21
+ }
22
+ }
23
+ ]
24
+ }
25
+ }
26
+
27
+ export default class Game extends Phaser . Game {
28
+ start ( ) {
29
+ super . start ( )
30
+ this . input . keyboard . addCapture ( 'SPACE' ) // to prevent the page from scrolling
31
+
32
+ this . scene . add ( 'LoadingScene' , LoadingScene , true )
33
+ }
34
+ }
35
+
36
+ document . addEventListener ( 'DOMContentLoaded' , ( ) => {
37
+ new Game ( config )
38
+ } )
Original file line number Diff line number Diff line change
1
+ <!DOCTYPE html>
2
+ < html lang ="en ">
3
+ < head >
4
+ < meta charset ="UTF-8 ">
5
+ < meta http-equiv ="X-UA-Compatible " content ="IE=edge ">
6
+ < meta name ="viewport " content ="width=device-width, initial-scale=1.0 ">
7
+ < title > Example</ title >
8
+ </ head >
9
+ < body >
10
+ < div id ="game "> </ div >
11
+ < script src ="./game.js " type ="module "> </ script >
12
+ </ body >
13
+ </ html >
Original file line number Diff line number Diff line change
1
+ import Phaser from 'phaser'
2
+
3
+ import PlayScene from './play'
4
+
5
+ export default class LoadingScene extends Phaser . Scene {
6
+ create ( ) {
7
+ this . load . image ( 'logo' , 'textures/logo.png' )
8
+
9
+ this . load . once ( 'complete' , ( ) => {
10
+ console . log ( 'Loading complete' )
11
+
12
+ this . scene . add ( 'PlayScene' , PlayScene , false )
13
+ this . scene . start ( 'PlayScene' )
14
+ } )
15
+
16
+ this . load . start ( )
17
+ }
18
+ }
Original file line number Diff line number Diff line change
1
+ import Phaser from 'phaser'
2
+
3
+ export default class PlayScene extends Phaser . Scene {
4
+ create ( ) {
5
+ this . logo = this . add . image ( 100 , 100 , 'logo' )
6
+ this . logo . setScale ( 0.2 )
7
+ }
8
+
9
+ update ( time , delta ) {
10
+ this . logo . x = 640 + Math . cos ( time / 1000 ) * 100
11
+ }
12
+ }
Original file line number Diff line number Diff line change
1
+ export * from './poki'
Original file line number Diff line number Diff line change
1
+ import Phaser from 'phaser'
2
+
3
+ export class PokiPlugin extends Phaser . Plugins . BasePlugin {
4
+ init ( data ) {
5
+ console . log ( 'injecting Poki SDK' )
6
+ this . loadingScene = data . loadingScene
7
+ this . gameplayScene = data . gameplayScene
8
+ this . autoCommercialBreak = data . autoCommercialBreak
9
+
10
+ const script = document . createElement ( 'script' )
11
+ script . setAttribute ( 'crossOrigin' , 'anonymous' )
12
+ script . setAttribute ( 'type' , 'text/javascript' )
13
+ script . setAttribute ( 'src' , 'https://game-cdn.poki.com/scripts/v2/poki-sdk.js' )
14
+ script . addEventListener ( 'load' , ( ) => {
15
+ console . log ( 'PokiSDK loaded' )
16
+ this . sdk = window . PokiSDK
17
+ this . sdk . setDebug ( true )
18
+ // this.sdk.init()
19
+ } )
20
+ script . addEventListener ( 'error' , ( e ) => {
21
+ console . error ( 'failed to load PokiSDK' , e )
22
+ } )
23
+ document . head . appendChild ( script )
24
+ }
25
+
26
+ start ( ) {
27
+ console . log ( 'start' )
28
+
29
+ // When is loading started?
30
+ }
31
+
32
+ stop ( ) {
33
+ console . log ( 'stop' )
34
+ }
35
+ }
Original file line number Diff line number Diff line change
1
+ {
2
+ "name" : " phaser-plugin" ,
3
+ "version" : " 0.0.1" ,
4
+ "main" : " lib/index.js" ,
5
+ "license" : " ISC" ,
6
+ "private" : true ,
7
+ "scripts" : {
8
+ "start" : " parcel ./example/index.html"
9
+ },
10
+ "devDependencies" : {
11
+ "parcel" : " ^2.0.0-rc.0"
12
+ },
13
+ "dependencies" : {
14
+ "phaser" : " ^3.55.2"
15
+ }
16
+ }
You can’t perform that action at this time.
0 commit comments