17

Your GPU can probably render even 100k sprites without issues, but you need to do it smart. Sprites and other geometry must be supplied to a GPU in batches grouped by the same texture, shader and blend mode. Big AAA games are minimizing draw calls issued to the GPU. Draw calls are usually expensive, so many similar drawing operations are grouped together ...


6

For a triangle with points p0, p1, and p2, and normal n, you’ll need to compare the vectors cross(p1 - p0, p2 - p0) and n. They should either point in the same direction, or in the opposite direction, for all triangles in your mesh. Suppose your convention is that the vectors must point in the same direction. The algorithm is simple. For each triangle, ...


6

You are correct that libGDX doesn't contain any sort of built-in support for rendering sprites in a certain order. (If it's there, I haven't seen it, and I've been using libGDX for a number of years.) What I do is create a SpriteComponent class that wraps the Texture object and emits x, y, and z attributes. Then in my draw method, I sort all ...


5

Here is a solution without resorting to 3D coordinates or splitting your sprite into 1x1 elements, that works if your objects occupy rectangular areas of tiles. Let (ei,ej) be the coordinates of the bottom tile of entity e. I assume the x axis is pointing north-east and the y axis is pointing north-west, so that (ei,ej) has the smallest coordinate values ...


5

Brief : This answer suggest to break big sprites into one by one tiles so the zPosition for each sprite which is used to sort them in depth will work correctly. To understand my proposal you will have to stop thinking in tiles for a while, even if your finished game needs to guarantee that all objects will be tile aligned. I suggest you to adopt the same ...


4

Sort the rendering order by the used sprite sheet and not by distance from camera. This works fine if you use z-buffer and don't render transparent objects. I.e. first draw all the trees (and other objects in the same sprite sheet) into the scene and test and write the depth in z-buffer. Then render all units and do the same. This will result in 2 draw calls ...


4

For normal cases, sprite order is determined by the Spritebatch.draw() call order. If this is the case: spritebatch.draw(apple); spritebatch.draw(mango); then apple will be drawn first and then mango will be drawn on top of that. So mango will overlap apple.


3

Increasing order in layer solved the problem.


3

The artificial depth from x and y is worth exactly as much as a the one from perspective projection, meaning all normal depth operations apply to it. There are essentially two possibilities for solving your problem: Keeping the static tiles in an already sorted structure and using the depth buffer. Sorting and Redrawing pros: lower graphics memory ...


3

Transparency with OpenGL is typically achieved using alpha blending, as you are attempting to do with glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA). In order for you to get the desired effect, though, it helps to understand what the blending function means. Let's consider the following scenario: you first draw a triangle, and then you want to draw a ...


3

The most robust method to ensure there are no transparency artifacts is to: Disable writes to the depth buffer (although you may want to have a separate depth buffer for effects, I'll explain later) Decompose your object into convex pieces (unnecessary in this specific case, a box is already convex) Sort the parts of all objects from farthest away to ...


2

As stated in the comments, that texture has a transparent background in the original game. That way they can just draw the base grass, then the player, then the tree.


2

The way you are batching your sprites might be suboptimal. If you're using glDrawElements() to render a batch of multiple sprites, then that can only mean you're storing 4 vertices per quad in your VBO (otherwise I fail to see how glDrawElements() alone could render several sprites at once. I might be wrong, in which case feel free to correct me). The ...


2

You can do this with two cameras with different culling masks. When you have multiple cameras in your scene, each camera will be rendered separately. The culling mask decides what will be rendered by the camera. Then the output of all the cameras get drawn on top of each other in order of their "Depth" value. Click on "Layers -> Edit Layers" and create a ...


1

Okay, the solution was very rather simple. It was the sorting layer/order of the child of the projectile that caused it. Changing it solved the issue.


1

I was thinking about putting them into an array list, and ordering them based upon their depth YES. but they are different object types. The guy is an object of class character, and the girl is an object of class NPC. Is there a way to put both of these object types into one array list, or should is their another solution. Define an interface that has ...


1

I made a little sample project of how I would implement this, as a component you can simply attach to any gameobject you want to be made draggable. I will include the code for the mono behaviour here too, each sprite you want to be able to collide needs a BoxCollider2D and a RigidBody2D, if you don't want physics to apply to the objects make sure to set ...


1

Ok, so just of the top of my head your going to want to make a new circle(2d) and apply a texture to this then write something along these lines (and attach it to the object) Pseudo code: private gameobject player private float scale; update{ face the player (using transform.lookat(player)) float distance = vector3.distance(transfrom.position,player....


1

You will have to sort the sprites based on their bounding box and start drawing things from back to front. In order to be successful with this you'll have to apply a mapping from the 3D coordinates (which seem dimetric to me) to the screen coordinates. Height differences translate directly into an offset in the y-coordinate while movement along the oblique(?)...


1

Do you have the same problem if you try to draw directly to the RenderWindow (window.draw(point, sf::BlendAlpha)), instead of drawing to a RenderTexture and then to a sprite? Because doing so is essentially doubling the buffer size for the draw unnecessarily. I would recommend you simply draw to the window for performance reasons. I think the fact you're ...


1

I used a straight forward approach for this. My map (not the end result!) is set up us horizontal lines, where i go from top to bottom, blitting everything from left to right. That way I automatically place everything in the correct order. My tiles (not walking sprites, they have their origin at (0,y) !) all have their origin in the left-middle, or (0,y/2) ...


1

UPDATE: doesn't work entierly! I solved this by setting the camera's transparency sort mode to orthgraphic: Camera.main.transparencySortMode = TransparencySortMode.Orthographic; Works for both LineRenderer or using a deformed cube. https://docs.unity3d.com/ScriptReference/TransparencySortMode.html


1

First of all - SpriteRenderer and LineRenderer don't cooperate, as they say on Unity forums. There are two ways of changing the LineRenderer's draw order: By changing the position in the line's material's Render Queue to lower: Creating a complately new layer (normal, not sorting) named for example LineLayer and creating a new camera for it. Set the camera'...


1

What you should ask yourself is what is the actual difference between the two types? An animated entity typically has both some form of a skeleton of bones which are animated through various animation tracks which a non-animated Sprite likely does not. That would mean for animated entities, their skeletal pose needs to be properly set based on the ...


1

When you want to have overlapping sprites in your game, you need to put them in a list which you sort by the coordinate of the lower edge of each sprite and then render them in that order. Further, when you are using a graphics API where y = 0 is the upper edge of the screen, you need to take the height of each sprite into account when you draw it and draw ...


1

It is the case that all particles share the same Z order in unity. This is a weird design choice, but I believe it 's because the emitter is an object that is sorted with the rest of the world, and does its own internal sorting for particles. (You also cannot mix particle systems). One way to handle this is to have two particle systems, one behind and one ...


1

I see two solutions to this: Make your player a part of the TiledMap by adding him to his own layer. This will automatically render him in the correct order like all of your other tiles. Add an integer property to your tiles in whatever program you're using to create your maps named "zIndex" and then sort your tiles by this property and render them in the ...


1

Sort by z position. You will probably want to add an origin to every object as well to determine their position in the game world (ie the players feed, the center of where the box touches the ground, etc.). There are some restrictions for what objects this will work for though. When the players z position becomes larger or smaller than that of an object he ...


Only top voted, non community-wiki answers of a minimum length are eligible