Book Update – 2018-09-01 – It’s taking shape

So I found an artist willing to collaborate with me on my GameMaker Studio 2 book. Thank God I can work with him once again! He’s the most talented Pixel Artist around. He knows about game development and the whole process and he can draw pretty much everything you throw at him.

I love this new graphics

I bet you can recognize his style! “Guess who’s back…” nudge nudge wink wink

What this means for the project

This will have a major impact over the whole project as the entire graphic assets will be distributed along the complete source code of the game. It will be freely modifiable and it will be freely available to be used in commercial projects as well as long as the original art credits will be included (you know, he remains the father of the original pixels).

You won’t be able to redistribute the graphics in reusable formats though. But this is to be expected. Your customers or your game’s players should not be able to export the graphics and re-use it for other projects. They will have to buy the book if they want to do so.

You’re also free to use the graphics for other game engines as well. You’re not restricted to GameMaker Studio 2… and to be honest some of the book’s concepts apply to other engines as well.

I’m rewriting the whole book from scratch and I hope to have the initial draft for review by December.

Video tutorials

The book will come with the complete development process on video. You’ll have free access to the complete development process. I’m recording everything I do and I will be editing it once the book is being finalized.

Like the idea? Support us

If you like the idea about what we’re doing here, please buy us a coffee. It will send us a strong support message. Also the more coffee, the more content we will be able to fit into the project in terms of both assets and development contents.

Buy Me a Coffee at ko-fi.com

Thank you!

P.S. just in case you didn’t get it, the artist is obviously Darftey!

Dark Titan – Battle Over Fire

So, in response to this hilarious tweet by Burrito Tim, I’m officially naming my 2D Sci-Fi Action Adventure Platformer, Dark Titan – Battle Over Fire!

Here it is in all its glory. Well… more or less…

I’ve added the energy pickup, the exploding blocks, the “bombable” blocks and enemy spawners that resets upon re-entering the zone. Also added Gamepad support. Next up:

  • refactoring and optimization
  • save slots
  • menus (main and option)
  • triggers
  • cutscenes
  • powerups
  • visual effects here and there

Updates as of 2018-08-22 – The Metroid-like project(s)

So I was working on a small Metroid-like game in GameMaker Studio 2. Then one day I thought: what if I wrote a book about how I made it? Maybe I could attach the whole GameMaker Studio 2 source project to the book. It might be useful to others and it might even pay some of my bills (and make me an author as a nice side effect).

Small gif of the project

And so I decided to write an ebook. I’m aiming for less than 200 pages but as of now I can’t be sure about that. There’s a lot to write about. But there’s one issue with this grandiose plan.

If I want to release the source project, I cannot use this graphics.

One thing I need to take care of, is the graphics. I took the graphics from another project I bought on the Scirra store (the Construct software developers) because:

  1. I thought I was just going to build a game in GMS2 and release it
  2. I loved this graphics
  3. I asked the authors and they told me the Construct project could be dissected to be re-purposed in GameMaker Studio 2 as long as I didn’t redistribute the graphics in any reusable way.

So it’s still ok to use that graphics for a complete game but it’s not ok for me to redistribute it in a reusable way (i.e. I can’t sell/give away the source code with that graphics). Which is expected, reasonable and correct.

In short, as soon as I will finish the game (using that graphics), I will need to re-make the whole project with either more permissive-licensed assets or with brand new graphics (made specifically for the book project).

I’m inclined to hire an artist and make brand new graphics but we’ll see how it all pans out.

I’ll post more updates soon.

P.S. The doors/hatches graphics I’m using is made by Luis Zuno aka ansimuz. His Warped Caves asset pack can be downloaded for free. Check his Patreon page as well as his Itch.io page. He makes lovely pixels.

Screen Tearing / Wavy Effect in GameMaker Studio 2 (using Surfaces)

After playing Environmental Station Alpha, I decided I wanted to implement the screen tearing effect Hempuli is using in his game. I didn’t know how he achieved it so I had to start from scratch and think about different approaches.

Knowing nothing about shaders, I was left with surfaces. I jotted down some code and immediately hit a wall; after asking around in the yoyogames forums, reading other’s comments, I could finally come up with a pretty decent solution.

Actual Code

I wrote the code so it could be easily hackable. This goes into the create event of your game controller object.
// handy shorter names
dw = display_get_width()
dh = display_get_height()

