官术网_书友最值得收藏!

HTML5 and WebAssembly

In this chapter, we will show you how the C code we write to target WebAssembly comes together with HTML5, JavaScript, and CSS to create a web page. We will teach you how to create a new HTML shell file to be used by Emscripten in the creation of our WebAssembly app. We will discuss the Module object and how Emscripten uses it as an interface between our JavaScript and the WebAssembly module. We will show you how to call WebAssembly functions written in C from within JavaScript on our HTML page. We will also show you how to call JavaScript functions from our C code. We will discuss how to use CSS to improve the look of our web page. We will introduce you to the HTML5 Canvas element and show how it is possible to display images to the canvas from within JavaScript. We will briefly discuss moving those images around the canvas from our WebAssembly module. This chapter will give you an understanding of how everything works together and lays the foundation for other features we are developing for our WebAssembly applications.

Beginning with this chapter and continuing through the remainder of the book, you will need image and font files from the GitHub project to compile the examples. For this chapter, you will need the  /Chapter02/spaceship.png  image file from the project directory. Please download the project from the following URL:  https://github.com/PacktPublishing/Hands-On-Game-Development-with-WebAssembly .
I highly recommend working along as you read each section of this chapter. You may use your favorite code editor and the command line to follow along. Even though we have provided links to download the code directly, it cannot be emphasized enough how much you will learn by actually following edits suggested in this chapter. You are going to make mistakes and learn a lot from them. If you decide to work along, another suggestion is the following: do not proceed to the next section unless your edit/steps in the current section are successful. If you need help, contact me on twitter (@battagline).

In this chapter, we will cover the following topics:

  • The Emscripten minimal shell file
  • Creating a new HTML shell and C file
  • Defining our CSS
  • HTML5 and game development
  • Adding a canvas to the Emscripten template
主站蜘蛛池模板: 昔阳县| 恩施市| 仙游县| 南宁市| 西乌珠穆沁旗| 双城市| 贺州市| 平遥县| 罗田县| 天气| 福州市| 江津市| 永州市| 靖边县| 武邑县| 上虞市| 新野县| 津市市| 石河子市| 白山市| 青岛市| 竹山县| 湖口县| 青田县| 敖汉旗| 河曲县| 关岭| 丰顺县| 吉安县| 沂源县| 云和县| 江城| 东安县| 磐安县| 天气| 大足县| 闸北区| 永寿县| 颍上县| 咸阳市| 建阳市|