Skip to content

Instantly share code, notes, and snippets.

@randalfien
Last active February 3, 2016 16:56
Show Gist options
  • Save randalfien/699c2c8da22d51969053 to your computer and use it in GitHub Desktop.
Save randalfien/699c2c8da22d51969053 to your computer and use it in GitHub Desktop.
Adobe AIR - Starling Image extension that let's you use a multipart image, similar to css background-position.
package cz.fishtrone.utils
{
import starling.display.Image;
import starling.textures.Texture;
/**
* Give a texture that is made of {parts} images, one below another, spaced evenly and specify which image {part} you want to see
*/
public class MultipartImage extends Image
{
public function MultipartImage(texture:Texture, part:int, parts:int = 4)
{
super(texture);
setTexCoordsTo(0, 0, part/parts);
setTexCoordsTo(1, 1, part/parts);
setTexCoordsTo(2, 0, part/parts+1/parts);
setTexCoordsTo(3, 1, part/parts+1/parts);
mVertexData.setPosition(2, 0.0, height/parts);
mVertexData.setPosition(3, width, height/parts);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment