My problem is the I need to represent a length-changing floor using a Texture2D, which means a floor that the sides has the image of the sides, and in the middle it repeats the same 'middle' image, like so:
To achieve this, I get the 'left edge', the 'middle' and the 'right edge' textures, problem is I don't know how to merge them into one single texture2D,
It is important to do that at run-time because the floor length is changing (horizontally), I read you can do that using SetData but I have no idea how...
It is very important for me that it will act as one texture and not multiple texture parts because I am using Farseer Physics Engine to move the floor and use it.
I am using C# and XNA with Visual Studio 2010, I am an almost-experienced C# programmer,
Thank you!
This answer may help you. Either you should use HLSL for repeating your floor or you should draw your floor on a RenderTarget and save it as single Texture. Enjoy.
First, create a new Texture2D to serve as your floor texture, specifying the appropriate width and height. Then, get the data of the three textures you want to merge, using the GetData method. Finally, use the SetData method to set the data of the new texture as appropriate (check the link, you can specify the start index).
Warning: GetData and SetData methods are slow. If you need to create this texture only once per game (at the initialization for example), it's not a problem, though.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With