About Monkey 2 › Forums › Monkey 2 Programming Help › Getting rid of the cracks? Tile Images…
This topic contains 9 replies, has 4 voices, and was last updated by
c0d3r9
9 months, 1 week ago.
-
AuthorPosts
-
July 14, 2018 at 2:17 am #15037
I’m having a bit of issues with cracks in my tile maps, any ideas of how to fix it?
Monkey12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182Namespace myapp#Import "assets/"#Import "<std>"#Import "<mojo>"Using std..Using mojo..Const VIRTUAL_SIZE := New Vec2i(320, 200)Class MyWindow Extends WindowField tiles:Image[]Field filterTextures:Bool = TrueMethod New()Super.New("Tile Test", 1280, 800, WindowFlags.Resizable)Layout = "letterbox-int"tiles = LoadSpriteSheet("tileset2.png", 48, 32, 32)EndMethod OnRender(canvas:Canvas) OverrideGameLogic()App.RequestRender()GameRender(canvas)EndMethod GameLogic()If Keyboard.KeyHit(Key.Escape)App.Terminate()EndEndMethod GameRender(canvas:Canvas)canvas.TextureFilteringEnabled = filterTexturesFor Local x:Int = 0 To Width Step 32For Local y:Int = 0 To Height Step 32canvas.DrawImage(tiles[14], x, y)NextNextEndMethod OnKeyEvent(event:KeyEvent) OverrideIf event.Type = EventType.KeyDown And event.Key = Key.Enter And event.Modifiers & Modifier.AltFullscreen = Not FullscreenEndifEndMethod OnMeasure:Vec2i() OverrideReturn VIRTUAL_SIZEEndEndFunction Main()New AppInstanceNew MyWindowApp.Run()EndFunction LoadSpriteSheet:Image[](path:String, numFrames:Int, cellWidth:Int, cellHeight:Int, prefix:String = "asset::")Local atlasTexture := Texture.Load(prefix + path)Assert(atlasTexture, " ~n Image " + prefix + path + " not found.~n ~n")Local images := New Image[numFrames]Local atlasImg := New Image(atlasTexture)Local columns:Int = atlasImg.Width / cellWidthFor Local i := 0 Until numFramesLocal col := i Mod columnsLocal x1 := col * cellWidthLocal y1 := (i / columns) * cellHeightLocal x2 := x1 + cellWidthLocal y2 := y1 + cellHeightPrint "i = " + i + ", x1 = " + x1 + ", y1 = " + y1 + " x2= " + x2 + ", y2 = " + y2images[i] = New Image(atlasImg, New Recti(x1 ,y1, x2, y2))NextatlasImg = NullReturn imagesEndPlace the image in assests folder or just download the tiletest.zip
July 14, 2018 at 3:38 am #15041This from discord. Make sure the spritesheet image is with the power of 2. So width and height 256*256 or 512*512. Textures and opengl thing.
July 14, 2018 at 3:45 am #15042Just tried using my SpriteTools Atlas class, and it fixes the problem by working its magic behind the scenes…
https://github.com/DoctorWhoof/spriteTools
Minimal changes to your code, and unchanged texture file.
Monkey123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960Namespace myapp#Import "images/"#Import "<std>"#Import "<mojo>"#Import "../spritetools"Using std..Using mojo..Using spritetools..Const VIRTUAL_SIZE := New Vec2i(320, 200)Class MyWindow Extends WindowField tiles:Image[]Field filterTextures:Bool = TrueMethod New()Super.New("Tile Test", 1280, 800, WindowFlags.Resizable)Layout = "letterbox-int"tiles = New Atlas( "asset::tileset2.png", 32, 32, 0, 0, TextureFlags.FilterMipmap ).CellsEndMethod OnRender(canvas:Canvas) OverrideGameLogic()App.RequestRender()GameRender(canvas)EndMethod GameLogic()If Keyboard.KeyHit(Key.Escape)App.Terminate()EndEndMethod GameRender(canvas:Canvas)canvas.TextureFilteringEnabled = filterTexturesFor Local x:Int = 0 To Width Step 32For Local y:Int = 0 To Height Step 32canvas.DrawImage(tiles[14], x, y)NextNextEndMethod OnKeyEvent(event:KeyEvent) OverrideIf event.Type = EventType.KeyDown And event.Key = Key.Enter And event.Modifiers & Modifier.AltFullscreen = Not FullscreenEndifEndMethod OnMeasure:Vec2i() OverrideReturn VIRTUAL_SIZEEndEndFunction Main()New AppInstanceNew MyWindowApp.Run()EndJuly 14, 2018 at 4:09 am #15043Tried the power of two by increasing the image (tileset2.png) to 256×256, but still had the gaps. I thought Monkey did that for you?? Maybe I’m thinking of BMX or MX1?
Ethernaut’s code does get rid of the gaps, but the seamlessness is not quite right now but better than the gaps

July 14, 2018 at 4:29 am #15046This is what I get when doing the tiling by hand in Photoshop:

Seems pretty close to what the Atlas did!
For tilemap work, check out “Pixel Edit“. It’s super simple, but has some killer features, like painting directly on the tile while you see the result in a tile map, etc.
<edit> If you zoom in, there’s indeed an odd edge interpolation going on… will investigate!
July 14, 2018 at 4:41 am #15047Argh, found a bug on my end! Will fix…
July 14, 2018 at 5:02 am #15048I’ve been using Pyxel Edit now for a while, it is awesome
Argh, found a bug on my end! Will fix…
Cool – I’ll keep an eye on your fix!
Thanks for helping
July 14, 2018 at 5:04 am #15049Ok fixed!
Instead of copying neighbor pixels, I copy the values from the other side of the tile (i.e. gap on the left edge of the tile gets the color values from the right edge).
On top of that, I also fill the pixels at the intersection of the gaps now, which something I didn’t do before because I’m lazy!
Updated here:
https://github.com/DoctorWhoof/spriteTools/blob/master/source/atlas.monkey2July 14, 2018 at 5:20 am #15050Looks perfect! I’ll test some more soon! Thanks a lot!
July 14, 2018 at 12:52 pm #15051with https://www.codeandweb.com/texturepacker
its possible to add a pixelborder to each tile on the spritesheet.
only a little tip
-
AuthorPosts
You must be logged in to reply to this topic.



