Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1410899 Posts in 69594 Topics- by 58581 Members - Latest Member: elpoeprod

October 09, 2024, 05:27:44 PM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsCommunityTownhallForum IssuesArchived subforums (read only)TutorialsGame Maker Tuts
Pages: [1] 2 3 ... 24
Print
Author Topic: Game Maker Tuts  (Read 371048 times)
ChevyRay
Guest
« on: October 06, 2008, 04:15:51 PM »

Note: Most of the tutorials linked in this post were written for older versions of Game Maker and might not work in GM Studio. If a particular piece of code is returning an error message, check Yoyo Games' official list of obsolete functions first.



Alright Game Maker users! Here I try to keep updated with the latest Game Maker related tutorials and links handy around TIG.



Game Maker For Beginners: I
Game Maker For Beginners: II
Game Maker For Beginners: III
Game Maker For Beginners: IV

Quote from: Derek
Having played with Game Maker for awhile, I have to say, I'm pretty impressed.  I can see why so many people use it!  And I'd like to see more.  I think it's a great way to make games and to learn how to make games.  It puts you in the right frame of mind to move on to "real programming" if you ever wanted to.

That said, the official tutorials for Game Maker aren't very good.  So let's try to make a better one!



Seamless View-Scaling in GM (*OBSOLETE*)

Quote from: ChevyRay
This is a tutorial how to get around using GM's built-in screen-scaling, which has an often undesired blur-effect when scaling up. An alternate method was to scale the view-port dimensions to scale the view. The problem with the view-port method is that it causes ugly seams to appear in your graphics when displayed on certain machines.



Surfaces in Game Maker Tutorial

Quote from: ChevyRay
I wrote a Game Maker tutorial awhile back that explained how to use Game Maker's Surfaces to scale the view without getting blurry results or strange tiling problems. Since then, I've probably gotten an email every week from somebody who has run into issues and errors using the scripts. I've come to realize that this is because a general lack of knowledge on how Surfaces work in Game Maker, and what is actually happening when you use them. So I'm writing this tutorial to clear these things up!



Speed Optimizations

Quote from: Derek
Since I'm a pretty mediocre programmer, I often go for an easy solution to my coding problems rather than an efficient one.  Game Maker is kind of notorious for being slow anyway, so it didn't take long for me to hit its limits.  But with a little research, and some good advice from experienced GM users, I started to make some optimizations to my game that significantly increased its speed.  And now I pass that knowledge down to you!



Grandma: GM Platformer Engine

Quote from: Matt Thorson
So I decided to finally start doing something about all the emails I receive asking how to make a platformer engine in Game Maker.



Fix for Room-Change Keyboard State Bug

Quote from: Christoffer
First, how do I get the engine to recheck keys when I'm starting a new room. Because as it is right now it takes a while before it actually reacts to keys that are being held in between rooms.



Walking Behind/In Front of Obstacles

Quote from: Dr.Salt
This is probably a really simple fix, but it couldn't hurt to ask.
I'm having trouble with depth. This little picture should illustrate the problem.




Displaying Numbers With 0s

Quote from: JasonPickering
Okay so hear is a question I have. How do I make it so a number is displayed as 0003 instead of 3.



Bare-Bones Typewriter Text

Quote from: caiys
After wanting some typewriter text for my game (so the text gradually appears one letter at a time) I did some searching for a tutorial and quickly found every example I came across was encased in a bunch of RPG 'extras' such as dialogue boxes and multiple answers. All I wanted was the bare-bones and after a bit of trial and error it turns out it's pretty damn easy.



Object-Based Parallax Scrolling

Quote from: caiys
What's the best way to do parallax scrolling in a platformer made in Gamemaker?
« Last Edit: March 08, 2014, 03:03:36 AM by C.A. Sinner » Logged
ஒழுக்கின்மை (Paul Eres)
Level 10
*****


Also known as रिंकू.


View Profile WWW
« Reply #1 on: October 06, 2008, 04:42:42 PM »

Wow, coincidentally we were just talking about that topic in one of the secret forums. Weird.
Logged

Xion
Pixelhead
Level 10
******



View Profile WWW
« Reply #2 on: October 06, 2008, 06:22:52 PM »

I look very forward to this  Grin
Logged

ChevyRay
Guest
« Reply #3 on: October 06, 2008, 07:01:23 PM »

