Example #1
0
void NinePatch::initialize(TextureRegion region, int left, int right, int top, int bottom)
{
    int middleWidth = region.getRegionWidth() - left - right;
    int middleHeight = region.getRegionHeight() - top - bottom;

    if (top > 0) {
        if (left > 0) patches[0] = TextureRegion(region, 0, 0, left, top);
        if (middleWidth > 0) patches[1] = TextureRegion(region, left, 0, middleWidth, top);
        if (right > 0) patches[2] = TextureRegion(region, left + middleWidth, 0, right, top);
    }
    if (middleHeight > 0) {
        if (left > 0) patches[3] = TextureRegion(region, 0, top, left, middleHeight);
        if (middleWidth > 0) patches[4] = TextureRegion(region, left, top, middleWidth, middleHeight);
        if (right > 0) patches[5] = TextureRegion(region, left + middleWidth, top, right, middleHeight);
    }
    if (bottom > 0) {
        if (left > 0) patches[6] = TextureRegion(region, 0, top + middleHeight, left, bottom);
        if (middleWidth > 0) patches[7] = TextureRegion(region, left, top + middleHeight, middleWidth, bottom);
        if (right > 0) patches[8] = TextureRegion(region, left + middleWidth, top + middleHeight, right, bottom);
    }

    // If split only vertical, move splits from right to center.
    if (left == 0 && middleWidth == 0) {
        patches[(uint32_t) Sides::TOP_CENTER] = patches[(uint32_t) Sides::TOP_RIGHT];
        patches[(uint32_t) Sides::MIDDLE_CENTER] = patches[(uint32_t) Sides::MIDDLE_RIGHT];
        patches[(uint32_t) Sides::BOTTOM_CENTER] = patches[(uint32_t) Sides::BOTTOM_RIGHT];
    }
    
    // If split only horizontal, move splits from bottom to center.
    if (top == 0 && middleHeight == 0) {
        patches[(uint32_t) Sides::MIDDLE_LEFT] = patches[(uint32_t) Sides::BOTTOM_LEFT];
        patches[(uint32_t) Sides::MIDDLE_CENTER] = patches[(uint32_t) Sides::BOTTOM_CENTER];
        patches[(uint32_t) Sides::MIDDLE_RIGHT] = patches[(uint32_t) Sides::BOTTOM_RIGHT];        
    }
}
Example #2
0
Sprite::Sprite(const TextureRegion& region) : color(1,1,1,1) {
    this->scaleX = 1;
    this->scaleY = 1;
    this->dirty = true;
    this->x = this->y = this->width = this->height = 0;
    
    this->rotation = 0;
    
    TextureRegion::setRegion(region);
    setColor(1, 1, 1, 1);
    setSize(std::abs(region.getRegionWidth()), std::abs(region.getRegionHeight()));
    setOrigin(width / 2, height / 2);
}
Example #3
0
void NinePatch::initialize(TextureRegion region, int left, int right, int top, int bottom)
{
    int middleWidth = region.getRegionWidth() - left - right;
    int middleHeight = region.getRegionHeight() - top - bottom;
    
    patches[0] = TextureRegion(region, 0, 0, left, top);
    patches[1] = TextureRegion(region, left, 0, middleWidth, top);
    patches[2] = TextureRegion(region, left + middleWidth, 0, right, top);
    patches[3] = TextureRegion(region, 0, top, left, middleHeight);
    patches[4] = TextureRegion(region, left, top, middleWidth, middleHeight);
    patches[5] = TextureRegion(region, left + middleWidth, top, right, middleHeight);
    patches[6] = TextureRegion(region, 0, top + middleHeight, left, bottom);
    patches[7] = TextureRegion(region, left, top + middleHeight, middleWidth, bottom);
    patches[8] = TextureRegion(region, left + middleWidth, top + middleHeight, right, bottom);
}
Example #4
0
void SpriteBatch::draw (const TextureRegion& region,float x,float y) {
    draw(region, x, y, std::abs(region.getRegionWidth()), std::abs(region.getRegionHeight()));
}