Four, Four, Four Textures in One

1 minute read

I am doing tech review for an upcoming book on Second Life and learned about the texture offset parameters last week. Basically, it is possible to set the origin of the image within the prim, so that the image “slides” across the face of the prim. I already knew that it was possible to set the image scale so that just a portion of the image would be shown. Putting 2 and 2 together, I figured that it would be really easy to tile 4 smaller images into a bigger image and then programmatically adjust the offset so that exactly one of the images would be shown at a time.

Drawing on my newfound knowledge of Photoshop, I created the following image using cover art taken from Amazon.com:

fourpix.jpg

I then wrote the following little script:

list Offsets = [-0.25, -0.25, -0.25, 0.25, 0.25, -0.25, 0.25, 0.25]; integer ListOffset = 0; default { state_entry() { ListOffset = 0; } touch_start(integer total_number) { float OffsetX = llList2Float(Offsets, ListOffset); float OffsetY = llList2Float(Offsets, ListOffset+1); llOffsetTexture(OffsetX, OffsetY, ALL_SIDES); ListOffset += 2; if (ListOffset >= llGetListLength(Offsets)) { ListOffset = 0; } } }

Every time the prim is clicked, the script uses the pair of offsets (X and Y) located at Offsets[ListOffset] and Offsets[ListOffset + 1]. It then steps ListOffset by two and wraps it around to 0 if necessary.

Clean, simple, and very cool. And it does what I want!

Updated: