Sign in to follow this  
Dustin Booher

having a bit of trouble splitting a tileset up

Recommended Posts

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


[CODE]
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));
}
}[/CODE]

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

Share this post


Link to post
Share on other sites
Dustin Booher    100
Okay I fixed it by changing

[color=#660066]Switches[/color][color=#666600].[/color][color=#000000]tileset[/color][color=#666600].[/color][color=#660066]GetData[/color][color=#666600]<[/color][color=#660066]Color[/color][color=#666600]>([/color][color=#006666]0[/color][color=#666600],[/color]
[color=#000000] [/color][color=#000088]new[/color][color=#000000] [/color][color=#660066]Rectangle[/color][color=#666600]([/color][color=#000000]x [/color][color=#666600]*[/color][color=#000000] image_width[/color][color=#666600],[/color][color=#000000] y [/color][color=#666600]*[/color][color=#000000] image_height[/color][color=#666600],[/color][color=#000000] image_width[/color][color=#666600],[/color][color=#000000] image_height[/color][color=#666600]),[/color]
[color=#000000] data[/color][color=#666600],[/color][color=#000000] x[/color][color=#666600]*[/color][color=#000000]image_width [/color][color=#666600]+[/color][color=#000000] [/color][color=#666600]([/color][color=#000000]y [/color][color=#666600]*[/color][color=#000000] image_width[/color][color=#666600]),[/color][color=#000000] image_height [/color][color=#666600]*[/color][color=#000000] image_width[/color][color=#666600]);[/color]

[color=#666600]to [/color]


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

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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this