Presentation is loading. Please wait.

Presentation is loading. Please wait.

Build your own 2D Game Engine and Create Great Web Games using HTML5, JavaScript, and WebGL. Sung, Pavleas, Arnez, and Pace, 2015. Chapter 4 Implementing.

Similar presentations


Presentation on theme: "Build your own 2D Game Engine and Create Great Web Games using HTML5, JavaScript, and WebGL. Sung, Pavleas, Arnez, and Pace, 2015. Chapter 4 Implementing."— Presentation transcript:

1 Build your own 2D Game Engine and Create Great Web Games using HTML5, JavaScript, and WebGL. Sung, Pavleas, Arnez, and Pace, 2015. Chapter 4 Implementing Common Components of Video Games

2 Ch 4: Common ComponentsBuild your own 2D Game Engine. Sung, Pavleas, Arnez, and Pace, 2015. 2 Game Loop Typical structure Notice: the input() update!

3 Ch 4: Common ComponentsBuild your own 2D Game Engine. Sung, Pavleas, Arnez, and Pace, 2015. 3 Game Loop: Implementation Input() inside vs outside of the real-time loop? Responsiveness when game is lagging Fixed update rate: Simple physics implementation (later in Chapter 9)

4 Ch 4: Common ComponentsBuild your own 2D Game Engine. Sung, Pavleas, Arnez, and Pace, 2015. 4 4.1: Game Loop Project New Engine component (similarity to gEngine.VertexBuffer!!)

5 Ch 4: Common ComponentsBuild your own 2D Game Engine. Sung, Pavleas, Arnez, and Pace, 2015. 5 _runLoop function requestAnimationFrame().call(class)  syntax! mIsLoopRunning not checked Will do so later No input() checking yet update() and draw() Separated!! No update in draw No draw in update!!

6 Ch 4: Common ComponentsBuild your own 2D Game Engine. Sung, Pavleas, Arnez, and Pace, 2015. 6 Trigger to start the loop Note the initializations

7 Ch 4: Common ComponentsBuild your own 2D Game Engine. Sung, Pavleas, Arnez, and Pace, 2015. 7 Starting the loop: MyGame.Initialize()

8 Ch 4: Common ComponentsBuild your own 2D Game Engine. Sung, Pavleas, Arnez, and Pace, 2015. 8 MyGame: update()

9 Ch 4: Common ComponentsBuild your own 2D Game Engine. Sung, Pavleas, Arnez, and Pace, 2015. 9 MyGame: draw()

10 Ch 4: Common ComponentsBuild your own 2D Game Engine. Sung, Pavleas, Arnez, and Pace, 2015. 10 4.2: Keyboard Input Events and event handlers HTML5 Event registration and handlers window.addEventListener(“Event”, handler) Keycodes: ‘A’ = xx ‘B’ = xx+1 …

11 Ch 4: Common ComponentsBuild your own 2D Game Engine. Sung, Pavleas, Arnez, and Pace, 2015. 11 The Engine.Input component

12 Ch 4: Common ComponentsBuild your own 2D Game Engine. Sung, Pavleas, Arnez, and Pace, 2015. 12 Input: variables for key states

13 Ch 4: Common ComponentsBuild your own 2D Game Engine. Sung, Pavleas, Arnez, and Pace, 2015. 13 Event handlers and initialization

14 Ch 4: Common ComponentsBuild your own 2D Game Engine. Sung, Pavleas, Arnez, and Pace, 2015. 14 Keyboard update() and support

15 Ch 4: Common ComponentsBuild your own 2D Game Engine. Sung, Pavleas, Arnez, and Pace, 2015. 15 Engine.Core: to init Input

16 Ch 4: Common ComponentsBuild your own 2D Game Engine. Sung, Pavleas, Arnez, and Pace, 2015. 16 Engine.Loop: to update input

17 Ch 4: Common ComponentsBuild your own 2D Game Engine. Sung, Pavleas, Arnez, and Pace, 2015. 17 Engine initialization (from MyGame)

18 Ch 4: Common ComponentsBuild your own 2D Game Engine. Sung, Pavleas, Arnez, and Pace, 2015. 18 Testing Keyboard input: MyGame.update()

19 Ch 4: Common ComponentsBuild your own 2D Game Engine. Sung, Pavleas, Arnez, and Pace, 2015. 19 Resource Management Synchronous load: Issue load and wait Stops web browser!! May seem “hang” to user Asynchronous load: Issue load, provide “Callback” and continue “Callback” is called when load is completed Pro: Efficient, support interactivity Con: Complex, requires synchronization

20 Ch 4: Common ComponentsBuild your own 2D Game Engine. Sung, Pavleas, Arnez, and Pace, 2015. 20 4.3: ResourceMap Project ResourceMap: Key-value pair of “string=id” and resource E.g., file name and content of file

21 Ch 4: Common ComponentsBuild your own 2D Game Engine. Sung, Pavleas, Arnez, and Pace, 2015. 21 ResourceMap: functions Load synchronization support Create/Store-to EntryMap Nothing else! Asset assessing support Check and retrieve Misc support (e.g., call back)

22 Ch 4: Common ComponentsBuild your own 2D Game Engine. Sung, Pavleas, Arnez, and Pace, 2015. 22 TextFileLoader: An Engine Component Working with ResourceMap isAssetLoaded(): Check before (re)-load! Call to: asyncLoadRequest() Filename (path) as ID onreadystatechange() Status report: next slide onLoad() When loaded: next slides

23 Ch 4: Common ComponentsBuild your own 2D Game Engine. Sung, Pavleas, Arnez, and Pace, 2015. 23 TextFileLoader: status check Status check!

24 Ch 4: Common ComponentsBuild your own 2D Game Engine. Sung, Pavleas, Arnez, and Pace, 2015. 24 TextFileLoader: onLoad() Successful loaded If loading XML Create DOMParser() If plain textfile Return the entire text source Work with ResourceMap asyncLoadCompleted()

25 Ch 4: Common ComponentsBuild your own 2D Game Engine. Sung, Pavleas, Arnez, and Pace, 2015. 25 Engine DefaultResoruces Notice SimpleShader is shared by all Renderables!! There will be many other examples Define DefaultResources engine component

26 Ch 4: Common ComponentsBuild your own 2D Game Engine. Sung, Pavleas, Arnez, and Pace, 2015. 26 Default SimpleShader engine resource

27 Ch 4: Common ComponentsBuild your own 2D Game Engine. Sung, Pavleas, Arnez, and Pace, 2015. 27 SimpleShader: user default resource

28 Ch 4: Common ComponentsBuild your own 2D Game Engine. Sung, Pavleas, Arnez, and Pace, 2015. 28 Engine: starting sequence Index.html Engine_Core.js

29 Ch 4: Common ComponentsBuild your own 2D Game Engine. Sung, Pavleas, Arnez, and Pace, 2015. 29 Testing async loading: MyGame No need to worry about initialization Game Engine Core (good!) MyGame Constructor simple again! Access shader from default resource

30 Ch 4: Common ComponentsBuild your own 2D Game Engine. Sung, Pavleas, Arnez, and Pace, 2015. 30 4.4: Scene File The “assets” folder A convention for ourselves (NOT defined by anything!!) XML format and parsing (not cover here)

31 Ch 4: Common ComponentsBuild your own 2D Game Engine. Sung, Pavleas, Arnez, and Pace, 2015. 31 MyGame class Constructor: declaring var and defining constants Game specific resources (assets) MAY NOT be there!! Initialize(): allocate and instantiate, setting up states Game specific resources are loaded!! update()/draw(): Seen this before … again: update(): DO NOT try to draw anything draw(): DO NOT make any changes to game state! loadScene()/unloadScene(): loading/unloading of scene specific information!!

32 Ch 4: Common ComponentsBuild your own 2D Game Engine. Sung, Pavleas, Arnez, and Pace, 2015. 32 MyGame: construct and load!

33 Ch 4: Common ComponentsBuild your own 2D Game Engine. Sung, Pavleas, Arnez, and Pace, 2015. 33 MyGame:initialize() Game specific resources are now loaded!!

34 Ch 4: Common ComponentsBuild your own 2D Game Engine. Sung, Pavleas, Arnez, and Pace, 2015. 34 Engine: starting sequence with new MyGame Index.html Engine_Core.js

35 Ch 4: Common ComponentsBuild your own 2D Game Engine. Sung, Pavleas, Arnez, and Pace, 2015. 35 Engine Core: startScene() Engine_Core.js Engine_Loop.js

36 Ch 4: Common ComponentsBuild your own 2D Game Engine. Sung, Pavleas, Arnez, and Pace, 2015. 36 4.5: Scene Objects Define GameEngine (Core and Loop) interface protocol with game developer (our API user) Abstract class for subclass by clients

37 Ch 4: Common ComponentsBuild your own 2D Game Engine. Sung, Pavleas, Arnez, and Pace, 2015. 37 Support for “sub-classing” Engine_Core.js

38 Ch 4: Common ComponentsBuild your own 2D Game Engine. Sung, Pavleas, Arnez, and Pace, 2015. 38 Game Loop: stop to unload resources Engine_Loop.js

39 Ch 4: Common ComponentsBuild your own 2D Game Engine. Sung, Pavleas, Arnez, and Pace, 2015. 39 Loading the next Scene …

40 Ch 4: Common ComponentsBuild your own 2D Game Engine. Sung, Pavleas, Arnez, and Pace, 2015. 40 4.6: Audio support Audio: files Just another example of external resource! Support for mp3 and wav formats HTML5: AudioContext Load/Decode audio resources Play audio resources!! Two important categories Audio as music: e.g., background Continuous playing, need control Audio as cue: Short, no need for control

41 Ch 4: Common ComponentsBuild your own 2D Game Engine. Sung, Pavleas, Arnez, and Pace, 2015. 41 Engine_AudioClip: Component

42 Ch 4: Common ComponentsBuild your own 2D Game Engine. Sung, Pavleas, Arnez, and Pace, 2015. 42 Loading of AudioClips Exact same structure as TextFile loader Work with ResourceMap isAssetLoaded() asyncLoadRequested() NEW: incAssetRefCount() In case loaded multiple times!! req.onLoad() … next slide

43 Ch 4: Common ComponentsBuild your own 2D Game Engine. Sung, Pavleas, Arnez, and Pace, 2015. 43 req.onLoad(): once loaded … Store the entire file content to ResourceMap asyncLoadCompleted()!

44 Ch 4: Common ComponentsBuild your own 2D Game Engine. Sung, Pavleas, Arnez, and Pace, 2015. 44 Audio as Cue Each Cue must be a separate file! Start and no more control!

45 Ch 4: Common ComponentsBuild your own 2D Game Engine. Sung, Pavleas, Arnez, and Pace, 2015. 45 Background music support Keep reference for future control


Download ppt "Build your own 2D Game Engine and Create Great Web Games using HTML5, JavaScript, and WebGL. Sung, Pavleas, Arnez, and Pace, 2015. Chapter 4 Implementing."

Similar presentations


Ads by Google