Hi !
Featured games (84)
games approved by the League of Dukes
Games in Showcase (601)
Games in Android Showcase (171)
games submitted by our members
Games in WIP (649)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Single Minecraft-like tileset  (Read 1819 times)
0 Members and 1 Guest are viewing this topic.
Offline nhmllr

Senior Devvie

Medals: 1
Projects: 3

slow and steady...

« Posted 2012-06-07 17:32:25 »

I am making a game with a grid based world.
I already have the code for running around and whatnot working.
However, there's something I want to learn how to do.

Different maps of my world require different tiles
So a beach might require sand tiles and palm tree tiles, while a forest might require grass and maple tree tiles
The thing is, sand tiles are functionally identical to grass tiles as a "floor", and palm trees are the same as maple trees as a "wall"
So I was wondering if there were ways to "clean up" some of my code

I know that in Minecraft, all of the block textures are derived from one picture

I assume that in the code, this singular picture is broken up into many different smaller textures
I'd like to do that

My grand idea is that I'd have one tileset for a beach, one for a forest, one for a dungeon etc.
So... how can I do this? How have people done it in the past?
(I'm using the standard LWJGL and Slick-Util)

Offline davedes
« Reply #1 - Posted 2012-06-07 19:05:33 »

This is very easy, it just takes a bit of understanding of how OpenGL textures and texture coordinates work.

In short, if you're rendering a textured quad (a pretty standard way of drawing sprites using Slick-Util) then you will probably be specifying texture coordinates [0,1] or something similar. If you only want to render a region of the whole texture, you have to specify different texture coordinates for each vertex of your quad.

I'd suggest making yourself an Image or TextureRegion type of class. Example here:

This is done not just for the sake of organization, but also performance. Texture binds are relatively expensive in OpenGL, so the fewer binds you need per frame, the more performant your game will be. LibGDX has some good texture packing tools; either for use offline (i.e. pack separate images into a single PNG file) or in game, on the fly (i.e. at startup, load and pack multiple images into the same OpenGL texture).

EDIT: Regarding your question of different tilesets for different environments; if you organize your sprite types to be in the same spot between sheets (i.e. ground type in cell (0, 0), tree type in cell (1, 0), etc) then you can use the same texture coordinates between sprite sheets. The only thing that needs to change is the texture you bind before rendering.

Offline davidllanos22

Junior Devvie

Projects: 2

I'm just a learner!

« Reply #2 - Posted 2012-06-07 22:04:57 »

If you are using slick is very simple:

Load your image and make a spritesheet:

public class Resources{
//definde image
private Image img;
//define spritesheet
public static SpriteSheet tiles;

public static void load(){
//load image (file location,image flipped?,filter)
img=new Image("data/images/tiles.png",false,Image.FILTER_NEAREST);
//load Spritesheet (image ,width of the tile,height of the tile)
tiles= new SpriteSheet(img,16,16);

Call it in the main class:

public class Main extends BasicGame{

public void init(GameContainer gc){


And for draw one image of the spritesheet is very simple. Once you have loaded it you can call it from wherever you want:

public void render(Graphics g,GameContainer gc){
//x=xtile of the sheet y= ytile of the sheet

I hope it's understandable Smiley

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline nhmllr

Senior Devvie

Medals: 1
Projects: 3

slow and steady...

« Reply #3 - Posted 2012-06-08 03:29:09 »

Thanks to both of you! I spent some time, and looking at your guys' example code, I got it to work!
It also simplified my code tremendously
Thanks again
Pages: [1]
  ignore  |  Print  
You cannot reply to this message, because it is very, very old.

Riven (24 views)
2015-07-27 16:38:00

Riven (14 views)
2015-07-27 15:35:20

Riven (19 views)
2015-07-27 12:26:13

Riven (9 views)
2015-07-27 12:23:39

BurntPizza (24 views)
2015-07-25 00:14:37

BurntPizza (36 views)
2015-07-24 22:06:39

BurntPizza (20 views)
2015-07-24 06:06:53

NoxInc (23 views)
2015-07-22 22:16:53

NoxInc (15 views)
2015-07-22 22:13:39

Jesse (36 views)
2015-07-22 03:10:36
List of Learning Resources
by gouessej
2015-07-09 11:29:36

How Do I Expand My Game?
by bashfrog
2015-06-14 11:34:43

List of Learning Resources
by PocketCrafter7
2015-05-31 05:37:30

Intersection Methods
by Roquen
2015-05-29 08:19:33

List of Learning Resources
by SilverTiger
2015-05-05 10:20:32

How to: JGO Wiki
by Mac70
2015-02-17 20:56:16

2D Dynamic Lighting
by ThePixelPony
2015-01-01 20:25:42

How do I start Java Game Development?
by gouessej
2014-12-27 19:41:21 is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!