tearings_surface  	= surface_create(dw, dh)    // We'll draw on this surface
tearings_y          = 0
band_num            = 16                        // How many bands you want on screen
band_height         = dh / band_num
tearings_x_offset   = 32                        // How much you want to displace the bands horizontally
tearing_speed       = 4                       	// Change this to speed up/slow down the tearings
I place the following code inside a draw_post event of my controller.
// Create surface if it doesn't exits
if !surface_exists(tearings_surface)
	tearings_surface = surface_create(display_get_width(), display_get_height())
	
// Let's set the target to our surface
surface_set_target(tearings_surface)
draw_clear_alpha(c_black, 0)

// We draw parts of our application surface on tearings surface
for (var current_band = 0; current_band < band_num * 2; current_band++)
{
	draw_surface_part(application_surface, 0, band_height * current_band - tearings_y, dw, band_height, sin( (degtorad(360) / band_num ) * current_band) * tearings_x_offset , band_height * current_band - tearings_y)
}

// Always reset the target surface
surface_reset_target()

// Draw the actual surface
draw_surface_stretched(tearings_surface, -tearings_x_offset, 0, dw + tearings_x_offset * 2, dh)

// Move the Tearings
tearings_y = (tearings_y + tearing_speed) % (band_height * band_num)

That's it.

And this is how I make that effect. I will implement a similar version for vertical tearings (for underwater levels? maybe?). Hope you find it useful.

A note about surfaces: remember to free the surfaces if you don’t need them anymore, otherwise it will lead to memory leaks.

Guide to develop low resolution 2D platformers with smooth movement and pixel perfect collisions in GameMaker Studio 2 (with slopes)

Low resolution is great. It saves CPU power, especially with the collision code I talk about in this article, and it makes it easier to work with the project (like when building huge rooms or making edits to sprites). You’ll see that sometimes there’s little to no reason to scale up your sprites. It’s just a waste of resources.

With the collision code I use objects move by whole pixels. This makes for perfect collisions but it usually leads to jittery movements. Luckily there’s a simple solution.

The Movement and Collision Code

This is the most practical collision code I ever came across on the web. I read about it some time ago on Zack Bell‘s blog and I subsequently adapted it slightly to suit my needs. It basically remains the go-to code for 2D low res platformers. It’s like… unbeatable. Think holy grail of platformer movement and collision.

I’m using the following hierarchy.

 obj_solid
  |
  |_ obj_slope
|_obj_slope_rx
|_obj_slope_lx

You can use a different hierarchy for your collisions, just adapt the scr_platformer_move code. I’m using fall through platforms so I use the obj_solid_top.

This script must be called from the create event of your active/moving objects.

/// @desc       Initialize Platformer Vars
/// @func       scr_platformer_init()

/// This script is usually called in the create event

// Initialize the variables used for movement code
xVel = 0                // X Velocity
yVel = 0                // Y Velocity

xVelSub = 0             // X Sub-pixel movement
yVelSub = 0             // Y Sub-pixel movement

This code should run at the end of your movement velocities calculations. Ideally at the end of your object’s step event (normal step event is fine).

(open in pastebin)

Collision Masks

It’s of fundamental importance that you take extra care when dealing with collision masks. Make sure they behave the expected way especially when flipping your objects around. Most of the times the error lies in the origin or in the symmetry of a mask.

Wrong Collision Mask

Here’s a sample of a wrong collision mask. Counter intuitively I placed the origin in the exact middle of the mask. It will result in asymmetric mask behavior when mirroring it (i.e. when turning left or right in the game). This mask will create collision issues and probably get objects stuck inside walls or slopes. 

This mask is wrong.

Correct Collision Mask

It took me a while to understand how the origin pointer looks and behaves. This is a centered, symmetric collision mask… I’ll be honest: it absolutely doesn’t look like that to me. But trust me, this is the right one.

This mask is correct.

Let's fix the jittery movement!

It’s all about surfaces. We need to:

  1. Disable the automatic drawing of the application surface.
  2. Resize the application surface to the correct, hi resolution size.
  3. Draw our sprites with sub-pixel offsets.
  4. Draw the stretched application surface manually in a post_draw event.

Considerations

Can you see what’s going on here? Objects still move by whole pixels. Their collisions are still being calculated for whole numbers only. Still, we draw the sprites with sub-pixel precision!

