Finding corners of 2D sidescroller level

0 favourites
  • 4 posts
From the Asset Store
59 unique spaceships created in pixel art style within 48 x 48 pixels. Great for creating side scroller shooter games.
  • 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.

    <img src="http://dl.dropbox.com/u/19921470/find_corners.png" border="0" />

    Anyone got any good ideas how I could approach this? :)

  • 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.

  • 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.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 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.

    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:

    <img src="http://dl.dropbox.com/u/19921470/find_corners_solution.png" border="0" />

    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!

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