Adam's Lair Forum

game development and casual madness
It is currently 2019/12/12, 00:11

All times are UTC + 1 hour [ DST ]




Post new topic Reply to topic  [ 25 posts ]  Go to page 1, 2, 3  Next

Would you use TileD for your projects?
Yes, been using it long time now. 0%  0%  [ 0 ]
Yes, I checked it out and it feels great. 67%  67%  [ 2 ]
Not sure, I'll think about it. 33%  33%  [ 1 ]
No, I have another program/system. 0%  0%  [ 0 ]
Total votes : 3
Author Message
PostPosted: 2015/11/20, 22:50 
Member
Member
User avatar

Joined: 2015/10/29, 18:52
Posts: 69
Location: Finland
Role: Hobbyist
Hey guys!

I've started creating a plugin that will support TileD tilemaps in your games! So far I get all the XML-data loaded - I think?

See the sources at GitHub!

Here's a boring glimpse of the progress:
http://puu.sh/lsDZB/633ef803de.png

...and ^that data "compiles" to this:
http://puu.sh/lvXAt/cba4d0bedb.png

The plugin will be supporting everything TileD has to offer in it's format.

Feature list:
  • Tilesets used in the tilemap are loaded automatically (must be loaded in the Project View)
  • Terrain types: TileD's custom terrain types with collision detection - you can determine what type of terrain your object is walking on!
  • Collision detection - plugin will build necessary shapes for the tilemap, including custom terrain tiles!
  • Fast rendering - plugin will use the low-level stuff for performance!
  • More to come...

Will update more soon!

_________________
.
..
...
....
What?


Last edited by misthema on 2015/11/23, 19:01, edited 2 times in total.

Top
 Profile  
 
PostPosted: 2015/11/21, 04:35 
Forum Adept
Forum Adept

Joined: 2014/12/13, 00:11
Posts: 398
Location: Brazil
Role: Gamer
Nice! I was doing the same too a few months ago, but I got stuck at the rendering part. If you need, here's my wip plugin.

_________________
I only know the basics of C#. I have no advanced knowledge.


Top
 Profile  
 
PostPosted: 2015/11/21, 09:57 
Member
Member
User avatar

Joined: 2015/10/29, 18:52
Posts: 69
Location: Finland
Role: Hobbyist
RockyTV wrote:
Nice! I was doing the same too a few months ago, but I got stuck at the rendering part. If you need, here's my wip plugin.

Great! As far as I looked the code, it'll help me with the Editor-side stuff which I'm completely lost with... :D
Thanks!

_________________
.
..
...
....
What?


Top
 Profile  
 
PostPosted: 2015/11/21, 11:58 
Member
Member
User avatar

Joined: 2015/10/29, 18:52
Posts: 69
Location: Finland
Role: Hobbyist
Created a git repository for the sources! Link updated in the first post.
All ideas and comments about the code are welcome!

_________________
.
..
...
....
What?


Top
 Profile  
 
PostPosted: 2015/11/21, 12:48 
Forum Adept
Forum Adept

Joined: 2015/07/08, 16:41
Posts: 414
Role: Gamer
Good stuff you've got here. It's going to be useful, since I do use Tiled.

I'm especially interested in the final rendering code, as I've got this SVG rendering side project I'm trying to get to work.


Top
 Profile  
 
PostPosted: 2015/11/23, 19:16 
Member
Member
User avatar

Joined: 2015/10/29, 18:52
Posts: 69
Location: Finland
Role: Hobbyist
hsnabn wrote:
Good stuff you've got here. It's going to be useful, since I do use Tiled.

Thanks! Good to hear. :)

hsnabn wrote:
I'm especially interested in the final rendering code, as I've got this SVG rendering side project I'm trying to get to work.

