3
\$\begingroup\$

My question is specifically about the type of perspective that GBA Pokemon games like Fire Red/Leaf Green have:

Pokemon screenshot

I'm not sure of the correct terms for what I'm trying to achieve.

I am using SDL2 and can render a tilemap and sprites on top of it, with basic collision detection, but since everything is constrained inside a tile, it looks like the player collides with a wall when their head touches it, rather than the feet.

The above screenshot has a tiny bit of perspective (is that considered 2.5d?), so the head of the player hides a portion of the tile above.

There are definitely ways to make this work, e.g. being a bit more lenient on collision (i.e. not the whole bounding box of the player but the middle of it collides with a wall), but my question is mostly about efficient rendering.

Is rendering from the bottom up the best thing to do so that I respect the perspective? If it is then I guess I need to know at which tile to render the player, so I need to compare every coordinate with the player coordinates to see if it's time to render the player?

\$\endgroup\$
  • \$\begingroup\$ Those games use a single layer for this. Some of the tiles just look like walls \$\endgroup\$ – Bálint Apr 2 '19 at 10:28
  • \$\begingroup\$ @Bálint, I know, I'm specifically asking about order of rendering and how to make sprites appear on top of e.g. walls when they are in front of them and behind when they are behind in an efficient manner \$\endgroup\$ – alexpeits Apr 2 '19 at 10:34
  • 2
    \$\begingroup\$ This is a kind of oblique projection. When you see the tops of objects and the front, we'll often call it an oblique top-down projection. \$\endgroup\$ – DMGregory Apr 2 '19 at 11:00
0
\$\begingroup\$

You don't need to consider when to render the player. Simply render your whole scene from the top of the screen to the bottom, with transparency around the parts which will overlap the tile above. Controlling render order was the old fashioned way to produce isometric games with tiles overlapping those behind them, and it will work in this way too.

Compared to a 3d-based approach, such as that advocated by Bálint, this approach has the advantage that you have pixel perfect control over your images which is better if you want to have a stylised pixel art look, but means that effects such as lighting and shadow are harder to model accurately.

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ Pixel perfection can be achieved in 3D too, with the appropriate pixel snapping applied to your assets or within your shaders. \$\endgroup\$ – DMGregory Apr 3 '19 at 11:11
0
\$\begingroup\$

If you are working with 2D, you usually work with two coordinates for the game logic, so x and y for a position of your objects. Additional, every object has an additional boundary, like a width and a height. If you got deterministic positions, these boundaries are most likely the size of a tile. Like a chess board.

Now, for the graphic steps, you work with the x and y position for your sprites, additional you got the size of your texture (like width and height) and also you got a z-order.

This order is basicly the depth of an texture. So if you want to draw your character above the ground. your ground textures need to have the z-value of 0, your character would have 1.
When your character stands infront of a tree, you should give them both the same z-value, then then draw the obects in the order of their y position, since that means its closer to the camera. The Branch on the this tree would then have an z-value of 2.

What you then do draw your objects in z-order starting with the lowest, so first the ground (value 0), then objects (value 1), then overhanging objects like a branch (value 2).

Every vertice has its own z-value. So for the most part, every vertice for a sprite should have the same z-value. If you dont give a z-value to a vertices, by default the y-position is chosen.

| improve this answer | |
\$\endgroup\$
0
\$\begingroup\$

If you can, it's best to do everything in 3D and just render it from a fixed angle. It worked for games that feel completely 2D (Enter the Gungeon) and for games that are 3D (LoZ: A link between worlds, though there the developers had to skew everything a bit to make everything visible).

If you can't use 3D, it's best to use layers and keep track of the player. Link to the past used this approach for instance. The top levels where in a different layer and whenever the player used stairs it would transfer it to a different layer.

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ Using layers makes sense. What would I do in the case where I have e.g. a fence, and the player can appear in front of the fence but also behind it? \$\endgroup\$ – alexpeits Apr 2 '19 at 10:56
  • 1
    \$\begingroup\$ @alexpeits draw the fence as entity/actor/sprite, but sort them based on their local y coordinate \$\endgroup\$ – Bálint Apr 2 '19 at 12:16
  • \$\begingroup\$ @alexpeits also, if this solved your issue, press the green tick button under the +1/-1 buttons \$\endgroup\$ – Bálint Apr 3 '19 at 0:31
  • \$\begingroup\$ You cannot recreate the shown effect from any 3d angle. \$\endgroup\$ – Jack Aidley Apr 3 '19 at 8:51
  • \$\begingroup\$ @JackAidley instead of just saying that, could you provide any reason why it's not possible? Because I've seen multiple examples that utilized these techniques and are popular. You just need some creativity to overcome some problems. Remember, 3d ≠ perspective \$\endgroup\$ – Bálint Apr 3 '19 at 9:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.