Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by westwind · Mar 22, 2013 at 08:04 AM · 2dtexture

Tiled Map Display Problem

Hi,

I load a tiled map made by Tiled Map Editor, but there are black edges around each tile, how to fix it?

alt text

The script I used is similar to UniTMX, here is the generating uv part:

     private List<Vector2> GenUV (ref TileSet tileset)
     {
 
         List<Vector2> uv = new List<Vector2> (); 
         int horizontalCellCount = (tileset.SourceWidth - tileset.Margin) / (tileset.TileWidth + tileset.Spacing);
         int verticalCellCount = (tileset.SourceHeight - tileset.Margin) / (tileset.TileHeight + tileset.Spacing);        
         float cellWidth = ((float)(tileset.TileWidth) / tileset.SourceWidth);
         float cellHeight = ((float)(tileset.TileHeight) / tileset.SourceHeight);
         int dataValue;
         for (int y = 0; y < Height; y++)
         {
             for (int x = 0; x < Width; x++)
             {
                 if (Data[y, x] != 0)
                 {
                     dataValue = Data[y, x] - tileset.FirstGID;
                     int posY = dataValue / verticalCellCount;
                     int posX = dataValue % horizontalCellCount;
                     float u = ((float)(tileset.Margin + (tileset.TileWidth + tileset.Spacing) * posX) / tileset.SourceWidth);
                     float v = 1.0f - ((float)(tileset.Margin + (tileset.TileHeight + tileset.Spacing) * posY) / tileset.SourceHeight);
                     uv.AddRange (new Vector2[] {
                         new Vector2 (u, v),
                         new Vector2 (u, v - cellHeight),
                         new Vector2 (u + cellWidth, v),
                         new Vector2 (u + cellWidth, v - cellHeight),                                                                
                     });
                 }
             }
         }
         return uv;
     }

My tileset has 4 pixels for both spacing and margin.

Thank you for your help.

screenshot.png (322.5 kB)
Comment
Add comment · Show 8
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image sdgd · Mar 22, 2013 at 08:33 AM 0
Share

do you have edge on the texture?

if you do than that's normal

avatar image westwind · Mar 24, 2013 at 05:30 AM 0
Share

Thanks for your reply, sdgd. Here is my texture: alt text

As you can see there is no edge. I used TexturePacker to create this texture.

spritesheet-hd.png (48.2 kB)
avatar image Kajos · Mar 24, 2013 at 08:22 AM 0
Share

Try setting spacing and/or margin to zero and see what that gives you.

avatar image westwind · Mar 25, 2013 at 08:03 AM 0
Share

I tried to use a texture without spacing and margin, but there are still edges. Here is a screenshot: alt text

screenshot.png (325.1 kB)
avatar image Kajos · Mar 25, 2013 at 10:56 AM 0
Share

Are you using shadows/baked shadows? What happens when you set the tiles to simple diffuse?

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by westwind · Mar 30, 2013 at 02:49 AM

Hi, I've found a solution. It seems a texture problem. I found someone asked a similar question at here: link text

However, the answer doesn't work for me. Instead, I found if I set the texture's Filter Mode to Point, there will be no dark lines. I don't know why, but it dose solve the problem.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

12 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

animation 2d platformer 2 Answers

Crunched texture compression - when to use? 2 Answers

Cheapest/Easiest way to just draw a bunch of pixels right to the screen 0 Answers

2D cube material pattern not repeating 1 Answer

How to "paint" the terrain in a script? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges