# Tag Info

0

To help you with collision : There are ways to check for pixels changing color(being drawn over eachother) but I don't use that. I give all object in the game a Bounds Property. The Bounds is a Rectangle that is at the position of the object(enemy/character). Rectangles have a method .Intersects that allows you to see if two rectangle are intersecting. ...

0

You could Create one Sprite Card Object. Give it the the four suit textures, face card textures, and card background texture. Example : for the 7 of spades you would draw the spade texture at 7 different locations with a white texture of a card in the background, and use DrawString to Draw the 7. That way you could (in your game class) say Card card = new ...

1

[EDIT] As your question, now clearer seems to be more about design and not so much a technical question I change my answer a bit. Your first attempt was the right one. Your sprite contains a drag&drop component. But it's necessary that it also contains the prefab it will instantiate once dropped in the game world. The main design is, from an inventory ...

0

I wouldn't use any permanent collision box that's moved around or anything similar. Instead, just play the attack animation and pick one specific frame where you're looking for collisions inside a specific area. Since I assume the overall attack animation will be rather short/fast, there shouldn't be any way to notice any difference. For example, the ...

0

After experimenting with my code for like 3 hours, I found the solution myself:- Before going to a different state, use the input.clearKeyPressedRecord() to clear all previously recorded key-Presses, or else even after changing a state, previously stored keyPress event will cause problems. So instead of doing this, public void changeState(GameContainer ...

3

Rigidbodies can be said to operate in two modes: Non-Kinematic has physics driven movement, the physics engine will consider any forces brought to bear on the object to calculate and apply changes to velocity, rotation and position. Kinematic lacks physics driven movement, the physics engine will not cause this object to move and any forces on the object ...

1

yeah, all solutions have already been made... i'll just add some more code (i'm rather from stackoverflow ^^) assuming you're using bounding box assuming you use plain java (java.awt) . List<Shape> shapeList = ...; //you know where you get them Shape exampleShape = shapeList.get(0); Rectangle2D boundingBox = exampleShape.getBounds2D(); see ...

0

You can use a simple shader for this, but I wouldn't do so, simply due to the fact that you're doing simple tinting with one color (or shades of one color) only. The Unity script above would work with some modifications, but you'll have to keep in mind that there's additional overhead/metadata in there that doesn't belong to the actual GLSL code. What I'd ...

0

To answer your question directly, it is possible to set the scene/game windows to enable gismos for your colliders but they will only be displayed when that gameobject (or a parent) is selected in the hierarchy. This can be improved by attaching a script that implements OnDrawGizmos(), as an example here is an implementation that would visualize a ...

1

If you know the canvas is a rectangle then this simplifies to the case of checking if the bounding rectangle of the shape being drawn is contained within the canvas' rectangle. That's a fairly efficient check to run, and (generally) finding the bounding rectangle for your shape should be fairly easy (just finding the minimum and maximum x and y coordinates) ...

0

I found the solution, I had to change this line: glm::mat4 MVP = Model * ViewProj; To this line glm::mat4 MVP = ViewProj * Model; I made some research and it seems that in DirectX its the other way around.

3

As already pointed out in the comments and answer: This can be arbitrarily complex. Particularly, depending on the exact use case and performance requirements, you can employ some rather sophisticated data structures in order to make these tests fast. The bounding box test is the simplest one that should be done in any case (and in fact, could already be ...

3

A few things catch my attention off the bat. First: filedata = sr.text.Split('\n').Select(s=>s.Split(',').ToList()).ToList(); Feels highly dubious to me. Are you sure this is doing what you expect it do be doing? Second: float halfWidth = mainCamera.aspect * (mainCamera.orthographicSize/100); float tempYOffset = ...

5

I have good news and bad news for you: The Bad News: I don't know or remember any Java library that does what you want The Good News: It's really easy to implement this type of algorithm yourself! Here's a couple, you can mix them to optimize your collision detection depending on the type of shape. BB Collision Detection You can imagine a box around ...

0

[EDIT: as I don't know what lib you're using, and as this question is not specific to Java, my answer is in pseudo-code.] If I understand your question correctly, atan2 is not what you're looking for. What you want to achieve is moving something (which has coordinates) from one point to another according to time. You just need to compute the vector between ...

0

Suppose the projectiles curret position is $(x,z)$. Then, in each step, you let $x_{new} = x_{old} + t \cos(\theta)$ and $y_{new} = y_{old} + t \sin(\theta)$ where $\theta$ is the angle you found, and $t$ is some small number (depending on the number of milliseconds since last update, for example).

0

The problem is your World matrix multiplication order. What you do is W = T * R * S; where W is the world transform, T is translation, R is rotation, and S is scaling. You should instead use: W = S * R * T. THis is because matrix multiplication is not commutative. Hope that helps.

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

Top 50 recent answers are included