• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Moe091

Best method for implementing a tile engine in java

3 posts in this topic

I need advice for a game I'm working on.

In terms of graphics it'll be basically the same as a square-tiled rpg, I'm thinking about how I wanna write a tile engine and I have a few different ideas in my head, I can't figure which one would be best or if there is an alternative method I'm not thinking of. Here are a few of my ideas:

(one thing to note, the map will be tile based but movement wont be restricted to being on a specific tile, you can move pixel by pixel)

have an array(either 1 or 2 dimensional) of integers, storing a 'tile id' for the tile at that location, then as part of the map file store the different tiles and there id's, with all the information for that tile that isn't going to change(layers, spawn points, collision, triggers, etc) and of course the tile image(s). then you just have to loop through the array and do a calculation based on the array index to find out where it goes and draw the tile stored in the Tile file that correlates to that index number.

this next one sounds easiest but idk if it's efficient/practical. Have the tile editor save the map as one big image, and have a second black and white version(white representing collidable areas) to use for collision detection(by drawing a collision box for the player in a color an checking for overlapping or something) then have a 3rd part saved which holds locations of all spawn points and triggers and interactive stuff like that, gives there location size and points to either a script or an object that defines its behavior. I could then have a Jpanel hold the entire map and move it around as my char moves so that the area around me is what's inside the JFrame and being rendered. I wonder if this will be inefficient because it's trying to render the whole map, not just what's visible. I never looked into collision detection but I have a vague idea of how I would get that system to work.

or I could do the same thing as above, except without a huge JPanel. Just have the map stores as an image and copy the area around my character to the JPanel with drawImage().

can anyone comment on the pros/cons of these methods, give advice for implementing any of them, or suggest an entirely different method?
1

Share this post


Link to post
Share on other sites
Moe091,

I'm also working on figuring out how to start a tile engine for my next game. Right now I'm leaning towards creating a very simple 2d array that will allow me to place tiles based on 'id'. For collision detection, maybe some sort of hash with the id as the key and a boolean as the value would solve that problem.

Another consideration is whether you plan to have a viewport or not. In my game, the character will be moving to different levels or maps, so I'm also trying to figure out how I would transition between screens.

Thanks for posting this question, because I need some help with it as well.
0

Share this post


Link to post
Share on other sites
The way I did it when I made a 2D Tile engine was by having an 2D array of Tile objects:
Tile[][] tile;
Then you would have an image where 1 pixel represents a tile and the RGB values represent what image and type of tile it is.
This makes it easy to make maps for instance to load up a map in the engine all you would have to do is:
tile = new Tile[mapImage.getWidth(null][mapImage.getHeight(null)];
tile.setMap(Image mapImage);
The setMap method would do something like:

for(int x etc etc){
for(int y etc etc){
int pixel = (buffered image version of mapimage).getRGB(x,y);
int r, g, b;
r = insert red algorithm here;
g = insert green alg here;
b = insert blue alg here;
int val = r + g + b;
switch(val){
case 1:
tile[x][y] = new ChildOfTileClass();
tile[x][y].setPosition(x * tilesize, y * tilesize);
break;
}
}
}

You could make a map editor if you wanted and it would be very easy.
In the engine I made you could just upload any image and it would convert to a map in the game.
To have tiles that are collide able you could do something like:
if(b == 0){
tile.setCollideable(true);
}else{
tile.setCollideable(false);
}

Probably not very resource efficient but is easy to program with and very flexible.
1

Share this post


Link to post
Share on other sites
Oh and I forgot to say that doing it with int ID's aren't relatively good because if you wanted to do an effect that effects the player like:
Player.speed - 1
then you would have to do this:
if(Player.getStandingTileID == some id){
player.setEffect(derpington)
}
instead you could do:
public class SlowTile extends Tile{

@Override
public void effect(Player player){
player.speed - 1;
}

}
Doing this could mean even more and more complicated effects.
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0