I'm going with the low-level stuff Duality has to offer. Here's what I have so far (it's working, but only shows white tiles hehe):
Code:
public void Draw( IDrawDevice device )
{
   if( GameObj == null || !_loaded || Layers == null || Layers.Count == 0 )
      return;
   
   Vector3 tempPos = GameObj.Transform.Pos;
   float tempScale = 1f;
   device.PreprocessCoords( ref tempPos, ref tempScale );
   
   int halfMapW = W / 2;
   int halfMapH = H / 2;
   
   var vertices = new VertexC1P3T2[4];
   
   for (var i = Layers.Values.GetEnumerator(); i.MoveNext();) {
      
      var layer = i.Current;
      
      if (!layer.Visible)
         continue;
      
      for (int y = 0; y < H; y++) {
         
         for (int x = 0; x < W; x++) {
            
            // Is renderable tile available?
            int gid = layer.GetTile(x, y);
            if (gid <= 0)
               continue;
            
            // Get the correct tileset for this GID
            var tileset = TiledTileset.FindByGID(gid);
            if (tileset == null)
               continue;
            
            
            
            int tileX = (gid - tileset.FirstGID) % tileset.W;
            int tileY = (gid - tileset.FirstGID) / tileset.W;
            
            var uvRect = new Rect((tileX * TileW) / tileset.WPixel, (tileY * TileH) / tileset.HPixel, (tileX * TileW + TileW) / tileset.WPixel, (tileY * TileH + TileH) / tileset.HPixel);
            
            int posX = (x - halfMapW) * TileW;
            int posY = (y - halfMapH) * TileH;
            
            // Top-left
            vertices[0] = new VertexC1P3T2();
            vertices[0].Pos.X = posX - (TileW / 2);
            vertices[0].Pos.Y = posY - (TileH / 2);
            vertices[0].Pos.Z = tempPos.Z;
            vertices[0].TexCoord = uvRect.TopLeft;
            vertices[0].Color = ColorRgba.White;
            
            // Top-right
            vertices[1] = new VertexC1P3T2();
            vertices[1].Pos.X = posX + (TileW / 2);
            vertices[1].Pos.Y = posY - (TileH / 2);
            vertices[1].Pos.Z = tempPos.Z;
            vertices[1].TexCoord = uvRect.TopRight;
            vertices[1].Color = ColorRgba.White;
            
            // Bottom-right
            vertices[2] = new VertexC1P3T2();
            vertices[2].Pos.X = posX + (TileW / 2);
            vertices[2].Pos.Y = posY + (TileH / 2);
            vertices[2].Pos.Z = tempPos.Z;
            vertices[2].TexCoord = uvRect.BottomRight;
            vertices[2].Color = ColorRgba.White;
            
            // Bottom-left
            vertices[3] = new VertexC1P3T2();
            vertices[3].Pos.X = posX - (TileW / 2);
            vertices[3].Pos.Y = posY + (TileH / 2);
            vertices[3].Pos.Z = tempPos.Z;
            vertices[3].TexCoord = uvRect.BottomLeft;
            vertices[3].Color = ColorRgba.White;
            
            device.AddVertices(tileset.Image, VertexMode.Quads, vertices);
         }
      }
   }
}

Not sure if I'm doing this correctly, but at least the tiles are all in place. Just need a little tweaking with the UV-coordinates... :) Also, there's some funny bugs in it. :D
http://puu.sh/lvWZJ/f4d9b2c843.png

Also updated an image link to the first post about the data it stores atm!

_________________
.
..
...
....
What?


Top
 Profile  
 
PostPosted: 2015/11/23, 23:17 
Forum Adept
Forum Adept

Joined: 2015/07/08, 16:41
Posts: 414
Role: Gamer
Thanks for the code snippet: I'll try to check it out tomorrow, see if I can extract any information I can use for the SVG rendering project. It's kind of late right now.

Sorry, didn't mean to sidetrack this thread. As you were, folks.


Last edited by hsnabn on 2015/12/04, 11:52, edited 2 times in total.

Top
 Profile  
 
PostPosted: 2015/11/24, 19:03 
Member
Member
User avatar

Joined: 2015/10/29, 18:52
Posts: 69
Location: Finland
Role: Hobbyist
Progress! I've been a bit dumb lately and just now figured out what's wrong with my rendering; the UV coordinates where like this:
Code:
var uvRect = new Rect(
    (tileX * TileW) / tileset.WPixel,
    (tileY * TileH) / tileset.HPixel,
    (tileX * TileW + TileW) / tileset.WPixel,
    (tileY * TileH + TileH) / tileset.HPixel
);


...when they should've just been like this:
Code:
var uvRect = new Rect(
    (tileX * TileW) / tileset.WPixel,
    (tileY * TileH) / tileset.HPixel,
    TileW / tileset.WPixel,
    TileH / tileset.HPixel
);


It's hard to remember the difference between a Rectangle and something else! :)

Here's where I stand at the moment:
http://puu.sh/lxayZ/016939fd5b.png

_________________
.
..
...
....
What?


Top
 Profile  
 
PostPosted: 2015/11/24, 19:20 
Site Admin
Site Admin
User avatar

Joined: 2013/05/11, 22:30
Posts: 2073
Location: Germany
Role: Professional
Looks neat! It's kind of nice to see you working on a very similar thing than I currently am, feels a bit like I have company working on this :D Maybe we'll even be able to inspire each other a bit when it comes to feature coverage and API design, so we both get the best of our implementation. Will keep an eye on your worklog.

_________________
Blog | GitHub | Twitter (@Adams_Lair)


Top
 Profile  
 
PostPosted: 2015/11/24, 20:20 
Member
Member
User avatar

Joined: 2015/10/29, 18:52
Posts: 69
Location: Finland
Role: Hobbyist
Adam wrote:
Looks neat! It's kind of nice to see you working on a very similar thing than I currently am, feels a bit like I have company working on this :D Maybe we'll even be able to inspire each other a bit when it comes to feature coverage and API design, so we both get the best of our implementation. Will keep an eye on your worklog.

Thanks! I'd be more than happy to share my knowledge and vice versa. :)

_________________
.
..
...
....
What?


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 25 posts ]  Go to page 1, 2, 3  Next

All times are UTC + 1 hour [ DST ]


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group