1. Hey! Guest! The 35th GMC Jam will take place between November 28th, 12:00 UTC - December 2nd, 12:00 UTC. Why not join in! Click here to find out more!
    Dismiss Notice

Invert Colors on Sprite Overlap

Discussion in 'Programming' started by Gravityhamster48, Nov 9, 2019.

  1. Gravityhamster48

    Gravityhamster48 Member

    Joined:
    Dec 6, 2018
    Posts:
    31
    Hello,

    I am making a simple platformer. My colors are monochrome (or whatever two colors you set it to) and I would like it so that when two objects overlap, their colors invert.

    Here's a pic of what the game looks like:
    QuestionPic1.png
    Here's a pic of the player overlapping the door:
    QuestionPic2.png
    I would like where the door and player overlap for the colors to invert. So, his eye would turn light, and the part of the body that overlaps the door to turn dark.

    Any ideas?

    Thanks,
    ~Gravityhamster
     
  2. NightFrost

    NightFrost Member

    Joined:
    Jun 24, 2016
    Posts:
    1,977
    I would use a shader for that. So the first question is, how familiar are you with shaders?
     
  3. CloseRange

    CloseRange Member

    Joined:
    Jul 2, 2016
    Posts:
    861
    What @NightFrost is fine but for something so simple I'd go even easier than that. if the colors are just 2 colors like you have make all your sprites full white.
    set the background color to whatever you want the background color to be
    then use image_blend to set the forground color.
    Code:
    if(keyboard_check_pressed(ord("f"))) {
         var temp = background_colour;
         background_colour = image_blend;
         with(all) image_blend = temp;
    }
    this will flip the color of all objects with the background color whenever you press f
     
  4. Gravityhamster48

    Gravityhamster48 Member

    Joined:
    Dec 6, 2018
    Posts:
    31
    I know a little about it. In fact, in this screen shot, the actual sprite colors are white and black, but I used a shader to change the palette. However, in order for me to learn how to do this, I had to look it up. I never got very far on doing things with GLSL from scratch.

    I don't think that's really what I'm looking for. This inverts everything. I want to invert only the colors on the part of the character overlapping the door.
     
  5. rIKmAN

    rIKmAN Member

    Joined:
    Sep 6, 2016
    Posts:
    4,646
    Google "gamemaker silhouette", the first 3 video results are tutorials that will show how to do this made by FriendlyCosmonaut and HeartBeast using blendmodes and TheReverend using shaders.

    There's also a great blog article by Juju which explains how the effect works in Ruin of the Reckless, but I don't think you need anything that complex so I'd probably go with FriendlyCosmonauts video and see how you get on.
     
  6. Gravityhamster48

    Gravityhamster48 Member

    Joined:
    Dec 6, 2018
    Posts:
    31
    Thank you! I've actually watched FriendlyCosmonaut's video on silhouettes in the past, but I wasn't sure if it would solve this problem. I may look at it. I'm not entirely sure if such a minor effect is really worth it for the project at this point, but we'll see. Thanks again, though!
     

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