Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Learn HTML5 by Creating Fun Games
Learn HTML5 by Creating Fun Games

Learn HTML5 by Creating Fun Games: Learning should be fun, especially when it comes to getting to grips with HTML5 Game Development. Each chapter of this book teaches a new concept for learning HTML5 by helping you develop a relevant game. It's education without the effort.

Arrow left icon
Profile Icon Rodrigo Silveira
Arrow right icon
R$50 per month
Full star icon Full star icon Full star icon Full star icon Full star icon 5 (1 Ratings)
Paperback Jun 2013 374 pages 1st Edition
eBook
R$49.99 R$245.99
Paperback
R$306.99
Subscription
Free Trial
Renews at R$50p/m
Arrow left icon
Profile Icon Rodrigo Silveira
Arrow right icon
R$50 per month
Full star icon Full star icon Full star icon Full star icon Full star icon 5 (1 Ratings)
Paperback Jun 2013 374 pages 1st Edition
eBook
R$49.99 R$245.99
Paperback
R$306.99
Subscription
Free Trial
Renews at R$50p/m
eBook
R$49.99 R$245.99
Paperback
R$306.99
Subscription
Free Trial
Renews at R$50p/m

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing
Table of content icon View table of contents Preview book icon Preview Book

Learn HTML5 by Creating Fun Games

Chapter 2. HTML5 Typography

Now that we have our environment set up, we're ready to take a deep dive into the actual code behind HTML5. This is where the book begins to take off, since no matter how much theory you learn, it's very difficult to master a programming language without some keyboard time.

The game we'll be developing in this chapter will be a typing game, with some emphasis in the typography aspect of it. Again, I remind you that the focus of this book is not to teach game development, but rather to teach you all about HTML5. Thus, the general approach we'll take to coding the games will not necessarily be most optimal for general game development, although all of the games covered in the book will perform fairly well in most major browsers.

The game


For lack of creativity, and to steer away from a possible lawsuit from a grumpy game company, we'll name this first game simply Typography Game. I know, that's not the most impressive game you've heard of, but at least it does a great job of explaining what the game is generally about.

The overall storyline for the game, as well as its general point, goes as follows: correctly type a phrase that is shown to you word-by-word, and win your dream boat. If you don't type each character correctly and fast enough then Snooty McSnootington wins the boat and you lose the game skills.

It's hard to convey all the details about this user interface from a single screenshot, but the waves in that beautiful ocean are actually very smoothly animated, as well as the boat, which floats freely and is tossed about by the waves. Also, although there are exactly six images in the entire game, all of the components used in this game are DOM elements. The boat, the waves, and the characters are done using...

Game elements


There were nine HTML5 elements used in this game. Each will be explained within its main category of either HTML, CSS, or JavaScript. The game itself is composed of roughly 15 elements, as depicted in the illustrations as follows:

The main game screen, with a subtle options widget as part of it.

After a game is finished, whether or not the player wins the game, a score board is shown, where the player is given the opportunity to enter his or her name as well as start a new game.

The preceding screenshot shows a messaging widget to indicate that the player has won or lost, as well as a leaderboard widget.

In order for us to easily identify each of the major visual game components, we'll list them as follows:

The options widget

This widget allows the player to select a preset difficulty level. Selecting a harder difficulty level will make the enemy move faster across his track towards the boat. Additionally, we could have made it so that the phrases that the player would need to type...

API usage


Now that we've discussed what all of the game elements are and how each HTML5 feature was used to fulfill that role, let's take a deeper look at how to make the most out of each of these APIs. For each of the following APIs, we'll provide a more concrete definition of the feature, what its intended use is, and a code example will follow. You may also refer to the complete source code attached at the end of the chapter in order to fill the gap between the code sample and how that feature fits in with the rest of the game code base. It is also recommended that you code along and play with the various settings and values in order to experiment with and more fully understand each API.

Web forms

The new HTML5 web forms API adds 13 new input types that allows for a much more flexible and powerful experience. What's more, web forms are also able to validate themselves requiring zero JavaScript intervention.

New input types

The following are the new input types defined in the new web forms...

The code


Now that you are familiar with the HTML5 APIs used in this fun game, let's look under the covers and see how the game was put together. Due to brevity and ease of explanation, only the main portions of the source code for this game will be listed or explained here. Be sure to download the complete source code for the game at the book's website.

The HTML structure

