I am currently working on a simple, tile based rpg for android devices. I have stumbled across an error which I cannot solve efficiently.
Rendering Mechanics
I am currently using android's Canvas implementation to render everything in my game. I load the tile map into a bitmap using an open source TMX loader I found (not really relevant which one). The TMX loader loads the map file and produces a bitmap of the data stored in the tmx file. I am using Tiled to create my maps. The game first draws this bitmap produced by the tmx loader and then all other objects (including the player) on top of the map.
The Problem
As suggested in the title, this causes problems for semi-transparent tiles such as in this map:
The gray box is where entities collide with the well in the center of the map.
This map would be rendered like this:
The arrow is the player - part of the player should be drawn under the wooden beams of the well but still over the grass
I am struggling to find a way draw the player under the wooden beams of the well and over the grass. If anyone could give me some advice on how to do this, it would be greatly appreciated.
What I have tried
In another game I was developing, I created an object layer on tiled which would contain rectangles where the map should be drawn over the player. This worked although it caused the frame rate to drop quite a lot and it is difficult to precisely plot the rectangles over the required areas.
Related
(if you want to skip all this text you can go straight to the "short
question" version at the bottom)
Hello, guys!
I'm a beginner android developer currently creating a 2D RPG game. It basically consists of a map where the player walks (in 8 possible directions - west, north-west, and so forth) and interact with objects, creatures and others. The player's character walking animation consists of 9 sprites per available walking direction, totalizing 72 sprites. I have these sprites both in individual .png files as well as in an organized sprite sheet.
Until some days ago, I've been using the individual sprites in the game. I would load their drawable ID into an int[][] array and then, when each frame was going to be drawn, I would decode (using BitmapFactory.decodeResource() method) the necessary sprite and pass it to my renderer class that would then draw it.
After some thinking, I decided to try and use the sprite sheet instead, since the constant decoding of the sprites images was bothering me. For that, I decode the bitmap containing the sprite sheet with all the needed sprites and store it into a member variable. Depending on the required sprite for the next frame, my program would crop the required sprite out of the sprite sheet (previously saved into memory), resize it according to the player's devices needs and then pass it to my renderer in order to be drawn.
The problem is, I can't tell which method is more efficient! While it's easy to measure how much memory the decoded sprite sheet bitmap occupies (when stored in a member variable) in the player's memory (approximately 4MB), it's hard to know how much memory my program uses for constantly decoding small bitmaps, that corresponds to the individual sprites. Does anyone have any insights on how I could make this comparison? Or perhaps can share a previous experience related to this subject? I have searched for hours and, despite having found much useful information on how to load bitmaps efficiently and suggestions for libraries (like Glide, Fresco, and Picasso), I still couldn't find an answer nor better methods. Thanks in advance!
SHORT QUESTION: Is it better to constantly decode small bitmaps or to just decode a large bitmap once and then crop smaller bitmaps from it as needed?
P.S.: I'm aware that both presented methods for creating the animations in my game are probably inefficient. But, for the sake of my learning (my primary objective for creating this game), I don't want to use game engines, like AndEngine and libgdx. I also started learning OpenGL ES (which I've read provides great tools for loading and displaying bitmaps), but implementing it into my game would require a complete remake, in which I'm not interested right now.
I'm developing a strategy game for Android using libGDX. It's loosely based on Risk and requires irregularly shaped regions. However, I am having trouble deciding how to detect when a player touches a point within one of these regions.
As of now, all I have is a full map image. One idea that I've thought of is to separate the image and create individual images for each region. Then, I can arrange them like a puzzle and check if the player has touched an opaque area of one of the regions.
if your shaped regions are polygons defined as a set of points, you can use a algorithm to determine the point is inside or outsite like here.
or
i donĀ“t lerned java, but maybe exist a control like html5 canvas hitregion.
What is the best way to get around the max texture size in Libgdx? I currently have a 2048x2048 texture with an ortho cam zoomed in at 2x which serves as the "map" for my top down shooter. The problem is that 2048x2048 just isn't enough space for the player to move around in, so I need to expand the map without creating a huge texture. Am I going about this wrong? should I not just use a giant texture for the background?
Only some phones will support textures bigger than 2048x2048. This is a GPU hardware/OpenGL driver limitation and not the fault of LibGDX.
The most common solution is to build a map out of several smaller textures that can be repeated to create the illusion of a giant map. You don't just take the map of the world and divide it into 2048x2048 chunks, you instead have a bunch of tiles that are 32x32 pixels and represent things like grass, dirt, grass meeting dirt, etc.
This is why LibGDX has a maps package. See https://github.com/libgdx/libgdx/wiki/Tile-maps
Instead of trying to create the map programmatically you record the map in a text file and use a map loader at runtime. There are a couple of supported map formats. The best way to create the map files is to use a map editor like http://www.mapeditor.org/
I have a large tmx map which I made in Tiled. I am using libgdx to render the tmx map. I would like to know how can I render specific tiles. For example I have a 100x100 tile/tmx map. Player entity spawns in 10,30 (x,y) I only want to render around the location of the player entity (or for any entity, and control the seeing distance within the respective entity class). How can I use libgdx to selectively render like this? I tried setting rendering bounds to camera but not working like I want.
I want to be able to zoom in/out of overall map (which would look dark/completely blacked out) except for the parts where an entity sprite is located. Looking to maintain the fog of war around the entity sprite.. and multiple entities.
Should I pass renderer into the entity constructor? multiple cameras? How can I do a layered effect where i have another 100x100 blacked out tilemap on top of the actual map and have it so the alpha around entities is 0? (bear in mind im using tmx maps)
I'm not really sure if this is the place to be asking this but I was trying to use the program Tiled but I'm not sure where to start. I have looked at its documentations but it's not that useful as I already have some experience in using a tiled editor in a game engine (GameMaker), but I'm working straight up Java for this project.
How does the Tiled object layer work? Does it allow me to place enemies in the tiled editor that would show up and actually move in the game or are they just static images like a tile?
Also if it does allow what I programed for the enemy how do I use it?
Tiled allows you to edit layers of tiles and items. There's tile layers which represent a 2D grid of images, and item layers which are just polygons with properties.
After you create a map, its up to you to do something with that data. Tiled is not like GameMaker. All Tiled does is allow you to read, write, and edit data.
I recommend you use LIBGDX as a game engine, and Tiled to create your maps. LIBGDX has support for loading and rendering tiled maps.
To create enemies, you'd place some polygons, add attributes to these polygons, and create enemies based on these properties when parsing the Tiled map in your game.