An old-school arcade-style 3D shoot-em-up rendered entirely with CSS 3D transforms

Overview

CSS Space Shooter

Screen shot

Play The Game

This is an experiment I made to investigate the capabilities of CSS 3D transforms. Having played about with this technology a little (see this or this, and having seen some very impressive demos (CSS FPS, CSS X-Wing, I wanted to explore the idea of making a simple 3D game with only DOM and CSS.

Everything in CSS? Cool!

CSS transforms allow us to position and rotate DOM elements in 3D space. The big advantage of this over, say, using canvas or webGL is that we do not need to worry about any of the complex maths involved in projecting a 3D object onto the screen. The browser's rendering engine (with the help of your GPU) will take care of all that. You just need to specify the x, y, z coordinates as well as the rotation along any axis. This makes it really simple to map your JavaScript objects onto the screen, by just keeping track of these simple coordinate and rotation values.

Having previously played with pseudo-3D in canvas, I have some idea of the massive amount of calculation involved in plotting all the lines and vertices of each object manually. In this regard, the simple, declarative nature of CSS allows some really powerful 3D effects with astonishingly little code.

...or not so cool.

That convenience comes at a cost, however. For one, in CSS it is really really hard to create any shape other than a rectangle or an ellipse. Triangles, for example, are only possible through dirty hacks with the border property.

Secondly, performance. Despite hardware acceleration for these 3D transforms, I quickly ran into performance issues when scaling up the number of objects interacting on screen simultaneously. Certain CSS operations are also very expensive, such as transitioning box-shadow values or gradient backgrounds.

I'm sure my code can be optimized and this performance ceiling can be raised considerably. However, I wouldn't recommend using CSS and DOM for a serious 3D game.

Browser Compatibility

  • Right now this works properly in the latest version of Chrome.
  • In my tests with Firefox it is very jerky and then usually grinds to a complete halt after a minute or so.
  • Internet Explorer has a couple of fatal issues - it does not yet support a key CSS property - transform-style: preserve3d - which is essential to this method of building up 3D objects and 3D scenes which all share the same perspective. Additionally, IE does not currently support the Web Audio API, which I use for the sound effects and music. The game currently won't even load for this latter reason.
  • I've not tested in any other browsers, but feedback is welcome.

Credits

Inspiration and implementation details:

  • Keith Clark - seriously, check out his stuff. It's amazing. Used his advice on positioning the DOM elements in the center of the viewport and moving them only with transforms, which works well.
  • html5Rocks - Some really helpful tutorials here and here on how to use the Web Audio API.
  • Dive Into HTML5 article on the localStorage API, which I use to store high scores.

Sound effects

I got all my sounds effects from https://www.freesound.org.

Music

Ludwig van Beethoven - Symphony No.7 in A major op.92 - II, Allegretto

Developing

npm install
npm run watch // dev mode 
npm run compile // production build

License

MIT

You might also like...

A slideshow that uses a CSS glitch effect for slide transitions.

A slideshow that uses a CSS glitch effect for slide transitions.

Glitch Slideshow A slideshow that uses the CSS Glitch Effect to transition between slides. Article on Codrops Demo Credits Images by Unsplash.com imag

Dec 16, 2022

Some ideas for modern multi-layer page transitions using CSS Animations.

Multi-Layer Page Reveal Effects Some ideas for modern multi-layer page transitions using CSS Animations. Article on Codrops Demo Sponsor Demo sponsore

Nov 1, 2022

Pure CSS (no JavaScript) implementation of Android Material design "ripple" animation

Pure CSS (no JavaScript) implementation of Android Material design

Pure CSS ripple effect (no JavaScript) CSS-only implementation of Android Material design "ripple" animation on click event Main advantage of this sol

Dec 11, 2022

CSS loading animations with minimal effort!

Whirl CSS loading animations with minimal effort! whirl is a curation of CSS loading animations(whirls! 😅 ). It started as a drop in CSS file to get

Jan 4, 2023

🔮 CSS loading animations made by single element.

Three Dots The project is a set of CSS loading animations created with three dots which made by just single element. I think the project can not only

Dec 29, 2022

Pure css cross-browser loading animations.

[ArtWorx] xLoader Pure css cross-browser loading animations. xLoader is part of the ArtWorx collection. Most of the loaders made by community, You can

Nov 15, 2021

Animatelo is a bunch of cool, fun, and cross-browser animations for you to use in your projects. This is a porting to Web Animation API of the fabulous animate.css project.

Animatelo Just-add-water Web Animations Animatelo is a bunch of cool, fun, and cross-browser animations for you to use in your projects. Great for emp

Nov 12, 2022

Flappy Bird is an arcade-style game in which the player controls the bird Faby, which moves persistently to the right

Flappy Bird is an arcade-style game in which the player controls the bird Faby, which moves persistently to the right

Flappy Bird is an arcade-style game in which the player controls the bird Faby, which moves persistently to the right. The player is tasked with navigating Faby through pairs of pipes that have equally sized gaps placed at random heights. Faby automatically descends and only ascends when the player taps the touchscreen.

Aug 16, 2022

A system for sharing tests between students. In RepoProvas anyone can look up old tests for their subjects and teachers or send old tests to help other students!

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: np

May 10, 2022

A utility that mutates and transforms a style-dictionary object into something Figma Tokens plugin understands

A utility that mutates and transforms a style-dictionary object into something Figma Tokens plugin understands

Brought to you by Style Dictionary To Figma A utility that transforms a style-dictionary object into something Figma Tokens plugin understands. Used b

Jan 4, 2023

This extensions adds blocks to help you create your own carnival games in MakeCode Arcade using throwable balls, extra timer functions, and extra game-over options.

Usage This extensions adds blocks to help you create your own carnival games in MakeCode Arcade using throwable balls, extra timer functions, and extr

Nov 16, 2022

This is our second school project in HTML 5, CSS 3 and JS. In this website you can find very interesting information about the countries around the world.

This is our second school project in HTML 5, CSS 3 and JS. In this website you can find very interesting information about the countries around the world.

Team Geonomy 💻 About This is a website about with interatcive map and very interesting information about different coutries 🗂️ Used technologies Use

Nov 23, 2022

:package: Introduction to CSS 3D transforms

Intro to CSS 3D transforms By David DeSandro 3dtransforms.desandro.com Tutorial, examples, and discussion all about CSS 3D transforms. Originally writ

Jan 2, 2023

A PostCSS plugin that transforms `css var` to `less var`.

PostCSS CSS var to Less var A PostCSS plugin to convert CSS variables to Less variables Installation npm install postcss-transform-css-var Examples /

Nov 28, 2022

A library of icons rendered purely in CSS and compiled using SASS.

Welcome to PureIcons.css: This is a library of icons rendered purely in CSS and compiled using SASSs. It is currently at 79 icons. More will be added

Apr 27, 2021

A library for panning and zooming elements using CSS transforms :mag:

Panzoom Examples Panzoom is a small library (~3.7kb gzipped) to add panning and zooming functionality to an element. Rather than using absolute positi

Dec 26, 2022

A web app build with HTML, CSS, and JavaScript. It allow users to add a book title and and it's author. Content are rendered also dynamically.

Awesome books: with ES6 Description the project. Built With Major languages Frameworks Technologies used Awesome Books In this project the featured se

Nov 4, 2022
Comments
  • Inverted controls

    Inverted controls

    First off all, great job on this cool mini game! Personally, I find the controls totally counter-intuitive. It feels like a kind of flight sim where I expect the down arrow to pull up, not the other way around.

    opened by bubblefoil 1
  • iOS ?

    iOS ?

    Hi, thats amazing ! Congrats !

    I'm looking for a way to make this work on iOS,

    Do you think there is any possibility to add any script to display some arrows and the fire button in a overlay at the bottom of the screen from your experience ?

    Thanks and good continuation !

    opened by tibewww 0
Owner
Michael Bromley
I am a programmer. Here are some of my projects.
Michael Bromley
Only 90's kids remember... well not really, but these beloved effects that would follow your mouse around will always be classic reminders of the old, beloved internet.

90's Cursor Effects "Knowing the codes" used to be all the rage, I want to bring a few back. A repo of the old effects that inspired creativity and th

Tim Holman 2.6k Jan 9, 2023
The incredible effect of rain of letters in the style of the Matrix trilogy.

O Efeito Matrix O incrível efeito da chuva de letras no estilo da trilogia Matrix. "Cedo ou tarde, você vai aprender, assim como eu aprendi, que exist

Jeferson Lucas 138 Dec 12, 2022
Recreation of the background scale hover effect seen on the DDD Hotel website using CSS clip paths.

Background Scale Hover Effect Recreation of the background scale hover effect seen on the DDD Hotel menu using CSS clip paths. Article on Codrops Demo

Codrops 98 Dec 6, 2022
.qube -- The Quintessential Responsive 3D CSS Cube

.qube Quintessential Responsive 3D CSS Cube Created by @zacharyjohnson — zachstronaut.com Hello web friend! The styles defined in "src/qube.css" provi

Zachary Johnson 63 Dec 17, 2022
CSS 3D Dropdown Concept

Makisu An experimental CSS 3D dropdown concept, wrapped up in a jQuery plugin. Check out the demo (you'll need a CSS 3D capable browser, such as Chrom

Justin Windle 1.5k Nov 28, 2022
3D (animated) cube using only CSS (Less), originally used by LeanCloud (aka. AVOS Cloud)

cube.less 3D (animated) cube using only CSS (LESS). Demo See this demo page. There's also a live production site (WIP) using these cubes. Install $ bo

Tunghsiao Liu 54 Nov 14, 2022
Pure CSS animated 3D Super Mario Icon

Pure CSS Super Mario This is the transferred source of a little sideproject I did in 2010. I initially did this without any CSS preprocessor and event

Andreas Jacob 14 Apr 15, 2021
CSS 3D renderer for Three.js.

CSS3D.js by Steven Wittens CSS 3D renderer for Three.js Note: this library is mostly obsolete now that Three.js has its own CSS 3D renderer which is i

null 365 Aug 27, 2022
sync CSS 3D transformations to a WebGL scene

gl-css3d Synchronize CSS 3D transformations to a WebGL scene Usage: var createCSS3D = require('gl-css3d'); // pass an HTML DOM element node, such as

null 30 Oct 17, 2022
Pure CSS Image Hover Effect Library

imagehover.css A Scaleable & Light Image Hover CSS Library Imagehover.css is a lovingly crafted CSS library allowing you to easily implement scaleable

Ciaran Walsh 1.8k Dec 21, 2022