Book description
Flash is fading fast as Canvas continues to climb. The second edition of this popular book gets you started with HTML5 Canvas by showing you how to build interactive multimedia applications. You’ll learn how to draw, render text, manipulate images, and create animation—all in the course of building an interactive web game throughout the book.
Updated for the latest implementations of Canvas and related HTML5 technologies, this edition includes clear and reusable code examples to help you quickly pick up the basics—whether you currently use Flash, Silverlight, or just HTML and JavaScript. Discover why HTML5 is the future of innovative web development.
- Create and modify 2D drawings, text, and bitmap images
- Use algorithms for math-based movement and physics interactions
- Incorporate and manipulate video, and add audio
- Build a basic framework for creating a variety of games
- Use bitmaps and tile sheets to develop animated game graphics
- Go mobile: build web apps and then modify them for iOS devices
- Explore ways to use Canvas for 3D and multiplayer game applications
Publisher resources
Table of contents
- HTML5 Canvas
- Dedication
- A Note Regarding Supplemental Files
- Preface
-
1. Introduction to HTML5 Canvas
- What Is HTML5?
- The Basic HTML5 Page
- Basic HTML We Will Use in This Book
- The Document Object Model (DOM) and Canvas
- JavaScript and Canvas
- HTML5 Canvas “Hello World!”
- Debugging with console.log
- The 2D Context and the Current State
- The HTML5 Canvas Object
- Another Example: Guess The Letter
- Hello World Animated Edition
- HTML5 Canvas and Accessibility: Sub Dom
- What’s Next?
-
2. Drawing on the Canvas
- The Basic File Setup for This Chapter
- The Basic Rectangle Shape
- The Canvas State
- Using Paths to Create Lines
- Advanced Path Methods
- Compositing on the Canvas
- Simple Canvas Transformations
- Filling Objects with Colors and Gradients
- Filling Shapes with Patterns
- Creating Shadows on Canvas Shapes
- Methods to Clear the Canvas
- Checking to See Whether a Point Is in the Current Path
- Drawing a Focus Ring
- What’s Next?
-
3. The HTML5 Canvas Text API
- Canvas Text and CSS
- Displaying Basic Text
- Setting the Text Font
- Text and the Canvas Context
- Text with Gradients and Patterns
- Width, Height, Scale, and toDataURL() Revisited
- Final Version of Text Arranger
- Animated Gradients
- The Future of Text on the Canvas
- What’s Next?
-
4. Images on the Canvas
- The Basic File Setup for This Chapter
- Image Basics
- Simple Cell-Based Sprite Animation
- Advanced Cell-Based Animation
- Applying Rotation Transformations to an Image
- Creating a Grid of Tiles
- Diving into Drawing Properties with a Large Image
- Pixel Manipulation
- Copying from One Canvas to Another
- Using Pixel Data to Detect Object Collisions
- What’s Next?
-
5. Math, Physics, and Animation
- Moving in a Straight Line
- Bouncing Off Walls
- Curve and Circular Movement
- Simple Gravity, Elasticity, and Friction
- Easing
- Box2D and the Canvas
- Interactivity with Box2D
- Box2D Further Reading
- What’s Next?
-
6. Mixing HTML5 Video and Canvas
- HTML5 Video Support
- Converting Video Formats
- Basic HTML5 Video Implementation
- Preloading Video in JavaScript
- Video and the Canvas
- Video on the Canvas Examples
- Animation Revisited: Moving Videos
- Capturing Video with JavaScript
- Video and Mobile
- What’s Next?
-
7. Working with Audio
- The Basic <audio> Tag
- Audio Formats
- Audio Tag Properties, Functions, and Events
- Playing a Sound with No Audio Tag
- Creating a Canvas Audio Player
- Case Study in Audio: Space Raiders Game
- Web Audio API
- What’s Next?
-
8. Canvas Games: Part I
- Why Games in HTML5?
- Our Basic Game HTML5 File
- Our Game’s Design
- Game Graphics: Drawing with Paths
- Animating on the Canvas
- Applying Transformations to Game Graphics
- Game Graphic Transformations
- Game Object Physics and Animation
- A Basic Game Framework
- Putting It All Together
- The Player Object
- Geo Blaster Game Algorithms
- The Geo Blaster Basic Full Source
- Rock Object Prototype
- Simple A* Path Finding on a Tile Grid
- What’s Next?
-
9. Canvas Games: Part II
- Geo Blaster Extended
- Creating a Dynamic Tile Sheet at Runtime
-
A Simple Tile-Based Game
- Micro Tank Maze Description
- The Tile Sheet for Our Game
- The Playfield
- The Player
- The Enemy
- The Goal
- The Explosions
-
Turn-Based Game Flow and the State Machine
- GAME_STATE_INIT
- GAME_STATE_WAIT_FOR_LOAD
- GAME_STATE_TITLE
- GAME_STATE_NEW_GAME
- GAME_STATE_WAIT_FOR_PLAYER_MOVE
- GAME_STATE_ANIMATE_PLAYER
- GAME_STATE_EVALUATE_PLAYER_MOVE
- GAME_STATE_ENEMY_MOVE
- GAME_STATE_ANIMATE_ENEMY
- GAME_STATE_EVALUATE_ENEMY_MOVE
- GAME_STATE_EVALUATE_OUTCOME
- GAME_STATE_ANIMATE_EXPLODE
- GAME_STATE_CHECK_FOR_GAME_OVER
- GAME_STATE_PLAYER_WIN
- GAME_STATE_PLAYER_LOSE
- Simple Tile Movement Logic Overview
- Rendering Logic Overview
- Simple Homegrown AI Overview
- Micro Tank Maze Complete Game Code
-
Scrolling a Tile-Based World
- First, a Tile Sheet That Contains the Tiles We Want to Paint to the Screen
- Second, a Two-Dimensional Array to Describe Our Game World
- Third, Paint the Tile-Based World to the Canvas
- Coarse Scrolling vs. Fine Scrolling
- The Camera Object
- The World Object
- Fine Scrolling the Row and Column Buffers
- Coarse Scrolling Full Code Example
- Fine Scrolling Full Code Example
- What’s Next?
- 10. Going Mobile!
-
11. Further Explorations
- 3D with WebGL
- Multiplayer Applications with ElectroServer 5
- Creating a Simple Object Framework for the Canvas
- Windows 8 Apps and the HTML5 Canvas
- What’s Next in HTML5.1 and Canvas Level 2?
- Conclusion
- A. Full Code Listings
- Index
- About the Authors
- Colophon
- Copyright
Product information
- Title: HTML5 Canvas, 2nd Edition
- Author(s):
- Release date: April 2013
- Publisher(s): O'Reilly Media, Inc.
- ISBN: 9781449335878
You might also like
book
HTML5 Canvas
No matter what platform or tools you use, the HTML5 revolution will soon change the way …
book
HTML5 Canvas Cookbook
Over 80 recipes to revolutionize the Web experience with HTML5 Canvas with this book and ebook …
video
HTML5 Canvas for Developers
Learn how to use the HTML5 Canvas element and related HTML5 capabilities such as video and …
book
Core HTML5 Canvas: Graphics, Animation, and Game Development
One of HTML5’s most exciting features, Canvas provides a powerful 2D graphics API that lets you …