1. Hey! Guest! The 32nd GMC Jam will take place between Feb 22nd, 12:00 UTC (Friday noon) and Feb 25th, 12:00 UTC (Monday noon). Why not join in! Click here to find out more!
    Dismiss Notice

Problem to "tie" armors to a player sprite.

Discussion in 'Programming' started by Tarte, Feb 3, 2019.

  1. Tarte

    Tarte Member

    Joined:
    Jan 10, 2019
    Posts:
    30
    Hi. I am creating a platform game on a game maker. My character has a lot of sprite with different swords and I want to add armor. I would like to have a way to glue or attach the armor without having to redo all the sprites with the armor. Thank you in advance for your answers.
     
  2. samspade

    samspade Member

    Joined:
    Feb 26, 2017
    Posts:
    1,499
    This might be what you're looking for.

     
  3. Sabrina Stoakes

    Sabrina Stoakes Member

    Joined:
    Jul 9, 2018
    Posts:
    69
    You could do that by drawing the armor sprites over your character!

    Adding a check like this for drawing the sprites could make it possible to have multiple armors:
    Code:
    ///Armor 1
    if armortype = 1 {
    ///Draw Armor 1
    }
    
    ///Armor 2
    if armortype = 2 {
    ///Draw Armor 2
    }
    
    That seems like the easiest way to me!
     
  4. RefresherTowel

    RefresherTowel Member

    Joined:
    Jul 13, 2016
    Posts:
    913
    A bunch of if statements is going to get very unwieldy quickly. A better method would be to store the current armour sprite in a variable and draw that variable over your character:
    Create
    Code:
    current_armour = spr_basic_armour_1;
    
    Whenever you upgrade to new armour:
    Code:
    current_armour = spr_the_new_armour;
    
    Draw Event
    Code:
    draw_sprite(x,y,spr_my_naked_character);
    draw_sprite(x,y,current_armour);
    
    That's a very simplified version, you can split it up into individual pieces by setting a variable for each piece (i.e. current_helmet, current_boots, etc) and drawing them all the same as above) but that's the general idea.
     
  5. PlayerOne

    PlayerOne Member

    Joined:
    Mar 14, 2018
    Posts:
    298
    You can make a ds_grid for each weapon(s), clothing items for each part of the body, stats for each item, and anything else you want. Just make sure you destroy the grid to prevent memory leaks once your finished.

    Code:
    //CREATE
    global.player=ds_grid_create(10,5);
    _id=global.player;
    
    //Head
    _id[0,0]=sprite;
    _id[0,1]=stat1;
    _id[0,2]=stat2;
    _id[0,3]=stat3;
    _id[0,4]=stat4;
    
    //Body
    _id[1,0]=sprite;
    _id[1,1]=stat1;
    _id[1,2]=stat2;
    _id[1,3]=stat3;
    _id[1,4]=stat4;
    
    //etc...
    
    Code:
    ds_grid_destroy(global.player)
    
     
  6. Tarte

    Tarte Member

    Joined:
    Jan 10, 2019
    Posts:
    30
    Thanks you very much for your answers guys ;)
     
  7. Tarte

    Tarte Member

    Joined:
    Jan 10, 2019
    Posts:
    30
    Ok Tanks, So I have to make a sprite armor when the character goes to the left, right, jump …?
     
  8. RefresherTowel

    RefresherTowel Member

    Joined:
    Jul 13, 2016
    Posts:
    913
    Depends on the way your character looks when they switch direction but generally, yes, you have to make the same amount of "angles" of the armour sprite as you would the normal sprite. This is part of the reason that many people do not display armour changes on a character if they have many different types of armours. It takes a lot of artwork.
     
  9. Tarte

    Tarte Member

    Joined:
    Jan 10, 2019
    Posts:
    30
    Ok thanks you very much
     
  10. Tarte

    Tarte Member

    Joined:
    Jan 10, 2019
    Posts:
    30
    Hey, If I put this in the event draw, the armor "trembles" oddly, but how do you put this in the Draw GUI event because you have to stick it to the character and it does not always have the same position relative to the camera ?
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice