Tag Info

New answers tagged

2

This does not necessarily have to be as computationally expensive as you imagine. First of all, as you hinted at, you don't have to check every entity; just the ones that are moving. As such it might be wiser to have individual entities update their grid cell in their update method. As for checking coordinates, there are a few optimizations you could make. ...


5

First of all, unless you have an exorbitant number of entities, assigning them to a sector on every logic frame is most likely performance-wise negligible. That said, it sounds like you are in over your head. Either your game doesn't actually need spatial partitioning, or what you are trying to create is too advanced for your level. The point of spatial ...


2

You don't have to check every entity, every frame. You only have to check entities when you move them. Further, since you're using a grid system, you can just check to see if they've crossed a boundary. For example, if they're currently in grid 5,5 and you have a grid line every 10 units, you only have to do a modulus on their current x and y coordinates ...


1

The frame you're in is irrelevant. You don't do this every frame. When the entity moves just check if it's in a new section and update it as needed.


0

Sounds like you need to create your own game object and use a custom triangulation algo to handle the detail based on some size related math. Maybe something like this could help ... http://forum.unity3d.com/threads/tessellation-algorithms-for-polygons.228051/ Others options might be to use a smarter shader and a bump map with your sprite ... vertex ...


0

What is the correct multiplication order for the entity/model matrix? Scale then rotate then translate. Can i use a single matrix for all components of a entity or do i need to calculate in the width/height of the image/text/animation component. No each component part of your scene has its own matrix as the matrix represents the combination of ...


0

In the Animator put the 2 animations on different layers. You might have to play with the Weight and Blending options on them a bit but it should do the trick. The Unity3D documentation for the Animtation Layers resides at: http://docs.unity3d.com/Manual/AnimationLayers.html


2

Answering the question in your title, units in Unity are arbitrary. It's just a number; the most common interpretation is that 1 unit means 1 meter, but that's just the most commonly agreed upon value. You could decide 1 unit = 1 foot, or 1 unit = 1 inch, etc. As for why you would use the default setting of 100 pixels, it's because the physics system ...


5

100 pixels per unit would mean a sprite that's 100 pixels would equal 1 unit in the scene. It's simply a scale to say how many pixels equal one unit. This can affect things like physics. A lower pixels to units setting would require more force to move one unit than a higher pixels to units setting. Yes, there may be times where you'll want to manipulate ...


1

Your best bet is to not generate tiles but generate and manage chunks which contain tiles. If you think about chunks as a fundamental part of the design then the issue may go away. I faced a similar issue in 3d with building my voxel engine. You likely want to do something like ... class Map { public Size Size { get { ... } } public ...


1

To get to your main question, whether or not to influence the vertices before or during the shader, using a shader is preferred. If you know how to write a routine that can take into account the viewport and coordinate system, using a shader is preferred as it allows many sprites to be adjusted in parallel. Also, it ensures the "cosmetic" coordinates stay ...


5

Yes, they are more efficient. Depending on your specific hardware and driver, massively so. The basic idea is that you want to minimize state changes. Changing the active texture is a state change. In many cases the GPU can only handle rendering with a single state at at time. If you think of all the dozens/hundreds/thousands of shader cores that a GPU can ...


2

Yes, using texture atlases is more efficient than using individual images. It largely boils down to two things: The images have to be transferred onto the GPU in order to be drawn to the screen. Sending one large image is going to generally be faster than sending a ton of small images. State changes on the GPU are expensive, and switching textures is a ...


2

This is one of "truths of old days" and no longer important (that much important). While using one texture is definitely more efficient(switching texture, as every operation, introduces some overhead), on today's hardware is not that big difference and the extra performance is generally not needed. If you have hardware capable of rendering millions textured ...


0

Using Unity SpriteEditor cut out the sprites from the texture. In your script, add: public Sprite[] cardSprites; In script inspector set the size of 52. Then just fill it with sprites. You do that by going to project window and mouse-moving all sprites from sprite sheet. Now you have all your sprites individually. Having said that, you absolutely ...


0

For situations like this where I want an endless map with possibly negative coordinates, I use a hash table instead of an array. In JS, the easiest thing (maybe not the cleanest) is to use an Object: function Map() { var contents = {}; function index(x, y) { return x + "," + y; } function set_map(x, y, value) { ...


2

I think I would store two sets of coordinates. One used for drawing your objects DISPLAY POSITION and a second used for keeping a TRUE POSITION. This way you can draw sprites with rounded coordinates to eliminate the distortion caused by fixed size of your view area. But this also allows you to keep the exact location without influencing any of your ...


0

Most important thing i see about your issue is to keep a good separation of concerns. When you wonder about 'negative array indexes', you have an issue because you mix the concern of knowing where the player is, and the concern of how you build/store your world data ('map'). Have a camera object, that will define what is the center of the current view ...


0

You can build a graph data structure to handle the changes between chunks. Depending on exactly how you want the chunk boundaries to work, you may or may not need to render more than one chunk at a time. Many games have chunk boundary hallways that are Z or other sight-line blocking shapes. These are so that the game can fresh load the next chunk before you ...


0

You get those errors because those types (SpriteText.Anchor_Pos and SpriteText.Alignment_Type) don't exist. The correct types are TextAnchor and TextAlignment. static function AlignTxt(obj : GameObject, txtAnchor : TextAnchor, txtAlign : TextAlignment) { obj.GetComponent(SpriteText).anchor = TextAnchor.txtAnchor; ...


1

You need to handle your map in chunks/tiles of fixed size.. and only keep the chunks in the immediate vicinity of your player actually on hand at any moment (out to whatever view distance you feel is reasonable) As the player crosses a chunk boundary, you add new chunks in the direction of movement, remove them behind the player, and keep going. If you are ...


0

I'll try to give a two-fold answer: On the one hand, giving a bit of source code as a MCVE. On the other hand, I'll quickly try to point out why implementing this on your own is a bad idea. I'll start with the latter. Why you should not implement it this way You mentioned in the comments I was always under the impression that this was a more efficient ...


-1

articles generally are not liked in Stack exchange but this is my go to blog post when trying to remember this http://www.david-amador.com/2010/03/xna-2d-independent-resolution-rendering/


1

The question appears to be about how to go about selecting the correct tiles after generating a map, so that is what I'll answer. What you are talking about is called "autotiling" or "auto tiling" (depending on who you ask). Here's a simple-ish method for handling that: Given a single tile, we can find it's neighbors. Each tile then has a 4 bit state for ...


0

A common technique is to construct your maps from premade sections of n*n tiles which can fit together in different ways ("super-tiles" if you would like to call them that way). My favorite example for this is the good old X-COM: UFO Defense. They become very visible on the overview map, especially in the "farmland" biomes: When you want your map to be ...


0

For random tile generation, using a cellular automata algorithm is a good approach. http://www.roguebasin.com/index.php?title=Cellular_Automata_Method_for_Generating_Random_Cave-Like_Levels This is a good tutorial on the basic idea. Essentially you have some some random (or noise) function that generates initial tiles. Then the process gradually groups ...


0

I believe your character is more rolling than sliding, since it have circle collider. You may try to set large angular damping for character's body when it receive no control forces.


0

I think the easiest and most natural approach to resolution independent layouts is a relative (percentage) scheme. So from the start do not work with the real resolution but only in a uniform [0,1]x[0,1] square wherever possible. That means that for a given screen_size and a given object_size and a given relative position (px, py) (for example (0.5, 0.5) ...


1

I suspect your issue lies in the way a sprite batch works in MonoGame. The performance cost is coming from using different textures for each tile. Let's take a peek into the MonoGame source code and see what's going on. If you follow the code down through SpriteBatch.End you eventually end up in the SpriteBatcher.cs class around about here: ...


0

OK, after much fiddling and reading and re-reading of my and others' code, I've figured it out. If anyone sees anywhere I could improve this or sees any issues, please do let me know. Also, I hope that this saves somebody out there from the same frustration that I dealt with, lol. As I'd discovered, it would only work right on one axis at a time. The key ...


1

It's because of the variable IsOnGround and duration of jump key. Imagine this, no matter how fast you are. Update will be called 60times a second. That makes jump key true for more than a instance. Also it takes player time to achieve lift off making isOnGround true for more than one instance . Hence the inconsistent jump, try switching isOnGround to off ...


0

You could use a different approach for your list. Linked list. where each item hold a pointer to the next item in list. Insertion and removal cost is O(1). This is not cache friendly though, but you can try. Better sorting methods, e.g. if you use a bubble-sort, you can pick a much better algo that suits your case better (single insertions/removals don't ...


2

The answer to this question here should help explain how to use the GetData function. Basically, the data is stored in the return array from the GetData call is formed by reading the 2D texture from left to right, top to bottom, transforming it as follows: AAAA BBBB => AAAABBBBCCCCDDDD CCCC DDDD To determine where a given pixel in the 1D array is, we ...


1

Though Fault's comment is correct, what I usually do is to store the rotation and translation and then recreate the view matrix when required. (Full article here). The gist of the idea is: (btw the type of camera you are creating is often referred to as an Arc-Ball camera.) public class ArcBallCamera { public ArcBallCamera(float aspectRation, ...


1

When you starts going upwards you can start counting X from 0 to 90. For example you can increase X by 1 every 16 ms (for example). Then you can use X to use appropriate shipX frame. When you stop going upward then decrease X from current value to 0 (for example 2 by every 16 ms). Then the ship should back to its prime position softly.


-1

Use ccsprite with ccbadgenode in order fire number of frame of spite with moveto postion can change each frame interval with time .cccallfuntion is -(void)playStarAnimation { Animation *anim = [Animation node]; sp = [anim playAnimCCSpriteWithFileName:@"STARS~ipad" frameName:@"STARS" Layer:physicsLayer From:1 To:42 Delay:1.0/20.0 Loop:4 ...


1

Is there a way I could speed up things? No, there isn't. The slowest part of your system is the time it takes for the image to be displayed on the monitor, which presumably is in the vicinity of 24 milliseconds. (The monitor takes 16 milliseconds to draw the frame, plus 8 milliseconds because on average the monitor will be halfway through drawing a ...


0

From what I know the fastest way to render something in SDL 2.0 is using textures. You can use SDL_BlitSurface so you don't need to use renderers and convert to textures but that is slower and it is also a bad habit to use it. I would say to stick with textures because it is probably the fastest way to do it. Plus that it is also not so much harder to use ...


2

Add a flag to determine if the player has been stopped. At that point, stop setting the players position to the camera's, and instead some other input. public float speed; public test testing; bool stopped = false; // Use this for initialization void Start () { speed = 10f; testing = Camera.main.GetComponent<test>(); } // Update is called ...


0

With just a couple of slight rearrangements, you could have: float a = (transform.position.x - Camera.main.transform.position.x) * Main.scale; float b = (transform.position.y - Camera.main.transform.position.y) * Main.scale; onscreen = a > -width && a < GameView.width && b > -height && b < GameView.height; It will ...


1

Keep an "on-screen tiles" collection that you update each time the camera moves and each tile has a reference to the objects in it. This was you only need to update the objects referenced by the tiles that are on screen (or just outside).


4

You should be using layers. That is you have a naked character sprite. On top of that you add layers for hair, armor, gear, weapons. Depending on your actual game, you might do that in generic form, or split in parts or even add skeletal system. For example in Diablo 2 character was split into parts that were combined: Here's another example of ...


12

Yay I found a research paper! In terms of computational cost Shadow Mapping seems pretty clear winner. Algorithm used can be found here and a C# implementation can be found here, relevant bit below. #region FOV algorithm // Octant data // // \ 1 | 2 / // 8 \ | / 3 // -----+----- // 7 / | \ 4 // / 6 | 5 \ ...



Top 50 recent answers are included