GML (Game Maker Language) posting please. How do I change one color to another in GML

Discussion in 'Programming' started by TunnelRhino, Dec 6, 2018.

  1. TunnelRhino

    TunnelRhino Member

    Joined:
    Jun 21, 2016
    Posts:
    28
    #1: How do I change in a game one pixel's color from one color to another?


    #2: How do I change in a game all of a sprite's one color to another color?



    #3: How do I change in a game all connecting colors into another color?
     
  2. Mert

    Mert Member

    Joined:
    Jul 20, 2016
    Posts:
    134
    For changing colours, you can use many technics. For changing a pixel color I simply use

    Question 1 - In DRAW EVENT
    Code:
    var col = make_colour_rgb(red,green,blue);
    draw_set_colour(col);
    draw_point(x,y);
    This simply draws a dot(pixel) on screen.

    2-Changing sprite's colour can be done either via image_blend or with a shader.
    IMAGE BLEND - In CREATE EVENT
    Code:
    image_blend = c_red;
    Changes the colour of the instance's sprite to red. (actually blends with it)

    SHADER
    Create a shader, it comes with default codes. Edit the part in vertex shader (On line 17)
    From
    Code:
    v_vColour = in_Colour;
    To
    Code:
    v_vColour = vec4(red,green,blue,alpha);
    You must fill the red,green,blue fields with 0-1. Game Maker gives you 0-255. Let's say you have 200,150,50 (R,G,B) colour. Do a basic percentage calculation to get 0-1 value.
    (GM Color value / 255 ) which means
    Red : 0,78
    Green : 0,58
    Blue : 0,19
    Edit : Alpha must be 0-1 too. Set it 1.
    Question 3 can also be done with shaders, I think there's one in the Marketplace(marketplace.yoyogames.com)
     

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