Hot answers tagged

154

Figure out your bottleneck A few hundred moving objects should not be a problem. However, a few hundred colliding objects might be. It will take some testing, yet I believe the bottleneck you have are the collision. By the way, about how many objects are we talking? What is the platform? A hundred objects for a mobile game is not the same as a hundred for ...


70

First of all, that game mechanic looks like it could be super fun, so congrats on thinking of it! Here are two simple solutions that could be used independently or together to solve this particular issue: Remove Very Small Pieces There isn't much of a point to keeping around tiny pieces of collision that really won't impede the player or have any real ...


69

Very old games used a technique where only those parts of a frame are redrawn that changed on that frame. What I can remember, the game "Little Big Adventure" uses this technique (1994). But you can see that the game has for most of the time a static camera. only when you move out of the visible area the scene is redrawn. If you play the game you would also ...


63

I'd disagree with the accepted answer here. I'd call this an autotile, and not a 9-slice "9-Slice" (or 9-patch) is usually used to refer to a system where the content creator slices the image along 4 lines (not necessarily equally-spaced tiles). When rendering a rectangle, the corner slices are displayed at their native size, and the edges/center are ...


50

Large, open areas do not work very well in top-down 2d. Putting the player in such an area just disorients them. It is much better to use more complex areas which limit the way the player can navigate. So you need some other way to communicate the scale of the world to the player. A common way to do that is by providing them with a world map they can access ...


49

There is a very simple way achieving this with shaders, you need three* textures: empty health bar, health bar texture and mask with gradient of health distribution with one extreme(e.g. darkest not black or most transparent alpha value) on one end and the other on other end. It is best shown on image, I am currently unable do draw curved gradient only ...


47

OpenGL is quite appropriate for 2D games. Although it is generally used for 3D, the same functionality can be used for 2D games. That is to say, anything you can do with 3D OpenGL will be applicable with "2D" OpenGL. Some further information can be found at this location. 2D OpenGL is achieved in the same manner that 3D OpenGL is. 2D OpenGL is only the ...


44

I was about to post a link to the Asteroid Base blog on the Walker enemy when I noticed karmington already linked to the Gamasutra article in a comment. It's probably worth giving this a bit more visibility and explanation as an answer in its own right though. The trick is raycasts. These let your code scan along a line for a collision. To get the Walker ...


42

A common way this is done is using an indirect texture lookup in the shader to distort the display texture: Here I'm using a texture with some low-frequency colour noise (tiling smooth blobs of random colours), and scrolling it across the display geometry over time. Instead of drawing the colours from this texture, I instead take the red & green ...


40

A name that will give you actual results in Google is 9-slice. Another way to call it and ask Google about it is 9-patch. As per this chat discussion, 9-pane seems to also be used, but the almighty Google will not show you what you need, unless you're into windows or something. Thanks to Kevin and Josh in chat for that.


38

My first suggestion would be to just stick with A = Counter-clockwise and D = Clockwise movement. It is not very confusing and is pretty much the "standard" (i.e. most common) choice when it comes to orbital movement like this. Another way would be to change the way your game moves. Instead of moving the player when they are on a planet you could rotate the ...


34

The solution is actually simpler than expected. The trick is to use Minkowski subtraction before your hexagon technique. Here are your rectangles A and B, with their velocities vA and vB. Note that vA and vB aren't actually velocities, they are the distance traveled during one frame. Now replace rectangle B with a point P, and rectangle A with rectangle C =...


34

One of the best, and most used, algorithms I've seen out there is generating dungeons using Binary Space Partitioning. The best general explanation I've read is the one found in The Chronicles of Doryen (attached at the end for backup purposes) because explains the procedure without getting into the code, thus leaving the implementation to the reader. Two ...


34

Implemented mathematically, as a pixel shader: On the CPU, calculate HealthDirection and its' dot product with V2 On the GPU, calculate a normalized direction away from the centerpoint for each pixel. Compare each dot product to HealthDirections' to choose whether to shade "background", or in color. If you "inverted" this algorithm and worked from the ...


34

I think you'll have to take the box's movement into consideration. That is, only crush if the box is moving towards the player. This is similar to other problems in platformers, where the movement is important. E.g. for platforms that you can jump through and onto from below, don't check collision if the player is moving upwards. So a block can crush the ...


