Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
GameMaker Programming By Example

You're reading from   GameMaker Programming By Example Master the development of 2D games by learning to use the powerful GameMaker Language and tools provided by the GameMaker: Studio workspace and engine!

Arrow left icon
Product type Paperback
Published in Dec 2015
Publisher
ISBN-13 9781785887963
Length 212 pages
Edition 1st Edition
Arrow right icon
Authors (2):
Arrow left icon
Brian Christian Brian Christian
Author Profile Icon Brian Christian
Brian Christian
Steven Isaacs Steven Isaacs
Author Profile Icon Steven Isaacs
Steven Isaacs
Arrow right icon
View More author details
Toc

The physics engine in a regular game


The remainder of this chapter will be a small tutorial on how to incorporate physics into a top-down style game, like our first one. We're just going to create a small engine to demonstrate how you would move around a player and get perfect collisions.

So first create a simple player sprite and wall sprite. They can be simple squares or complex shapes if you want. Make sure that you center the origins—it's important for the collisions to work properly.

Now create a player and wall object. Give the wall its sprite, a density of 0, and a collision shape. If you made the sprite complex (although walls are usually blocky), then select the Shape option and plot a series of points to get a collision shape that matches the wall and then open up the player object. Give the player its sprite and a collision shape. If the player's sprite is complex, then use the Shape option.

Now let's make the player move and stop at the wall. Add a Create event, and set phy_fixed_rotation...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €18.99/month. Cancel anytime