Publishing System Settings Logout Login Register
Browsergames: Creating a basic Isometric Map
TutorialCommentsThe AuthorReport Tutorial
Tutorial Avatar
Rating
Add to Favorites
Posted on June 8th, 2010
4101 views
JavaScript

5. Stylesheet

Now the stylesheet. I will explain on how to use spritesheets below the code dump.

html, body { 
margin:0px;
padding:0px;
color:#333333;
}
div#map {
width:600px;
height:400px;
margin:0px auto;
border:4px solid #CCCCCC;
background-color:#000000;
z-index:0;
overflow: hidden; }

div#map2 {
width: 800px;
height:250px;
border:5px solid #990000;
margin:10px auto;
overflow: hidden; }

div.content {
position: relative;
overflow: hidden; }

div.content div.tile {
width:64px;
position: absolute;
height:64px;
line-height:64px;
background-image:url('grass_and_water.png'); }

div.content div.tile:hover {
opacity:0.8;
-moz-opacity:0.8;
-webkit-opacity:0.8;
-khtml-opacity:0.8;
}

.grass_0 { background-position:0px 0px; }
.grass_1 { background-position:64px 0px;}
.grass_2 { background-position:128px 0px; }
.grass_3 { background-position:192px 0px;}
.grass_4 { background-position:0px 58px;}
.grass_5 { background-position:64px 58px;}
.grass_6 { background-position:128px 58px;}
.grass_7 { background-position:192px 58px; }

div#map div#content div.tile div.object {}

.npc_0 { background:transparent url('temple.png') top left no-repeat; position:relative;width:256px; height:128px;left:-128px;bottom:96px; }

This is actually very very easy. So we now the size of our tiles which are 64x64px in our case. The div.content div.tile sets the basic attributes of all tiles, width / height, absolute position and the background image, but no positions. So it will just show the upper left of the image and cuts it after 64px height and width.

This is where the other classes will be needed (.grass_0, .grass_1 etc) Those classes will be set by the tile variable of the game map array. However those classes just have one css attribute, the background-position. So for example .grass_1 uses 64px and 0px. This will show the second image from the upper left of the tiles image. Basically you're just giving coordinates for the upper left corner of the tile. This + tiles width and height will result in the wanted tile. Sounds much more complicated than it is. I think I added enough example tiles to make this clear.

Next Page
Pages: 1 2 3 4 5
Dig this tutorial?
Thank the author by sending him a few P2L credits!

Send
Balor

I'm a freelancing webcoder from germany next to Frankfurt. I'm developing web application solutions for mid-sized companies. I'm a coder with minor art skills.
View Full Profile Add as Friend Send PM
Pixel2Life Home Advanced Search Search Tutorial Index Publish Tutorials Community Forums Web Hosting P2L On Facebook P2L On Twitter P2L Feeds Tutorial Index Publish Tutorials Community Forums Web Hosting P2L On Facebook P2L On Twitter P2L Feeds Pixel2life Homepage Submit a Tutorial Publish a Tutorial Join our Forums P2L Marketplace Advertise on P2L P2L Website Hosting Help and FAQ Topsites Link Exchange P2L RSS Feeds P2L Sitemap Contact Us Privacy Statement Legal P2L Facebook Fanpage Follow us on Twitter P2L Studios Portal P2L Website Hosting Back to Top