JavaScript Game Tutorial - 2D Tower Defense PART 2 @Frankslaboratory
JavaScript Game Tutorial - 2D Tower Defense PART 2  @Frankslaboratory
Uploaded February 2021 | Updated September 2026, 1 week ago
Let's add more features to our JavaScript game inspired by Plants vs Zombies. In this tutorial we will practice object oriented programming and use plain vanilla JavaScript and HTML canvas element to create 2D tower defense game. We will use different types of units, to defend our base against a variety of enemies, we will collect resources and fight boss battles. Have fun.

Relevant links:
JavaScript 2D Tower Defense PART 1: youtu.be/QxYg8-mhhhs
Sprite sheets and game graphics: mobilegamegraphics.com/product/alien-pixel
Temporary alternative sprite sheets in case the website is down:
Zombie sprite sheet: frankslaboratory.co.uk/downloads/zombie.png
Plant sprite sheet: frankslaboratory.co.uk/downloads/plant.png

Vanilla JavaScript Fish game (multiline sprite sheet animation)
PART1: youtu.be/jl29qI62XPg
PART2: youtu.be/MwTQtPGuBmo
This JavaScript tutorial is part of a series, for more game development check out this playlist youtube.com/playlist?list=PLYElE_rzEw_sowQGjRdvwh9eAEt62d_Eu

Timestamps:
0:00 Project overview
02:27 How to use JavaScript classes to create floating messages
17:02 How to prepare sprite sheets for our game
24:01 How to use draw image method for sprite animation
31:24 How to control frame rate separately for each sprite sheet
35:36 Animating towers (defenders)
43:00 How to allow player to switch between different units

Today we are building a game from scratch using vanilla JavaScript and HTML5 canvas element. I like strategic elements with tower defense games, choosing the right unit against specific enemy, knowing what combination of units to use against certain enemy compositions, it can get quite complex. Plant's vs zombies does this so well with their selection of 50 plus plants with different abilities and a wide range of enemies and interactive environmental elements. Today I would like to lay down groundwork for that in our game. We will allow player to choose between blue and pink defender. We will add sprite sheets, create floating status text and couple more things. I want this episode to be as beginner friendly as possible so I will just write the code in a simple readable way. I want this to be easy to follow along for beginners.

You can message me on TWITTER twitter.com/code_laboratory
Check out some of my source code on CODEPEN codepen.io/franksLaboratory

If you started with vanilla JavaScript and HTML5 canvas recently you might want to try some of the tutorials from beginner friendly projects playlist first: youtube.com/playlist?list=PLYElE_rzEw_v8TXJ_ITSSBP_ypUKfQ7K-

#frankslaboratory

The description of this video may contain affiliate links, which means that if you buy one of the products that I recommend, I'll receive a small commission without any additional cost for you. This helps to support the channel and allows me to continue making videos like this. Thank you for the support!
JavaScript Game Tutorial - 2D Tower Defense PART 2JavaScript project tutorial for beginners [HTML Canvas Particles]JavaScript RETRO Games: Super WeaponsCSS Animation Tutorial for Beginners [Animated Background Effect]JavaScript RETRO Games: Armored EnemiesHandling Audio & Art in JavaScript GamesJavaScript Game Development: One Codebase - Many 2D GamesHow To Code Flying Creatures with JavaScriptSprite Animation with pure CSS | How to animate any sprite sheet using just CSS3 and HTML propertiesAnimate Voice & Music with JavaScriptHTML5 Canvas Text Animation Tutorial [HTML, CSS, JavaScript]Collision Detection Between Rectangles in JavaScript
Franks laboratory |

JavaScript Game Tutorial - 2D Tower Defense PART 2

SHARE TO X SHARE TO REDDIT SHARE TO FACEBOOK WALLPAPER