DEV Community

Cover image for Ruby2d: Take your first steps toward animation and game design
Whiting
Whiting

Posted on

Ruby2d: Take your first steps toward animation and game design

With a quick Google search into how modern video games are developed, you'll likely stumble upon the powerful gaming engines behind industry-leading games like World of Warcraft or Call of Duty. These engines give the developers the tools they need to create games with complex physics, sophisticated visual processing powerful performance.

If, like most early developers, you're not ready to develop a complex, 3-dimensional interface, Ruby2d might be a good place to start.

Ruby2d

What is Ruby2d? Ruby 2d is a gem that can be installed into any Rubyist's environment to so that 2d apps can be written and run from one simple script. Ruby2d comes with predefined classes that allow for a variety of shapes, animations, and user interactions.

"...creating 2D applications should be simple, natural, and joyful, in the spirit of the Ruby language itself" (ruby2d on Github).

Get started

As per ruby2d documentation, to get started, simply install the ruby gem and require 'ruby2d' in your ruby file. For your first app, they recommend simply rendering a rainbow triangle on screen.

set title: "Hello Triangle"

Triangle.new(
  x1: 320, y1:  50,
  x2: 540, y2: 430,
  x3: 100, y3: 430,
  color: ['red', 'green', 'blue']
)

show
Enter fullscreen mode Exit fullscreen mode

In your command line, run ruby triangle.rb, and
voila! You've created a 2d app.

Alt Text

Predefined Classes

Spend some time exploring some of the classes available to you with the ruby2d gem. There are more than just triangles!

Ruby gives you the ability to integrate text, audio, images, user input, and sprite animations. In no time, you'll be building your own games, like this Rubyist's ruby2d-coded version of snake.

Alt Text

I recommend you explore the documentation and start tinkering with what ruby2d makes available. With the power of the ruby2d gem, you can build classic games in only a few lines of code. Go for it!

Resources

Top comments (0)