Seamless Screen-Scaling
Game Maker


This is a tutorial how to get around using GM's built-in screen-scaling, which has an often undesired blur-effect when scaling up. An alternate method was to scale the view-port dimensions to scale the view. The problem with the view-port method is that it causes ugly seams to appear in your graphics when displayed on certain machines.

Thus, we're going to use the surface-method. The good thing about this method is you can apply it to your game easily, because none of your drawing events or anything need to be changed. You just have to make one persistent object at the beginning of the game, be consistent with your scaling, and you're set.

With this method, we will be changing the view-ports as well. This is a sure-fire method, because if the graphics card doesn't support surfaces, it'll automatically revert to using the view-port method, which is better than nothing, right?

So here we go.

STEP 1: Choose the scale you want. Use a view for every room and have the port W and port H scaled appropriately. So, for example, if you were using a scale of 2... it would look like this, in GM's room editor.



It is important that this is consistent for all rooms. If you have lots of rooms, it might be easier to do this via code*. I prefer to do it that way, because then the values aren't constant and I can support multiple different scales.

STEP 2: Create 3 scripts, screen_init, screen_begin, and screen_end. Here is what goes in each of the scripts...

Quote from: screen_init
// screen base(view_wview and view_hview)
screen_x = 0;
screen_y = 0;
screen_w = 320;
screen_h = 240;
screen_scale = 2;

// create a surface for the whole screen to be drawn on
screen = surface_create(screen_w,screen_h);

// this will destroy the screen object if surfaces are not supported on the graphics card, reverting to the viewport method
if screen = -1{instance_destroy();}

Quote from: screen_begin
// this draws the surface on the screen
surface_reset_target();
draw_clear(0);
draw_set_blend_mode_ext(bm_one, bm_zero);
draw_surface_stretched(screen,screen_x,screen_y,screen_w*screen_scale,screen_h*screen_scale);
draw_set_blend_mode(bm_normal);
screen_refresh();

Quote from: screen_end
// this sets surface 'screen' as the drawing target for everything in the game, so all drawing will be done on this surface and not on the game screen
surface_set_target(screen);

STEP 3: Now we have are scripts, but where do they go? Create an object. Like, obj_screen, objScreen, o_screen, or whatever, and do the following:

A) place the screen_initscript in the Create event.
B) place the screen_begin script in the Begin Step event.
C) place the screen_end script in the End Step event.

And place that object in the first and foremost room of your game, mark it persistent, and make sure there are no duplicates of it.

 You're done, and now have nice, crisp scaling Smiley



TIPS:

*Here's how I defined all my rooms in Skullpogo. Instead of going through every room in the game and setting its view dimensions, I just defined it all here in one neat little piece of code at the beginning of the game (right after the screen_init script, actually, because you need to use variables defined in it).

Quote
var w,h;
w=240*screen_scale;
h=320*screen_scale;
room_set_view(rmSplash,0,true,0,0,240,320,0,0,w,h,0,0,0,0,noone);
room_set_view(rmIntro,0,true,0,320,240,320,0,0,w,h,0,0,0,0,noone);
room_set_view(rmGame,0,true,0,0,240,320,0,0,w,h,0,0,0,0,noone);
room_set_view(rmHelp,0,true,0,0,240,320,0,0,w,h,0,0,0,0,noone);
room_set_view(rmScore,0,true,0,0,240,320,0,0,w,h,0,0,0,0,noone);
room_set_view(rmEnd,0,true,0,0,240,320,0,0,w,h,0,0,0,0,noone);

Things to note about doing it this way:

1) Advantage: because if you decide to change your game's scale, you can do it by just changing the screen_scale value. One little number change and its all done.

2) Foresight: what if you want to have the user choose between multiple game scales? Well, you could have the player choose the scale value at the beginning of the game, and then call this script to set all the rooms. Actually that's exactly what I did in Skullpogo.

3) WARNING: You'll notice that I used room_set_view because it can change the view settings in other rooms. Don't change the view port for the room you're in, the results won't be pleasant. I did this all from an INIT room at the beginning of the game, the room itself which doesn't have any view specifications. So make sure this isn't called from any of the rooms that are being altered.

