blog games developers documentation portfolio gallery

More in this category:

Crop()

void Crop(Rect cropRect)



Will crop the image to the size and offset indicated by cropRect.

Left edge of the changed image is at pixel cropRect.x
Bottom edge of the changed image is at pixel cropRect.y
Right edge of the changed image is at pixel cropRect.x + cropRect.width
Top edge of the changed image is at pixel cropRect.y + cropRect.height

Coordinates go from left bottom (0,0) to top right (texture.width, texture.height)

cropRect.x and cropRect.y will be clamped between 0 and texture.width (of texture.height)
cropRect.width will be clamped between 0 and texture.width - cropRect.x
cropRect.height will be clamped between 0 and texture.height - cropRect.y

Example:

if(GUI.Button(new Rect(0,0,200,25), "Crop to left-top 60%")) {
myTexture.Crop(
new Rect(0f, // start at left
myTexture.height * 0.4f, // start at 40% from the bottom
myTexture.width * 0.6f, // new width 60%
myTexture.height * 0.6f // new height 60%
)
);
}







follow us