GameMaker Studio 2: Tutorial completo de plataforma (parte 15: sinalização)



▶ Código-fonte completo: https://shaunjs.itch.io/shauns-complete-platformer-tutorial-series ▶ Apoie meu trabalho: https://www.patreon.com/shaunjs ▶ Efeitos sonoros que usei: shaunspalding.co. uk/files/Sounds.zip ▶ Fonte que usei: https://managore.itch.io/m5x7

source

45 thoughts on “GameMaker Studio 2: Tutorial completo de plataforma (parte 15: sinalização)

  1. If you right click while your character is dead, there will be no oPlayer object for the point_in_circle function to work. To prevent this, you'd need to use a "if (instance_exists(oPlayer)" before running the Global Right Pressed event.

  2. The create event of oText can become
    spd = 0.25;

    letters = 0;

    border = 10;
    because all the other variables are or can be created elsewhere.

    You can remove

    if (h == 0) h = string_height(text);
    from the step event because you can add
    draw_set_font(fSign);

    h = string_height(text);
    to the global right pressed event of oSign within the with statement.

  3. i actually figured out the latter part of the tutorial with the sign on my own although i did do it a different(and slightly less optimised) way so i could add a prompt for a keypress, i feel really accomplished

    i also like how this works a lot since theres no line limit so you can decide that yourself

    also when i wrote other.text it came as red in gamemaker and showed it was an inbuilt variable so i changed the name of the variable in all instances to signtext

  4. My solution for making a sign marker when close to the signpost is probably inelegant, but I was really happy I made it work anyway.
    I made a sprite with a downward arrow that cycles through a little animation, then made an object for it. The object is invisible by default, but made visible whenever the player is within a certain radius of the sign. Then I just had to place the marker object over the signpost in the room editor!

  5. Big thanks for the tutorials so far.

    Why does my text disappear immediately as the last letter is loaded?
    It has no hang time, so now you have to toggle it a second or third time for you to read it properly

  6. If anyone's interested I created my marker with a blinking effect. After creating the sprite and attaching it to the marker object and everything, I used the following code:
    In create : timer =0;

    image_alpha = 0;

    in the step event:

    if (instance_exists(oPlayer)) && (point_in_circle(oPlayer.x,oPlayer.y,x,y,64))

    {

    timer +=1;

    if (timer = 30) //assuming framerate is 60fps

    {

    switch(image_alpha)

    {

    case 0:

    {

    image_alpha = 1;

    timer = 0;

    }

    break;

    case 1:

    {

    image_alpha = 0.25;

    timer = 0;

    }

    break;

    case 0.25:

    {

    image_alpha = 1;

    timer=0;

    }

    break;

    default:

    {image_alpha = 1;

    timer = 0;}

    break;

    }

    }

    }

    else image_alpha = 0;

    Also in the create event for oSign I wrote this:
    instance_create_layer(x, y – 40,layer,oSignPoint); // where oSignPoint is the name of my marker object.

  7. 20:11 If anyone wanted to make an ANIMATED arrow appear, I came up with a way to do so using a Draw Event in oSign:

    /// Arrow Over Sign When Player is Close

    draw_sprite(sSign,0,x,y);

    if(instance_exists(oPlayer))

    {

    if(point_in_circle(oPlayer.x,oPlayer.y,x,y,64))

    {

    sprite_index = sBouncingArrow;

    image_speed = 1;

    draw_sprite(sBouncingArrow,-1,other.x,other.y-30)

    }

    }

    NOTE: You have to make your own animated arrow sprite, which for me was sBouncingArrow

  8. For the "homework" you can add a draw event in oSign and put this code:

    draw_self();

    if(point_in_circle(oPlayer.x, oPlayer.y, x, y, 64)) && (!instance_exists(oText))

    {

    draw_set_alpha(1 – point_distance(x, y, oPlayer.x, oPlayer.y)/64);

    draw_sprite(sMarker, 0, x, y-sprite_height)

    }

    draw_set_alpha(1);

  9. extremely hacky sign marker code incoming:

    in obj_signpost step event:

    if (point_in_circle(obj_player.x,obj_player.y,x,y,64) and markeron == false)

    {

    markeron = true;

    instance_create_layer(x+5,y-35,"Entities",obj_signmarker);

    with(obj_signmarker)

    {

    image_alpha = 0.6;

    image_speed = 1;

    }

    }

    if (!point_in_circle(obj_player.x,obj_player.y,x,y,64) and instance_exists(obj_signmarker))

    {

    with(obj_signmarker) instance_destroy();

    markeron = false;

    }

  10. For some reason within my oText, my text drew outside of the text box… To alight the text I had to use draw_text(x+100, y-h-border+50, text_current); Although now aligned, the text is black although was specified to be white in in DrawSetText(c_white,fSign, fa_center, fa_top);

  11. If someone does not like the fact that the player cannot move while reading the sign, I wrote at the bottom how you can change it.

    1. In oText>Step>Destroy when done change vk_anykey to for example vk_enter
    2. In oSign create Step event and write this:

    if(instance_exists(oText))

    {

    if (!point_in_circle(oPlayer.x,oPlayer.y,x,y,64))

    {

    instance_destroy(oText);

    with (oCamera)

    {

    follow = oPlayer;

    }

    }

    }

    I know it might not be the best way to do it, but it works very well for me.

  12. I noticed a little bug. If you reset game when player is dead the slow-mo effect is permanent. To fixed this you need to change script in oTransition.
    oTransition>Key Press – R

    if (instance_exists(oPlayer)) SlideTransition(TRANS_MODE.RESTART);

  13. FIXED!!!

    If you are having the same issue I had (detailed below) with the scrips not working it IS because of the changes to how scripts work since the release of this tutorial.

    Shaun has a great video explaining the changes to the scripts (https://www.youtube.com/watch?v=9nwlgfzyNzA)

    .

    For some reason the script no longer seems to work. I know scripts have changed with version v2.3.0 so not sure if this is the reason. I get an error:

    ############################################################################################

    ERROR in

    action number 1

    of Create Event

    for object <undefined>:

    draw_set_colour argument 1 incorrect type (undefined) expecting a Number (YYGI32)

    at gml_GlobalScript_DrawSetText (line 14) – draw_set_colour(argument0);

    ############################################################################################

    gml_GlobalScript_DrawSetText (line 14)

    I've resolved the issue by not using the script Shaun uses and putting the four draw events in separately as he suggests as the other more long winded way.

    Just an FYI for 2021.

  14. For anyone wandering why Game Maker Studio (GMS)'s Y-coordinate is reversed, this is because "Screens display left to right, top to bottom, as scanlines. So, historically top left was 0,0." (Reddit Comment)

  15. If you succeed in making a little marker that appears above the sign when you walk within a certain radius, you can use this code to make it bob up and down smoothly 🙂

    Create Event (inside the marker object)
    /// @description Defining the Marker variables
    frequency = 5; //Control the speed – higher is faster
    amplitude = 5; //Control how 'high' the sign bobs
    midpoint = 20; //The starting point
    timer = 0; //Leave as 0
    bob = 0; //Leave as 0
    createy = y; //Ensured the Y fluctuates around the original position

    Step Event (inside the marker object)
    /// @description Make the sign bob
    bob = dsin(timer * frequency) * amplitude + midpoint; //Function to make the value of bob fluctuate
    timer++; //Progress the timer
    y = createy – bob; //Convert the bob value into movement in the y-axis
    if (!point_in_circle(oPlayer.x,oPlayer.y,x,y,125)) instance_destroy(); //Destroy the object if the player is not close enough

    That's all 🙂

  16. So im tring to add a sprite above the sign post when the player is withing the same distance of the sign post but i cant seem to get it to work. Can someone help me?

  17. Thanks for these tutorials – super helpful and clear!

    I'm having an issue with the DrawSetText you created. When I try to launch the game, it gives me the error that it expected a variable in argument one for draw_set_colour (whereas of course it's currently set as (argument0). Any idea why it might be doing this? Means I can't use the script and have to input all the lines every time.

  18. 9:00 dude this is already better than some AAA games, where they skip entire conversations the moment the player presses a key by accident, even before having finished writing the text to screen!

  19. GMS2.3.0> Users the scripts has been changed:

    this fixed for me:
    in the DrawSetText Script:
    function scr_DrawSetText(argument0, argument1, argument2, argument3) {

    draw_set_colour(argument0);

    draw_set_font(argument1);

    draw_set_halign(argument2);

    draw_set_valign(argument3);

    };

  20. for some robotic guys like me:

    7:20 – Shaun didn't put the brackets in the code so some of you may have misunderstood his code as:

    if ( h == 0 )
    {
    h = string_height ( txt )
    w = string_width ( text_current )
    }

    but it's actually this

    if ( h == 0 )
    {
    h = string_height ( txt )
    }
    w = string_width ( text_current )

    hope that helps you!

  21. For the homework, my method was to dive into the draw event of the sign (making sure to write a basic draw for the Sign right at the start), then add an if statement if the player got in a 64 pixel radius. If they did, there is a second draw event using with oSign that draws the same triangle Shaun uses above the sign (other.y – [some distance]).

    This has the added benefit of less faff with objects floating about, and you can envision using a variable to set the y distance everyframe, then count that variable up/down to "animate" the triangle by redrawing it every so often.

  22. if (point_in_circle(o_player.x,o_player.y,x,y,64))
    // … Yea, that code doesn't work if your player is dead / disappeared… It goes against the Dying tutorial…
    if (instance_exists(o_player)) && (point_in_circle(o_player.x,o_player.y,x,y,64))
    // That thing saves the day!

Deixe uma resposta

O seu endereço de email não será publicado. Campos obrigatórios marcados com *