4) Possibilities! Now your whole screen is drawn on a single surface, which can be moved, rotated, stretched, cut up, or manipulated as you please. The latest I made was an effect where the screen spins away into the background, and I took out the draw_blank(0) for the effect, so the screen leaves behind images as it whirls away in the transition. You can also change the color of the screen, save it to external files, darken/lighten it, or even apply screen filters (which I've also covered with my Retro Remakes project).

~*~

So if you got that working, here's a side project for you. Notice that in screen_init, I defined variables for screen_x and screen_y. But so far, they've just sat at zero and don't do anything. With this, you could create a little function that "jumps" that x and y value around a bit, giving the screen a "shaking" effect, and at the end of the effect snapping them back to zero. Or, you could have the screen slide off one side of the screen as a sort of transition.

~*~

Anyhow, enjoy folks. I'm currently working on an advanced GML library/extension called DeftScreen which will be used to handle a bunch of screen, scaling, and view effects and functions with ease. So that'll go here when it's done, too.

Questions can be PMed to me, posted here, or emailed to me ([email protected]). I'm always glad to help.

ChevyRay
« Last Edit: October 26, 2010, 11:08:18 AM by ChevyRay » Logged
Hideous
That's cool.
Level 10
*****


3D models are the best


View Profile WWW
« Reply #4 on: October 07, 2008, 12:14:17 AM »

How about a basic game maker tutorial? I've always hated the ones on yoyogames, and they don't really help me understand anything.
Logged

medieval
Guest
« Reply #5 on: October 07, 2008, 01:26:25 AM »

This helped me out. So much.
Logged
Melly
Level 10
*****


This is how being from "da hood" is like, right?


View Profile
« Reply #6 on: October 07, 2008, 04:27:38 AM »

How about a basic game maker tutorial? I've always hated the ones on yoyogames, and they don't really help me understand anything.

I would do it if I could use Game Maker anymore.
Logged

Feel free to disregard the above.
Games: Minus / Action Escape Kitty
___
Vice President of Marketing, Romeo Pie Software
Level 10
*


View Profile
« Reply #7 on: October 07, 2008, 06:40:50 AM »

Make a tutorial that doesn't make the lower left pixel of every sprite the transparent color.  Sad
Logged
medieval
Guest
« Reply #8 on: October 07, 2008, 07:33:56 AM »

Make a tutorial that doesn't make the lower left pixel of every sprite the transparent color.  Sad
There isn't a short or easy way to do it; you're going to have to use alpha masks for that.

sprite_set_alpha_from_sprite(sprite,mask)
Logged
___
Vice President of Marketing, Romeo Pie Software
Level 10
*


View Profile
« Reply #9 on: October 07, 2008, 08:10:25 AM »

Make a tutorial that doesn't make the lower left pixel of every sprite the transparent color.  Sad
There isn't a short or easy way to do it; you're going to have to use alpha masks for that.

sprite_set_alpha_from_sprite(sprite,mask)

You're an alpha mask.

I mean... thanks.
Logged
ChevyRay
Guest
« Reply #10 on: October 07, 2008, 11:40:54 AM »

Yeah, it's strange that GM does its own transparency handling, and can't use transparency inherent in an image. Unless they're external, though, then I think it can actually pick up transparency values (just from PNG, though? Not sure.)

In The Courts of CandleBre, everything is antialiased, so I created sprite masks for everything, i load them all up, set the transparency from the mask, and then free the masks from memory. Works alright, if you really don't mind the extra work. And external images.

But yeah.
Logged
moi
Level 10
*****


DILF SANTA


View Profile WWW
« Reply #11 on: October 07, 2008, 11:47:11 AM »

GM can't use alpha?
Logged

subsystems   subsystems   subsystems
Hideous
That's cool.
Level 10
*****


3D models are the best


View Profile WWW
« Reply #12 on: October 07, 2008, 11:56:57 AM »

Registered version can, partly.
Logged

TeeGee
Level 10
*****


Huh?


View Profile WWW
« Reply #13 on: October 07, 2008, 11:59:14 AM »

It does use alpha from .pngs or separate alpha masks. You just can't contain .pngs within the executable (and I don't know why would you ever want to do it anyway).
Logged

Tom Grochowiak
MoaCube | Twitter | Facebook
Derek
Bastich
Administrator
Level 10
******



View Profile WWW
« Reply #14 on: October 07, 2008, 02:31:09 PM »

Thanks, Chevy!  This is a good tut! Beer!

