Color based collision

Get help using Construct 2

Post » Sat Apr 28, 2012 1:40 pm

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:

http://img62.imageshack.us/img62/6964/vertscroll.png

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?

Thanks.
B
14
S
5
G
7
Posts: 235
Reputation: 5,175

Post » Sat Apr 28, 2012 2:27 pm

No need detect as RGB~
Hint: The river didn't hold any collision but "other objects"~
Hope it help~ =)
B
13
S
5
G
3
Posts: 63
Reputation: 3,989

Post » Sat Apr 28, 2012 4:27 pm

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
Joe72012-04-28 16:27:43
B
14
S
6
G
5
Posts: 173
Reputation: 4,742

Post » Sat Apr 28, 2012 4:49 pm

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.
B
56
S
20
G
7
Posts: 305
Reputation: 8,754

Post » Sat Apr 28, 2012 5:28 pm

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
B
60
S
22
G
14
Posts: 1,479
Reputation: 16,346

Post » Sat Apr 28, 2012 10:38 pm

@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?
B
14
S
5
G
7
Posts: 235
Reputation: 5,175

Post » Sun Apr 29, 2012 1:33 am

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..vtrix2012-04-29 01:39:05
ImageImage
B
61
S
19
G
6
Posts: 809
Reputation: 9,028

Post » Sun Apr 29, 2012 2:00 am

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.
Image Image
B
161
S
48
G
89
Posts: 7,347
Reputation: 66,249


Return to How do I....?

Who is online

Users browsing this forum: Google [Bot], Governador, RookieDev, tarek2, Thelegendvinny and 17 guests