The loops for collision checks have to run for very low numbers/distances. This means ultra-smooth movement, ultra high performances and very low disk/ram resource usage (compared to up-scaled pixel art).

Still jittery on slopes? Let's fix it

If you download the attached project you’ll see how I solved the slopes jittery movement. 

I’m using simple trigonometry to find the Y position given the X position on a slope. I’m still using whole pixels to compute collisions but I use the following snippet just to draw the sprite of the player.

// Check for slope offset
slope = collision_rectangle(bbox_left, bbox_bottom +1, bbox_right, bbox_bottom + 1, obj_slope, true, true)

if slope
{
    var slope_height    = abs(slope.bbox_bottom - slope.bbox_top)
    var slope_base      = abs(slope.bbox_right - slope.bbox_left)
    var angle           = arctan(slope_height / slope_base)

    // Slope to the right
    if object_is_ancestor(slope.object_index, obj_slope_rx)
    {
        if bbox_right < slope.bbox_right slope_spr_y = slope.bbox_bottom - (bbox_right + xVelSub - slope.bbox_left) * tan(angle) else slope_spr_y = slope.bbox_top } // Slope to the left else if object_is_ancestor(slope.object_index, obj_slope_lx) { if bbox_left > slope.bbox_left
            slope_spr_y = slope.bbox_top + (bbox_left + xVelSub - slope.bbox_left) * tan(angle)
        else
            slope_spr_y = slope.bbox_top
    }
}
else
    slope_spr_y = 0    // Not on slopes
And so in the draw event of the player I use the following:
// Slope Y Position
if (slope_spr_y != 0)
    var yspr = slope_spr_y
else
    var yspr = y + yVelSub

draw_sprite_ext(sprite_index, image_index, x + xVelSub, yspr, image_xscale, image_yscale, 0, c_white, image_alpha)

Conclusions

This system might not be perfect and I’m open to new solutions. Let me know if you have a better system to obtain smooth movements using low resolution assets.

A little update

Since I now have a full-time job, I removed my Patreon page and my silly “donations” form. I also ordered a brand new notebook; it’s ridiculously powerful so I can run GameMaker Studio 2 with no lag (and in Full HD resolution).

Lately I found myself willing to create content but the very same job that gave me financial freedom, is kind of keeping me from making progress on my own projects. I guess I should stop planning ahead and just go with the flow.

What’s next

Now that I have a full time job, I need to re-assess my priorities. Game development will always be a part of my life but in a lighter, brighter and smarter way. I’m focusing exclusively on my own projects while keeping an open approach for the future.

I have no immediate plans on releasing or developing commercial games. Right now I’m focusing on creating some content for this blog and for my Patreon channel. Maybe even my YouTube channel (but don’t hold your breath).

3 Platformer Engines

While developing Fuzeboy I learned a lot about platformer engines. I decided to share my knowledge with my Patrons so I’ll be creating three platformer engines, each one with a different level of complexity. Patrons will be able to download said engines and use them for any purpose, commercial or not, with or without crediting me; feel free to modify anything without my written consent. I basically give up any right I might have over them.

Basic Platformer Engine

This basic platformer engine will have all the characteristics of games such as the first Super Mario Bros. (8bit NES era). Basic platforming with no slopes, underwater physics, simple shooting mechanic, enemies with elementary AI, score points, basic health, basic powerups and maybe a couple of extra.

Intermediate Platformer Engine

While some characteristics will build upon the basic platformer, new problems will call for new approaches and a redesign of some game components. We’ll start using managers like the video manager, input manager and data manager. We’ll look at video scaling and we’ll add slopes and ladders. Also we introduce the 8-way shooting and the advanced animation system (the one I used in Fuzeboy). One way platforms, moving platforms and more.

Advanced Platformer Engine

This is a totally different engine. I’m thinking Super Metroid here. Powerups & inventory, room transitions, gamepad support and input customization, data saving and loading, complex world interactions, triggers, complex camera behavior, cutscenes, dialogues and much, much more.

GameMaker Studio 2 Courses

Just to reiterate that I’m not leaving game development altogether, I’m organizing GameMaker Studio 2 courses at my day job office. Right now we’re thinking about organizing classrooms for the locals but we might scale a bit and extend the offer to schools as well. This is something I’m making in real life so, no online courses for now (for those, look into Benjamin Anderson’s courses). So yeah, I’m also teaching GameMaker Studio 2.