One other possible solution to the seam problem is to add

Code:
x = ceil(x);
y = ceil(y);

in the End Step of every object that is showing seams.  Maybe Carnivac can confirm this method, since he was the one who suggested this on YoYoGames!
Logged
ChevyRay
Guest
« Reply #15 on: October 07, 2008, 02:53:02 PM »

I can confirm, actually. I help him with his games so I have his source files. Smiley

Actually, that's a little heftier, because then you're making two calculations every step of the game for every object calling the function in the room. It's not THAT hefty, but I like to think ahead. Also, what it does is makes it so that game maker doesn't try to draw something off the pixel-grid, in some cases which it will either draw it distorted a bit, or when scaled (as said) it'll create seams.

And instead of ceil, use div. Like, create a script called align or adjust and use this:

Code: ( adjust() )

x = x div 1;
y = y div 1;


That will floor the values, and is less system costly. Also, I'd warn against this because you're changing values in real time, so you might end up with collision problems depending on how you programmed your collisions.


What I usually do is just have anything that moves use a draw_self or draw_self_ext script in the draw event, that looks like this:

Code: ( draw_self() )

draw_sprite(sprite_index,-1,x div 1,y div 1);


You'd use this one if the object had alpha, scaling, blending, or rotating.

Code: ( draw_self_ext() )
draw_sprite_ext(sprite_index,-1,x div 1,y div 1,
image_xscale,image_yscale,image_angle,image_blend,image_alpha);


So when you call those scripts from the draw event, it'll keep the object's x and y values as decimals, but draw them pixel-perfect with no seams. This is better if you use friction, in my opinion, for movement and collision systems.

Also, this are useful if you want to get a seamless value you can create a function...

Code: ( seam(value) )

return argument0 div 1;


So if you were moving something, you could go...

Code:

x = seam(x + horiz_speed);
y = seam(y + vert_speed);


or drawing something...

Code:

draw_background(bg_trees, seam(trees_x), seam(trees_y));

« Last Edit: October 07, 2008, 03:01:47 PM by ChevyRay » Logged
ஒழுக்கின்மை (Paul Eres)
Level 10
*****


Also known as रिंकू.


View Profile WWW
« Reply #16 on: October 07, 2008, 03:04:21 PM »

I think this tutorial as you've written it has a problem (although you may have mentioned it) -- what if the player uses surfaces? I.e. if they change the surface target themselves elsewhere in the game, it might interfere with all drawing going to this surface. So they'd have to be sure to reset it to the drawing surface each time.
Logged

ChevyRay
Guest
« Reply #17 on: October 07, 2008, 03:41:59 PM »

I assumed someone who uses surfaces already knows how to accomplish this anyway. But you're right.

The tutorial was mostly for less advanced use. If other surfaces are being used, it's a bit of a different story.
Logged
ஒழுக்கின்மை (Paul Eres)
Level 10
*****


Also known as रिंकू.


View Profile WWW
« Reply #18 on: October 07, 2008, 04:13:17 PM »

Well, there are probably lots of people who know how to use surfaces who didn't work this method out yet (including me). I'm not sure I personally have use for this though, for one reason: my game is by default 640x480, so doubling that to 1280x960 or something is probably large than many screens can handle. Do you know if this method would work as well for partial scale levels, like 1.5x, or would it only look good in whole number scaling (2x, 3x, etc.)?
Logged

ChevyRay
Guest
« Reply #19 on: October 07, 2008, 04:28:35 PM »

Well, there are probably lots of people who know how to use surfaces who didn't work this method out yet (including me). I'm not sure I personally have use for this though, for one reason: my game is by default 640x480, so doubling that to 1280x960 or something is probably large than many screens can handle. Do you know if this method would work as well for partial scale levels, like 1.5x, or would it only look good in whole number scaling (2x, 3x, etc.)?
It depends on the game. If you're looking to show off pixels, chances are it won't look good. Scaling to non-integer values usually causes some strange distortions in GM. But yeah, you can use any value you want and the code should work, provided the view-ports are being multiplied as well. Like, 320x240 scaled to .5 would just half it. You could even use it to have a mini-view inset of something else going on elsewhere in the game. This is actually what I'm doing in The Courts of CandleBre.
Logged
Pages: [1] 2 3 ... 24
Print
Jump to:  

Theme orange-lt created by panic