Friday, January 24, 2020

GameMaker Studio 2 - Build-In Functions

4. BUILD-IN FUNCTIONS

Last post we have learn how to draw a rectangle using draw_rectangle () function. This function is a build-in functions that available within the GameMaker Studio 2 Language (GML). For all the list of available functions along with the required arguments and examples of code to show how thy can be used, we can look it at the documentations from yoyogames here.

Aside from the web documentations, middle click at the function within the editor will open a documentation tab to find some brief explanations and examples.








Now lets "move-along" with the lesson from sheepolution.com. 😀

Just like the post before, we start by drawing another rectangle in the draw event :

//Draw a rectangle
draw_rectangle(100,50,200,150,true);


When we look at the documentations, the numbers are x and y position of the left corner rectangle against the GameMaker room, as of (0,0) is located at the top left of the screen or at the top left of the GameMaker room.










draw_rectangle(100,50,200,150,true);

100 = The x coordinate of the top left corner of the rectangle.
50   = The y coordinate of the top left corner of the rectangle.
200 = The x coordinate of the bottom right corner of the rectangle.
150 = The y coordinate of the bottom right corner of the rectangle.
true = Whether the rectangle is drawn filled (false) or as a one pixel wide outline (true).




















And now, how to make the rectangle move? 
When the rectangle move, means the coordinates is being altered either by adding some amount of value or by subtract some amount of value.

In LÖVE framework (as written at sheepolution.com tutorials), we do this by using code :

function love.load() x = 100 end
function love.update() x = x + 5 end
function love.draw() love.graphics.rectangle("line", x, 50, 200, 150) end


Lets add a Create event :
x = 100;

And add a Step event :
x = x + 1;













And modified the draw event :
draw_rectangle(x,50,200,150,true);


and things become very weird :
Why is that?

Lets take a look at the function that we write in the draw event :

draw_rectangle(x1,y1,x2,y2,true);
draw_rectangle(x,50,200,150,true);

We only alter the value of x1 but not x2, thats why. The x1 is moving along 1 pixel at a time at x axis, but the x2 is not moving because the value is fix at (200,150) coordinates.

Now lets fix the code :

draw_rectangle(x,50,x+100,150,true);

why is x+100, not x+200 ?
Well, we have create a variable in the Create event :

x = 100

so x+100 equal to 100+100 = 200.

If we run the game now, the rectangle now should move normally.

1 comment:

  1. Tukitanotes.Blogspot.Com: Gamemaker Studio 2 - Build-In Functions >>>>> Download Now

    >>>>> Download Full

    Tukitanotes.Blogspot.Com: Gamemaker Studio 2 - Build-In Functions >>>>> Download LINK

    >>>>> Download Now

    Tukitanotes.Blogspot.Com: Gamemaker Studio 2 - Build-In Functions >>>>> Download Full

    >>>>> Download LINK uC

    ReplyDelete