The GameMaker Studio 2 Book

I was writing a book about making an Advanced Platformer Game in GameMaker Studio 2. Turns out making a book is way more complicated than making the game itself. For now I’m leaving this on the table but I won’t be actively working on it in the immediate future.

Kren – Deep Silence

Going back to my own projects and talking about long term plans, means going back to Kren. During the past months I developed a solid engine, written a sound storyline and found a group of people (all friends I know in person, in real life, here in Italy) interested in its development. We’re working weekends to draw concepts and storyboards but it won’t be until next January when I’ll be discussing and showing more substantial material. We take our time and we want to plan it well from start to finish, ironing out all the details.

That’s all for now

So that’s it. I’ll upload some new content soon.

Scaling up my game 4x without resizing a single sprite (GM:S 1.4)

So I was developing a low res game (480 x 270) in GameMaker: Studio 1.4. The moment comes when I need to test it on mobile. I create my APK, load it up on the phone and there it is… a horrible mess of graphic artifacts!

The camera movement was all jittery, the zoom effect made all the tiles look funny and overall it just felt wrong.

The problem was obviously the very low resolution of the game. The camera (the view), along with every other object in the game, can move only by whole “game pixels”. That means that if you divide the actual display resolution by the game resolution (480 horizontal pixels in my case) you get the minimum “screen pixels” that any object can be moved/re-drawn. No in-between values are possible.

This is actually hi-res. Just scaled up 4x (background still old-size) - 1 game pixel is now 1 view pixel. But sprites are 4x bigger so they look low-res (fake it).

On a 1920 pixels wide screen, that’s 4 “screen pixels” per “game pixel”. So the camera (along with every other objects) can move only by 4 screen pixels at once and no less. This means jittery movement.

Since I wanted the camera to be able to move at least 1/4th of a game pixel, I had to upscale the whole game by a factor of 4… I had to go Full HD to keep my low res game enjoyable.

That meant resizing 175 sprites, move their origins, check their collision masks, resize the tilesets and backgrounds, adjust the speeds, re-make the whole levels and probably fix other bugs… unless…

Unless I used this code in the room start event of my controller.

global.game_scale = 4


// Increase the room size
room_width  = room_width  * global.game_scale
room_height = room_height * global.game_scale

    
// Object resize
with(all)
{
    x = x * global.game_scale
    y = y * global.game_scale
    image_xscale = image_xscale * global.game_scale
    image_yscale = image_yscale * global.game_scale
}

// Tile resize
var num = tile_get_count();
for (var i = 0; i < num; i++;)
{
    var tid = tile_get_id(i)
    var tx  = tile_get_x(tid)
    var txs = tile_get_xscale(tid)
    var ty  = tile_get_y(tid)
    var tys = tile_get_yscale(tid)

    tile_set_scale(tid, global.game_scale, global.game_scale)
    tile_set_position(tid, tx * global.game_scale, ty * global.game_scale)
}

I also increased the view size by 4 (and resized the application surface accordingly) so the objects in the game looked exactly like before (size-wise). Now everything is 4 times bigger.

I still have to resize any in-game created instance and modify the speeds of some of my objects… but at least I didn’t have to resize 175 sprites. Now the camera moves and zooms smoothly. Everything can move 1/4th of a game pixel without looking jittery.

Separation of Concerns in GameMaker Studio

I recently got into the (bad) habit of using just one single controller object for my games. It manages everything from input to video. The logic behind this was that the less objects GameMaker has to manage, the less resources it will use.

In principle that’s true. In reality, switching from 5-6 controllers down to 1 doesn’t make any difference at all in terms of performance. We’re not talking about hundreds of objects; we’re talking about 6. I mean… what was I thinking?

So I took a step back and returned to my old (good) habit of having multiple, distinct, autonomous and self-contained controllers. Each concerned only with doing his own thing.

These are my controllers now.

I’ll admit it: the Game controller is still somewhat generic; all the others define their own variables and run their own code independently. Data deals with game data like options and statistics. Video deals with app surface drawing, display resolution managing and view/camera stuff. Audio and Input are pretty self-explanatory too.

Log deals with the log console, but it will soon become Dev. A Development controller that enables development mode actions and tools like a debug console, a log viewer and so on. When a game is released, the Dev controller must be simply removed from the first init room.

The added benefit is that now I can export a single object into any other project, where and when I need it. That’s neat.