Finding corners of 2D sidescroller level

Get help using Construct 2

Post » Sun Mar 31, 2013 8:44 pm

Hey,

I am looking for the most simple and efficient way to find corners in a sidescroller level. Level is composed of solid squares (red in image), and I've defined the points I'd need to locate with black circles. Basically what I need to find, is each corner. I'd like to place a sprite in each of these corners, so that sprite does not overlap the collisions, but rather floats x pixels away from surrounding collisions. The angle of collision squares can vary.



Anyone got any good ideas how I could approach this? :)
B
24
S
8
G
7
Posts: 756
Reputation: 7,192

Post » Sun Mar 31, 2013 9:22 pm

Ashley sneaked in Sprite.BBoxBottom, Sprite.BBoxLeft, Sprite.BBoxRight, Sprite.BBoxTop at some point.
Those ate the offsets based on the bounding box, other wise you would use image points, or some trig.
Image Image
B
161
S
48
G
90
Posts: 7,348
Reputation: 66,751

Post » Sun Mar 31, 2013 11:26 pm

@vee41 - Is it possible to take the principle from getting an AI to walk around a room by turning to a certain direction because the walls were different sprites?

By this I mean something like
Leftwall is overlapping Topwall > (trigger once) create sprite at X: (topwall.X - 25), Y: (topwall.Y -25)

25 is just an example number of pixels of course, and this assumes the origin point is very top left of the sprite.

edit: for your second picture on the right side where the small box meets the big one the bottom section of the wall would need to be a left wall and the top portion a right wall.wretchedshark2013-03-31 23:27:56
B
14
S
6
G
2
Posts: 136
Reputation: 3,210

Post » Mon Apr 01, 2013 7:55 am

[QUOTE=wretchedshark] @vee41 - Is it possible to take the principle from getting an AI to walk around a room by turning to a certain direction because the walls were different sprites?

By this I mean something like
Leftwall is overlapping Topwall > (trigger once) create sprite at X: (topwall.X - 25), Y: (topwall.Y -25)

25 is just an example number of pixels of course, and this assumes the origin point is very top left of the sprite.

edit: for your second picture on the right side where the small box meets the big one the bottom section of the wall would need to be a left wall and the top portion a right wall.[/QUOTE]

@wretchedshark That was my first attempt, the main problem (which I forgot to tell in the initial post) is that it was a bit slower method than I had hoped for, and required quite many checks and positioning of objects on collisions.

@newt thank you, was not aware of those! Those would be useful in this scenario as well.

What my current approach is, and seems to work somewhat decent, is to spawn sprite on each collision corner via imagepoints. After that I use an 'measuring sprite' which I rotate 360 degrees around the center of sprite at distance X. Whether this measure sprite is overlapping an collision or not, I can find the angle of surrounding solids. I seek for left and right collision angles, and position the sprite in between those via some basic mathemagics.

Here is an visual masterpiece I drew to describe the solution:



I only need to run it once so performance is not an issue. It still feels a bit excessive, but at least it works. :)

Thanks again!
B
24
S
8
G
7
Posts: 756
Reputation: 7,192


Return to How do I....?

Who is online

Users browsing this forum: anty21ro, Braus, Kagubro, Yahoo [Bot] and 2 guests