The first component of this game was the HTML structure. The main pieces of it are the tracks where each player moves, along with each individual player, and the containers that show the text that needs to be typed by the user. There is also a second container that displays whatever text the player actually types in. For customization, there is an input type range that allows the player to change the difficulty level of the game, which for all practical purposes, only increases the speed attribute of the enemy player.

<section class="tracks">
  <div class="track">
    <span data-name="badGuy" data-speed="0"...

Summary


In this chapter, we finally jumped off the spring board we set up in the previous chapter, and dove headfirst into the very deep world of HTML5 game development. We started out by setting up the project structure used in constructing this game and discussed the main goals and objectives of the game. Next, we looked at each of the components used in the game and discussed how and why they were used. Finally, we look a deeper look at each of the HTML5 APIs, that make up each of these components, and looked at some code examples to make them work.

Since the complete source code for the game is fairly lengthy, we only took a brief peek at the main structure of the code, so that when you download the full source from Packt's website, the code looks somewhat familiar to you. Again, I want to remind you that because the focus of this book is not game development but rather HTML5, the methods and techniques used to make this game may or may not be the most optimal approach to game development...

Left arrow icon Right arrow icon

Key benefits

  • Learn the basics of this emerging technology and have fun doing it
  • Unleash the new and exciting features and APIs of HTML5
  • Create responsive games that can be played on a browser and on a mobile device

Description

HTML is fast, secure, responsive, interactive, and stunningly beautiful. It lets you target the largest number of devices and browsers with the least amount of effort. Working with the latest technologies is always fun and with a rapidly growing mobile market, it is a new and exciting place to be."Learn HTML5 by Creating Fun Games" takes you through the journey of learning HTML5 right from setting up the environment to creating fully-functional games. It will help you explore the basics while you work through the whole book with the completion of each game."Learn HTML5 by Creating Fun Games" takes a very friendly approach to teaching fun, silly games for the purpose of giving you a thorough grounding in HTML5. The book has only as much theory as it has to, often in tip boxes, with most of the information explaining how to create HTML5 canvas games. You will be assisted with lots of simple steps with screenshots building towards silly but addictive games.The book introduces you to HTML5 by helping you understand the setup and the underlying environment. As you start building your first game that is a typography game, you understand the significance of elements used in game development such as input types, web forms, and so on.We will see how to write a modern browser-compatible code while creating a basic Jelly Wobbling Game. Each game introduces you to an advanced topic such as vector graphics, native audio manipulation, and dragging-and-dropping. In the later section of the book, you will see yourself developing the famous snake game using requestAnimationFrame along with the canvas API, and enhancing it further with web messaging, web storage, and local storage. The last game of this book, a 2D Space shooter game, will then help you understand mobile design considerations.

Who is this book for?

If you are are looking to get a good grounding in how to use the new awesome technology that is HTML5, this book is for you. Basic knowledge of HTML and/or HTML5 is welcome, but optional. The book is a friendly and exciting reference for beginners.

What you will learn

  • Understand why the open web is the best platform to develop for
  • Set up a local web development environment
  • Create DOM-based games such as a typography game using semantic HTML5 tags and CSS3 features
  • Use the new canvas element to create a 2D space shooter game
  • Discover writing portable code while developing a basic Jelly Wobbling Gravity Game
  • Create animations using RequestAninmationFrame while improvising the Snake game.
  • Make your games portable across desktop and mobile devices
  • Get started with WebGL for 3D game development, and with other upcoming HTML5 features and APIs

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Jun 25, 2013
Length: 374 pages
Edition : 1st
Language : English
ISBN-13 : 9781849696029
Languages :

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing

Product Details

Publication date : Jun 25, 2013
Length: 374 pages
Edition : 1st
Language : English
ISBN-13 : 9781849696029
Languages :

Packt Subscriptions

See our plans and pricing
Modal Close icon
R$50 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
R$500 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just R$25 each
Feature tick icon Exclusive print discounts
R$800 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just R$25 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total R$ 852.97
Learn HTML5 by Creating Fun Games
R$306.99
HTML5 Game Development Hotshot
R$272.99
HTML5 Web Application Development By Example : Beginner's guide
R$272.99
Total R$ 852.97 Stars icon
Banner background image

Table of Contents

7 Chapters
An Overview of HTML5 Chevron down icon Chevron up icon
HTML5 Typography Chevron down icon Chevron up icon
Understanding the Gravity of HTML5 Chevron down icon Chevron up icon
Using HTML5 to Catch a Snake Chevron down icon Chevron up icon
Improving the Snake Game Chevron down icon Chevron up icon
Adding Features to Your Game Chevron down icon Chevron up icon
HTML5 and Mobile Game Development Chevron down icon Chevron up icon

