A message from our CEO about the future of Stack Overflow and Stack Exchange. Read now.

Hot answers tagged

15

A simple way to achieve smooth lighting in a tile based game, is to draw a "lightmap" to a render target, and then drawing this render target over top your scene while alpha blending it. Your light map render target would be the size of your tile map, but in pixels. Each pixel would represent the light color of its corresponding tile. This render texture ...


7

In a case like this, you are going to want to Pool your world tiles. The idea is to pre-load a fixed amount of tiles that you will be re-using during the rendering of your world. When setting a tile into the world, you would typically set certain properties such as its position and texture. The rest of the object is already ready to go in memory. The ...


4

an engine agnostic way to do it is to use average light mapping. First, you need to generate a black and white map as a 2D array of booleans that is the size of the world where the blocks are True and empty is False. Like This(1 is black, 0 is white): Then you need to create a new 2D array that is the same size as the first array but is an array of ...


3

There are several options I can think of for associating each portal with a level, but the one you tried already is worthy of another go. Since you seem to have the Level class sorted nicely with Level.level1, Level.level2 etc., why not try a parent portal class with the different portals associated with the different levels in the same fashion? i.e. Portal....


3

There is never one best method. Only the method which works best for you and your game. But most tile-oriented game engines I know use a 2d array of integer values for each static map layer where each entry represents the tile-type at a given tile-coordinate pair. When your tiles have more properties than can be expressed with a single ID value, this 2d ...


3

Use floating point variables for entities' velocity and position. Use integers only when translating from world position to screen position. This way, your ship will move smoothly thorugh tiles. Also, add a Camera object to convert your world coordinates to screen coordinates as soon as possible.


3

The player should have a position, that can be any number, and a target position. When the current position is equal to the target position, check the input, and set the new target position accordingly. When the target position doesn't equal the current position (e.g. the player just started moving) move the current position closer to it. Make sure the ...


3

The reason there isn't a standard AABB or partition strategy for tile-based maps is that it's already easier to detect collisions against it than using AABBs. static int TILE_WIDTH=16, TILE_HEIGHT=16; Tile[,] map; class Character { int width, height; int x, y; bool isColliding () { for(var i = this.x; i < this.x + this.width; i += ...


2

You can choose the selection tool at the top, select all the tiles you want to move then press ctrl + x to cut and press ctrl + v to paste it where you want.


2

There is a reason the Thriving Ghost Town - villages represented by about 3 buildings and huge metropoles represented by about 20 - is such a common trope in games. Even a small town of realistic size would be far too large for most story-focused game concepts. You simply don't have the resources to add content to make all of it interesting, and even if you ...


2

You need a finer-grained method of moving your viewport. What you're doing now is essentially moving it by the size of a single tile every time you scroll, when what you want is a smaller increment. You do this by using a camera object represented by an x, y coordinate. Update its position with your scrollIncrement, then use that as the starting point for ...


2

It sounds like you already have a walk-map which says which tiles are walkable and which are non-walkable based on the terrain: the static walkmap. What you need is a second walkmap which tells you which tiles are non-walkable because of object presence: the dynamic walkmap. This map only needs to be recalculated when there is a change, so you can keep it ...


2

Very sorry for posting this without doing my proper research. I have found a program called Tiled. It does exactly what I want it to do (or close enough). When I save my finished tile map in Json format, I can open it up in a text editor and the array is right there in the "data" section.


2

I personally store my map data in a 2D array. map[y][x] It doesn't take up that much memory space. I mean, considering the amount of RAM current machines have, a few MBs (10-20 usually, but it depends on the size of the map, of course) is not a big deal. However I had concerns regarding the CPU usage. When rendering the map, I simply set the code to only ...


2

Looks like the rendering is off by 1 pixel (texel) for the flipped tiles or the source copy isn't flipped properly and catches most the next/previous tile in the tileset.


2

This looks like a job for Breadth-First Search. The algorithm in this case would work like this... Initialize a "Concentration" value for each tile to 0. For each source tile, initialize its Concentration value to your desired peak at that point, and add it to a Queue of tiles. While the queue is non-empty... i) remove the first tile from the queue and ...


2

I just feel like the algorithm I described will just create me a big spaghetti and it will take me a long road to complete Not really. Appreciate that there is a difference between compile time code written to achieve a task, and the instructions / paths taken in silicon when that code is executed. The former's quite condensed and simple to read; whereas ...


2

This tileset is famous because it was used in RPG maker VX. It seemingly consists of 6 tiles (2 by 3) and it even outputs tiles in that size, but it actually handles the tileset as if it was 4 by 6: You can then create every tile combination you need (which is 48 in most cases, source here, see the "The blob" section) For instance, creating a tile, that ...


1

It's pretty easy for a torch : using a custom pixel shader you calculate the distance between each fragment and the torch ; you can then calculate where the first dense tile that blocks light coming from the torch. You then calculate the distance where the light isn't blocked, multiply that by something < 1 so the torch doesn't light the sun, substract ...


1

Since you are talking about things blocking light, I'm assuming you have some model for how light should spread. For example everything with no blocks above it is completely lit, light spreads to all neighbouring cells but loses a certain amount of brightness. You should be able to implement those rules fairly easily on the software side at least the ...


1

You want to patrol between different locations, so you could just create a list of locations to visit in order (so you would have two locations for a move back and forth behavior). Once your actor has visited each location she can start over and return to the first location (or you could visit the locations in reverse order, or stop, or whatever). For ...


1

My solution, using the Brensenham algorithm as suggested by Sam Hocevar: public static Point[] brensenham(Point p1, Point p2) { final ArrayList<Point> points = new ArrayList<Point>(); // BRENSENHAM the line across final int dx = abs(p2.x-p1.x), sx = p1.x<p2.x ? 1 : -1; final int dy = -abs(p2.y-p1.y), sy = p1....


1

You may not need to include Occlusion Culling for a 2D game in Unity. Unity has a thing called FrustumCulling that hides any object not in view of the camera. In a 3D game, this isn't always ideal because the frustum doesn't account for distance, meaning that the game would still do things like render rooms behind doors that you can't technically see. ...


1

I think you need some documentation about collisions. It seems you want to check the collision between 2 hitbox on a 2D game: if (rect1.x < rect2.x + rect2.width && rect1.x + rect1.width > rect2.x && rect1.y < rect2.y + rect2.height && rect1.height + rect1.y > rect2.y) { // collision detected! } But you're ...


1

It is possibly a bug in the renderer. Try with and without WebGL. Also file a ticket on the issue tracker, providing the library version and minimal example to reproduce: https://github.com/melonjs/melonJS/issues


1

I can't comment yet, but it's probably the i++ in the first line of: for (int i = 0; i < Gdx.graphics.getWidth(); i++) { float y = PerlinNoise1D(i, 5f, 3); //other stuff } Since gradient noise is smooth at small intervals and abrupt at big intervals try and scale the value. Something like: float y = PerlinNoise1D(i * 0.1, 5f, 3);


1

If in general clicking the unit has no other use than selecting the tile, you could simply put the units on the Ignore Raycast layer so you can select directly the tile, in this case you can also attach a script on the tiles with the OnMouseDown function. If you want to access, in that way, the unit, you could maintaing of structure describing the tiles (so ...


1

You can initialize tile1, tile2 and tile3 and then you can add them to Array. tile1 = new Texture(Gdx.files.internal("grass.png")); tile2 = new Texture(Gdx.files.internal("dirttile.png")); tile3 = new Texture(Gdx.files.internal("watertile.png")); Here is how you will initialize Array: Texture[] tile = {tile1, tile2, tile3};


1

There are two ways you can perform collision detection: Check in advance whether there's a collision, then move First move, then check whether we're in collision and correct our position I'm not sure which way you're doing it, but given the fact you've said the entity is still intersecting the tile, I'm assuming it's the latter. If so, try correcting the ...


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