Quantcast
Channel: Questions in topic: "segment"
Viewing all articles
Browse latest Browse all 14

Segmenting image (at runtime) for puzzle pieces

$
0
0
Hi, I'm working on my first Unity project, a sliding puzzle ([like this][1]), and I'm struggling with splitting the texture (imported at runtime) into segments to fit the square pieces. Each tile is a default Sprite-GameObject. My current code: Texture2D image = Resources.Load ("Images/katze"); //Calculating the tile sizes float sizeX = image.width / numCols; float sizeY = image.height / numRows; //Take the smaller size (tiles are square) float tileSize = Mathf.Min(sizeX, sizeY); //I don't know the reason for this value, just played around :) float pixelsToUnits = tileSize / 8; //Get the topLeft point which acts as 'origin' for segmentingthe image Vector2 midPoint = new Vector2(image.width / 2, image.height / 2); Vector2 offset = new Vector2 (tileSize * numCols / 2, tileSize * numRows / 2); Vector2 topLeft = midPoint - offset; //new Vector2 (tileSize * numRows / 2, tileSize * numCols / 2); Vector2 pivot = new Vector2 (0.5f, 0.5f); // Center for (int x = 0; x

Viewing all articles
Browse latest Browse all 14

Latest Images

Trending Articles



Latest Images