33

X = x*cos(θ) - y*sin(θ) Y = x*sin(θ) + y*cos(θ) This will give you the location of a point rotated θ degrees around the origin. Since the corners of the square are rotated around the center of the square and not the origin, a couple of steps need to be added to be able to use this formula. First you need to set the point relative to the origin. Then you ...


33

There's a solid overview of different popular tile combination patterns put together by Boris the Brave, building on some earlier work by Sean Howard. I'll briefly summarize the main categories these authors identify in case the links break in future, along with a few additions of my own. I recommend you read the original articles for the full details. Rug ...


32

2D Tiled games usually have more layers which renders in different layers - some renders in the background others above the player. That part of the roof renders above the player and that's why player can go behind that building. Here is the image example from my game to explain better:


32

Planning to grow: Hard-coded constants are fine for small projects but, eventually, as your software grows in size, you will wish you could change those settings without having to recompile everything. There are many times you will want to change settings while the game is running and you can't do that with hard-coded constants. CVars: Once your project ...


29

You can't. At least, not as a game developer. As a gamer, you can purchase more expensive keyboards with "anti-ghosting" features, but otherwise the limitation is part of the hardware itself, so there's nothing you can do in software to solve it. Check out this demo page to see how keyboard ghosting works, plus a demo: https://web.archive.org/web/...


28

Your RAM is your limit. The following tests were performed on a system with these specs: Intel i5-6600 16 GB RAM NVIDIA GeForce GTX 1070 Windows 7 Home Premium Here is a script I ran which grows a tilemap by filling it with a single tile (32x32 pixels). The Method Grow() adds another column and another row to the current map. The method gets called 100 ...


28

This is Matt, the creator of Trainyard. @DMGregory summoned me here! :) It sounds like you're working through the same issues I had to deal with. It's a tricky problem where there isn't necessarily a perfect solution. One thing to consider is the constraints of the problem. I was targeting a 50mm wide screen on the early iPhones, and Apple's recommendation ...


27

Have you considered that it looks very odd for a person to standing perpendicular to a slope? You need to be upright to stay in balance. Some alternatives: Treat his feet as a separate object and rotate them to be parallel to the slope. (A raycast will find the angle's normal, as dnk described. The angle for the feet is that + 90°.) Fake it, by moving ...


27

I think not overthinking this issue will give the best results so I would just implement a simple key-value saving system into your game that you store along your other save data and then load on-demand when you need to access a previous state. The flow could look something like this: Load level from file Before placing a tile / object check if it has a "...


26

There is a simple way to do exactly what you want. In addition to a float velocity you'll need to have a second float variable which will contain and accumulate a difference between real velocity and rounded velocity. This difference is then combined with velocity itself. #include <iostream> #include <cmath> int main() { int pos = 10; ...


25

Well there are a couple ways of thinking about this. One is to list the specific features the engine should have (what you've asked here.) However the other way is to just start making games without worrying too much about the "engine", and then features you find are being reused between multiple games (in particular, features used in every game) you should ...


25

dot(A,B) = |A| * |B| * cos(angle) which can be rearranged to angle = arccos(dot(A,B) / (|A|* |B|)). With this formula, you can find the smallest angle between the two vectors, which will be between 0 and 180 degrees. If you need it between 0 and 360 degrees this question may help you. By the way, the angle between two parallel vectors pointing in the same ...


23

OpenGL as the name states is a graphics library. Although it is developed with 3d in mind, there are no hardcoded assumptions in the library that you'll be using 3d. Moreover, thanks to it's 3d capabilities, several things that would be hard to do in a strictly 2d approach are trivial. Examples: Z-sorting is simplified by using 3d coordinates the depth ...


22

I haven't looked at specific implementation of A* by Aaron but with a normal A* you could include the 'block tower' as passable terrain but update the heuristic so that the 'cost' is much higher than a normal tile (so that AI will evaluate whether it is easier to destroy the block and continue or simple go around via the path that is not blocked). Then you ...


21

In various Super Mario games, it's called a pit, abyss or bottomless pit. Bottomless Pit is also a TV trope.


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