Is it possible to make my game detect colors?

0 favourites
  • 10 posts
From the Asset Store
Full game Construct 2 capx code source to post on Google Play
  • What the title says. Basically, I want to make objects act in certain ways depending on the color they're touching. For example, if the player touches red, it gets hurt. Something like that.

    For more context, I'm trying to make a rhythm-based bullet hell game, like the game Just Shapes & Beats. I thought I could animate the levels themselves with Adobe Animate, export them as .mp4 files and put them into Construct as backgrounds, so I'm trying to do color detection with videos, specifically.

    It's okay if it's not possible though, I just want to make sure. Thanks.

  • You can paste the object on a small Drawing Canvas, and read the color from it. I haven't tried it with videos though..

  • I've done this with video before (and changed it into a tilemap which I could use for a platformer.) Basically what dop2000 said, paste video to canvas, take snapshot of canvas and translate color to tilemap for collisions. In my case I also did some 'chroma key' with threshold to make it a little easier to use.

    Here's an old template I used to play 'streams' of a mario video (there's more events than you need just for the video, because I was playing with some other ideas.) If you know JS, you can also do it in scripting and it will probably run a bit faster.

    Here's an example with a 'let's play', the green color is the tilemap w/o the video.

  • Hello, thank you both for your replies. I already know how to take a snapshot of the canvas and all that stuff, but I'm stuck at the part where I'm supposed to translate the color to tilemap. I don't know what events and expressions I should use.

  • Did you look at the code I posted above? It shows how to translate color to tilemap.

  • Hey, sorry to be a bother, but I don't know what to do to translate a specific color to tilemap. I've copied the whole code, but I can't seem to find the way to actually make it work, if that makes sense.

  • Check for RGB match (or close enough match.)

    Say your color is MatchR, MatchG, MatchB

    Color at a point is:

    pointR = DrawingCanvas.SnapshotRedAt(loopindex("X")/DrawingCanvas.PixelScale,loopindex("Y")/DrawingCanvas.PixelScale)

    pointG = DrawingCanvas.SnapshotGreenAt(loopindex("X")/DrawingCanvas.PixelScale,loopindex("Y")/DrawingCanvas.PixelScale)

    pointB = DrawingCanvas.SnapshotBlueAt(loopindex("X")/DrawingCanvas.PixelScale,loopindex("Y")/DrawingCanvas.PixelScale)

    How close is the point color to the match color:

    distance = sqrt((MatchR-pointR)^2 + (MatchG-pointG)^2 + (MatchB-pointB)^2)

    Check that distance is less than some threshold to find a match.

    Use the project debugger or browser.log to print the values or display all the above values to the screen, so you can get an understanding of the range of values in your project.

  • Hello! Thank you for your valuable info, unfortunately after all these months, I still can't get it to work. If it's not too much to ask, I'd like to open the actual project to see how it works.

    If what you've shown me so far is part of a project you'd rather not share with others, then it's completely fine! But there doesn't seem to be any tutorials online on how to make this work (Asides from the official guide, which doesn't work very well for me.)

    I just don't understand if pointR (and the others) are variables, strings, system expressions or whatever, and I also don't know where should I put the RGB value for detecting a specific color.

    sorry for bothering you lol

  • Sorry, I don't want to release the full project.

    If you post your project, I can see if I or someone else can help with it.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)