0 Favourites

Color based collision

  • I want to create a vertical scrolling shooter of sorts. I want to achieve the effect of a ship or boat navigating on a river.

    This is my river here:


    That is "the map". The player is allowed to move on the white part. If the player touches the black part, he's dead.

    I want to draw the map in Paint, save it as PNG and import it as sprite or tiled background. Then have the player with bullet behavior and he goes up and can move left and right, but he most not touch the black "shore".

    I (think I) need a condition like

    Player->Is overlapping Background on color (RGB(0,0,0))

    Can this be done in C2?


  • No need detect as RGB~

    Hint: The river didn't hold any collision but "other objects"~

    Hope it help~ =)

  • I would make two standalone sprites for the left and for right shore and make one condition: if 'overlapps left-shore' and 'overlapps right-shore' --> game over

  • You don't even need two separate sprites. Just make it the same object, and set the animation speed to 0. Then load each image as frames in one sprite. Then you can just test for collision or overlap on the one sprite and it will hold true no matter which shore you collide with.

  • I wouldn't use a super big image for collision but build the collision out of a little resized square. This way you only load a little texture and you get a good level of customisation directly inside C2

  • AkiraWong, Joe7, TL22: Thanks for the suggestions, I know about these options. But then the collision polygon has too many vertices (points), anything more than 8 and you get the performance warning - and in my case I'd need like at least 40, perhaps even more than 100 for more complicated levels - the map I was giving was just a simple example.

    Yann: Thanks, I did think of this. I could use the square just for the margins so that I don't have too many sprites. BUT: how can I dynamically create the "little squares" based on the image I want to use as a map? How to get the coordinates for the little squares from the map image?

  • i think you have 2 options, making the levels by hand by placing colliders, or using the canvas plugin to check for rgb color, i would say that option one would be the fastest, option 2 is how lemmings and worms worked, checking different colors and based on this you can move or not, but its pretty difficult and will get very complex, but if you wanna try..

    you could also make different shorelines pieces with collison set, and generate them randomly on y-axis, you would need pieces that would fit on each other ( with some overlap maybe) but could be nice..

  • Construct 3

    Buy Construct 3

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

    Buy Now Construct 3 users don't see these ads
  • Yanns suggestion is the best I think. There's no reason the detectors cant be 2x2 images scaled up with the poly set up accordingly.

    They don't even have to be visible. You can make a mask thats just the size of the viewport, and have it draw based on the players position.

    Also rgb detection isn't that fast, and I've found it can vary across the different browsers.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)