Customer reviews

Rating distribution
Full star icon Full star icon Full star icon Full star icon Full star icon 5
(1 Ratings)
5 star 100%
4 star 0%
3 star 0%
2 star 0%
1 star 0%
Formigone Nov 22, 2013
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Book covers basics of HTML5, as well as bleeding edge topics that you're not likely to find in any other book nowadays, such as CSS flows, CSS shaders, and the native NoSQL IndexDB database engine found inside modern browsers.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

What is included in a Packt subscription? Chevron down icon Chevron up icon

A subscription provides you with full access to view all Packt and licnesed content online, this includes exclusive access to Early Access titles. Depending on the tier chosen you can also earn credits and discounts to use for owning content

How can I cancel my subscription? Chevron down icon Chevron up icon

To cancel your subscription with us simply go to the account page - found in the top right of the page or at https://subscription.packtpub.com/my-account/subscription - From here you will see the ‘cancel subscription’ button in the grey box with your subscription information in.

What are credits? Chevron down icon Chevron up icon

Credits can be earned from reading 40 section of any title within the payment cycle - a month starting from the day of subscription payment. You also earn a Credit every month if you subscribe to our annual or 18 month plans. Credits can be used to buy books DRM free, the same way that you would pay for a book. Your credits can be found in the subscription homepage - subscription.packtpub.com - clicking on ‘the my’ library dropdown and selecting ‘credits’.

What happens if an Early Access Course is cancelled? Chevron down icon Chevron up icon

Projects are rarely cancelled, but sometimes it's unavoidable. If an Early Access course is cancelled or excessively delayed, you can exchange your purchase for another course. For further details, please contact us here.

Where can I send feedback about an Early Access title? Chevron down icon Chevron up icon

If you have any feedback about the product you're reading, or Early Access in general, then please fill out a contact form here and we'll make sure the feedback gets to the right team. 

Can I download the code files for Early Access titles? Chevron down icon Chevron up icon

We try to ensure that all books in Early Access have code available to use, download, and fork on GitHub. This helps us be more agile in the development of the book, and helps keep the often changing code base of new versions and new technologies as up to date as possible. Unfortunately, however, there will be rare cases when it is not possible for us to have downloadable code samples available until publication.

When we publish the book, the code files will also be available to download from the Packt website.

How accurate is the publication date? Chevron down icon Chevron up icon

The publication date is as accurate as we can be at any point in the project. Unfortunately, delays can happen. Often those delays are out of our control, such as changes to the technology code base or delays in the tech release. We do our best to give you an accurate estimate of the publication date at any given time, and as more chapters are delivered, the more accurate the delivery date will become.

How will I know when new chapters are ready? Chevron down icon Chevron up icon

We'll let you know every time there has been an update to a course that you've bought in Early Access. You'll get an email to let you know there has been a new chapter, or a change to a previous chapter. The new chapters are automatically added to your account, so you can also check back there any time you're ready and download or read them online.

I am a Packt subscriber, do I get Early Access? Chevron down icon Chevron up icon

Yes, all Early Access content is fully available through your subscription. You will need to have a paid for or active trial subscription in order to access all titles.

How is Early Access delivered? Chevron down icon Chevron up icon

Early Access is currently only available as a PDF or through our online reader. As we make changes or add new chapters, the files in your Packt account will be updated so you can download them again or view them online immediately.

How do I buy Early Access content? Chevron down icon Chevron up icon

Early Access is a way of us getting our content to you quicker, but the method of buying the Early Access course is still the same. Just find the course you want to buy, go through the check-out steps, and you’ll get a confirmation email from us with information and a link to the relevant Early Access courses.

What is Early Access? Chevron down icon Chevron up icon

Keeping up to date with the latest technology is difficult; new versions, new frameworks, new techniques. This feature gives you a head-start to our content, as it's being created. With Early Access you'll receive each chapter as it's written, and get regular updates throughout the product's development, as well as the final course as soon as it's ready.We created Early Access as a means of giving you the information you need, as soon as it's available. As we go through the process of developing a course, 99% of it can be ready but we can't publish until that last 1% falls in to place. Early Access helps to unlock the potential of our content early, to help you start your learning when you need it most. You not only get access to every chapter as it's delivered, edited, and updated, but you'll also get the finalized, DRM-free product to download in any format you want when it's published. As a member of Packt, you'll also be eligible for our exclusive offers, including a free course every day, and discounts on new and popular titles.