Jump to content

  • Log In with Google      Sign In   
  • Create Account


having a bit of trouble splitting a tileset up


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
1 reply to this topic

#1 Dustin Booher   Members   -  Reputation: 100

Like
0Likes
Like

Posted 14 February 2012 - 11:59 AM

so im trying to split up a tileset into seperate tiles, ive done this before but idk what im doing wrong atm.


image_width = Switches.tileset.Width / target_cols;
                    image_height = Switches.tileset.Height / target_rows;
                    Color[] data=new Color[image_height*image_width];
                    Texture2D temp = new Texture2D(Switches.device, image_width, image_height);
                    Switches.images = new List<Texture2D>();
                    Switches.positions = new List<Vector2>();
                    for (int y = 0; y*image_height < Switches.tileset.Height; y++)
                    {
                        for(int x=0;x*image_width<Switches.tileset.Width;x++)
                        {
                            data = new Color[image_height * image_width];
                            Switches.tileset.GetData<Color>(0,
                                new Rectangle(x * image_width, y * image_height, image_width, image_height),
                                data, x*image_width + (y * image_width), image_height * image_width);
                            temp.SetData<Color>(data);
                            Switches.images.Add(temp);
                            Switches.positions.Add(new Vector2(x*image_width,y*image_height));
                        }
                    }

thats my code, in the example im use tile width/height is 32x32 and the image is 64x32 (only 2 tiles)

Sponsor:

#2 Dustin Booher   Members   -  Reputation: 100

Like
0Likes
Like

Posted 14 February 2012 - 12:20 PM

Okay I fixed it by changing

Switches.tileset.GetData<Color>(0,
new Rectangle(x * image_width, y * image_height, image_width, image_height),
data, x*image_width + (y * image_width), image_height * image_width);

to


 Switches.tileset.GetData<Color>(0,
                                new Rectangle(x * image_width, y * image_height, image_width, image_height),
                                data, 0, image_height * image_width);

but now its not reading my first tile at all, it just reads the second one twice.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS