Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - lawatson

Pages: 1 ... 7 8 9 10 11 12 13 14 15 16 [17] 18 19 20 21 22 23 24 25
241
Game Design / For Dummies: Gamemaker Surfaces
« on: June 28, 2015, 04:50:41 PM »
If you're looking at this, that either means that you want to learn how to use surfaces because it sounds interesting, or you just got linked here on accident or something.

A surface in gamemaker is basically a drawing canvas. Just like the game screen, you can draw things on this surface. The difference between surfaces and the game surface is that you can manipulate surfaces in a wide variety of ways while not affecting the game screen. Surfaces are insanely useful in terms of graphics, as they are used for the most complex things like proper lighting engines, screen effects, and even get used in some fangames! (Remember Signore's purple warp?)

So now we know what a surface is, but obviously we're not just here to hear just that. That'd be dumb as crap, so now I'll talk you through the steps of making a surface, drawing to the surface, and manipulating it! Awesome, right? Let's do this.

What we're going to do is make an object which makes each fourth of the screen wave around while also having different colors drawn to each fourth.

Step 1: Making an object for the surface.

Super simple. We'll make an object so that we can define the surface and do all those cool things with it. The recommended qualities for the object are:

Title: oSurfaceWaveScreen
Sprite: No Sprite (We're not gonna be involving a sprite with the surface.)
Visible=1 (We've gotta make the effect visible, right?)
Solid=0
Depth=-100 (The surface will appear over most of the objects on the screen by doing this.)
Persistent=0
Parent: No Parent
Mask: Same As Sprite / No Mask

Step 2: Defining the events and actions.

Create Event:

surf=surface_create(800,608);

//End Of Code

What this does is define the variable "surf" as a newly created surface with a width of 800 and a height of 608.



Room End and Destroy Events:

surface_free(surf);

//End Of Code

What this does is it frees the "surf" surface from the RAM so that we don't end up having another "surf" surface floating around uselessly whenever the game restarts or the room ends.



Step Event:

if !surface_exists(surf){
    surf=surface_create(800,608);
}
surface_set_target(surf);
visible=0;
with(GAMEOVER)visible=0;
screen_redraw();
with(GAMEOVER)visible=1;
visible=1;
surface_reset_target();

//End Of Code

Alright, so now this'll probably seem odd and confusing, so I'll walk you through it.
The reason for this part:

if !surface_exists(surf){
    surf=surface_create(800,608);
}

Is because surfaces are stored in RAM. Normally they'll stay there, but there's always an odd chance that they'll leak out of the memory. In order to make sure that we're always drawing on a surface that exists, we use this code to assure that the "surf" surface exists.

The function surface_set_target() is what sets the surface you'll draw on. If we don't want to draw on the game surface and instead on the "surf" surface, we use this code to make that change.

Now onto the next lines in the code.

visible=0;
with(GAMEOVER)visible=0;
screen_redraw();
with(GAMEOVER)visible=1;
visible=1;

This is confusing for a variety of reasons, but I'll make sure you understand it at its fullest. Basically, it makes the surface invisible, makes the GAMEOVER object invisible, and then redraws the screen. Why this is amazing is because what we're doing isn't actually drawing it on the game surface. We're redrawing the whole entire screen...On the "surf" surface! Since we've copied the screen, we can make the GAMEOVER object visible again and make the surface visible again. That's the reason for this code.

The surface_reset_target() function works almost exactly like the surface_set_target code, but all it does is switches the drawing surface back to the game surface.



Draw Event:

draw_set_color(c_black);
draw_rectangle(0,0,800,608,0);
if surface_exists(surf){
    r+=2;
    for (i=0;i<4;i+=1){
    switch i{
        case 0:
            col=make_color_rgb(255,255,0);
        break;
        case 1:
            col=make_color_rgb(0,255,255);
        break;
        case 2:
            col=make_color_rgb(255,0,255);
        break;
        case 3:
            col=c_white;
        break;
    }
    draw_surface_part_ext(surf,i*200,0,200,608,i*200,32*sin(degtorad(r+(90*i))),1,1,col,1);
    }
}

//End Of Code

This code might look like absolute nonsense to a novice gamemaker coder, but either way I'll make sure you understand it. It's actually not that complex.

draw_set_color(c_black);
draw_rectangle(0,0,800,608,0);

The reason for this is that even though we've got the screen drawn to the surface, we've also got the original screen, unchanged, sitting there behind it. We'll make the original screen blank by putting a gigantic rectangle over it. What we do next is execute the following code whenever the "surf" surface exists:

    r+=2;
    for (i=0;i<4;i+=1){
    switch i{
        case 0:
            col=make_color_rgb(255,255,0);
        break;
        case 1:
            col=make_color_rgb(0,255,255);
        break;
        case 2:
            col=make_color_rgb(255,0,255);
        break;
        case 3:
            col=c_white;
        break;
    }
    draw_surface_part_ext(surf,i*200,0,200,608,i*200,32*sin(degtorad(r+(90*i))),1,1,col,1);
    }

Basically, what we do is increase the variable "r" each frame. We'll use it later.

Aside from that, we start a "for" loop. Basically how it works is it repeats the same code, but each time having "i" be a different value. In that loop, the switch statement checks the variable "i" from the for loop and uses it to set the variable "col" depending on what value "i" is. After that, we draw a part of the "surf" surface. As you should remember, we drew the entire screen onto the "surf" surface, so now we can have our fun with it. Basically, since the "for" loop will repeat 4 times, we draw a different part of the surface 4 times. This is where it gets really tricky to explain.

The arguments for the draw_surface_ext() function are: ID, Left, Top, Length, Height, X, Y, Horizontal Repetition, Vertical Repetition, Color, Alpha.

We're obviously drawing from the "surf" surface.

The left of the part is dependent on "i". Since "i" ranges from 0 to 3, we'll have one part's left be 0, one be 200, and up to 600.

The top of the part is 0. This is so we always draw the correct part of the surface.

The length of every part is 200, because that's exactly 1/4 of the room width.

The height of every part is 608 so we draw the correct part.

The X is also dependent on "i". We won't change this.

The Y position is 32*sin(degtorad(r+(90*i))). This may sound odd, but there's a good reason for this. To make each part wavy, we use the sine function which plots points in a perfect wavy pattern. the degtorad() function simply converts degrees into radians, which is the sine function's way of working. We use the "r" variable as the base degrees, but we also add "i*90" degrees to it. This is how we make the parts wavy.

No extra horizontal or vertical repetition of the part is needed; We're only drawing the part once.

The color is dependent on the "col" variable defined by the switch statement above. Basically, we'll draw one part yellow, one part cyan, one part magenta, and one part white. Gamemaker blends the colors and does amazing things with them.

The alpha is 1, because we need to make it fully visible.

After that, the function is called, the for loop ends, and the code closes.

We'll see what we just created in a gif form! Although, I'd suggest you put it in gamemaker yourself too to see how it affects the screen.

This is what the end result should be similar to:


(click to show/hide)

This concludes the tutorial. This is only getting a certain screen effect, though. You'll have to do a whole bunch of experimentation when you want a fancy screen effect of your own. Now that you know the basics of making a surface, I hope you enjoyed the tutorial!

242
Off Topic / Re: Hi friends in of me
« on: June 28, 2015, 02:56:25 PM »
aaaaeeeieoieoeueouoaiueiueeaeoiu.

243
Video Discussion / Re: I Wanna be the Wischtech in 0:54
« on: June 26, 2015, 02:31:45 PM »
hahahahaha nice

244
Video Discussion / Re: I Wanna be the Wischtech in 2:54
« on: June 24, 2015, 02:39:57 PM »
*clack* noice

245
Gameplay & Discussion / Help with IWTTT2
« on: June 21, 2015, 07:18:11 PM »
How do I find the secret areas like Horror World and the Extra Boss? I've looked all over the place, but I can't find the entrances anywhere. Are they in the acts and not the world hubs?

246
Gameplay & Discussion / Re: Post the fangame you just beat!
« on: June 21, 2015, 04:06:29 PM »


IWTTT2 cleared on Normal Mode. That's the time I took to beat Veilac. I'm not sure how hard Veilac is on hard mode. I dunno how, but I took 7 less hours on this boss than Casualcrap did. \:SoonerLater:/

247
Programming Questions / Re: Problems with creating this shape
« on: June 21, 2015, 02:25:32 PM »
god damn it that looks nice

edit: whoopsied my other post. ._.

248
Gameplay & Discussion / Re: K3 save problem
« on: June 20, 2015, 01:12:36 PM »
I think that v1.30 is okay with the influka fight, but who knows. Test out your hitbox by dying a bit to see if it's good.

249
Gameplay & Discussion / Re: K3 save problem
« on: June 19, 2015, 11:51:03 PM »
All the version's save files can be used in later versions, but later version's save files can't be used in previous versions. I'm afraid that your two choices are either doing it over again or savehacking.

250
Gameplay & Discussion / Re: What's Your Progress?
« on: June 19, 2015, 06:06:36 PM »
3 minutes after i started the stream, i beat it. those avoidance-dodges were damn nice.
took me 8 hours

congrats, we're like 2 peas in a pod now. hey gza do the thingy again

251
Unfinished / Incomplete / Re: Shadesbot Plays Guy Games
« on: June 07, 2015, 05:46:00 PM »
looking forward to that dank hendeca corner clear

252
Meet and Greet! / Re: :o
« on: June 07, 2015, 02:42:19 PM »
whoa dude, a post :o

253
Video Discussion / TAS 5th save clear
« on: June 07, 2015, 01:47:21 AM »
Not much of an accomplishment, but it was really fun to do.

https://www.twitch.tv/lawatson/c/6800441

254
Gameplay & Discussion / Re: What's Your Progress?
« on: June 06, 2015, 09:49:19 PM »


This is basically where the game gets hard. The saves before it are basically 1/2 as hard, or less.

255
Damn, dude. Looks really hard. Congrats!

Pages: 1 ... 7 8 9 10 11 12 13 14 15 16 [17] 18 19 20 21 22 23 24 25