- Home /
How to put specific shapes/textures instead of generating colors (C#)
Hello,
My problem is that I'm making pentomino-like game and I'm generating shapes from matrixes. Code works well, etc. But my problem is to add textures to them (2D plant-shape like figures). Is there any method to hardcode them or is this just wrong from the beginning and I should start with different approach and models of that pentominos?
Right now:
public void InitBlockTextures(int w, int h) //initializing block textures
{
green_texture = new Texture2D(w, h);
...
black_texture = new Texture2D(w, h);
CreateBeveledTexture(green_texture, 0, 1, 0);
...
CreateBeveledTexture(black_texture, 0, 0, 0);
}
public Texture2D GetBlockTexture(int color) //for each color we're getting texture
{
if(color==1)return green_texture;
...
if(color==8)return black_texture;
return null;
}
I used matrixes and colors generated that way cause it was pretty simple to program rotating options for something like this:
public class PentominoPieces //here we have pieces
{
...
int[,] P8R1 = new int[4,4] {
{1,1,0,0},
{0,1,1,0},
{0,0,1,0},
{0,0,0,0}
};
...
}
public int[,] GetTetrisPieceBitmask(int type, int rotation) //each rotation has specified bitmask
{
...
if(type==8)
{
if(rotation==1)return P8R1;
if(rotation==2)return P8R2;
if(rotation==3)return P8R3;
if(rotation==4)return P8R4;
}
But now it not looks that easy anymore and I'll be thankful for every help.
I know that I look like total n00b (and it's not far from there), but actually I answered much more qusetions than I asked (http://answers.unity3d.com/users/24865/mcdardy.html <- it's not my fault that I can't log in on that account) so I'll be glad if one of Great $$anonymous$$asters of Coding help me a little - pretty please :)
Answer by GwenoleGerard · Oct 08, 2013 at 07:46 AM
I'm not sure what you want to do (my english are very bad) but if you use a texture you create in script, you can use Texture2D.SetPixel, Texture2D.SetPixels and Texture2D.Apply to change with code your Texture, like said here
Edit: to load your own Texture, you can use Ressources.Load and do something like that:
Texture2D myTexture = Ressources.Load("YourPath/YourTextureName") as Texture2D
The example in the link show how apply directly the Texture on object's material and said "The path is relative to any Resources folder inside the Assets".
Hope it could help
Thank you, thank you, thank you for your answer, and don't worry bout your english - my isn't perfect also. I try to explain better:
What I have:
What I need:
https://lh6.ggpht.com/nu6Ffy1nfV77dapIYOnY6UJ5SQJ1Lxb0zRsRy$$anonymous$$rlUdz9YZrol8m3GrrAzsl7vTHQJwbC=w300 (not snakes though, but you can get the idea)
$$anonymous$$y prototype is working and is flawless, but I need to add those "custom plants shape like" textures and I don't know if I made the right approach... Any way to "hardcode" them (choosing from $$anonymous$$yProjectDirectory my png/gif) and bind to my shapes?
Thanks once again for your time
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Stirching textures together to make another one 0 Answers
Flip over an object (smooth transition) 3 Answers