Example #1
0
static cxInt cxSpriteTexture(lua_State *L)
{
    CX_LUA_DEF_THIS(cxReaderAttrInfo *);
    cxConstChars v = NULL;
    cxConstChars k = NULL;
    if(!lua_istable(L, 2)){
        luaL_error(L, "args error");
        return 0;
    }
    lua_getfield(L, 2, "v");
    v = luaL_checkstring(L, -1);
    lua_pop(L, 1);
    lua_getfield(L, 2, "k");
    k = luaL_checkstring(L, -1);
    lua_pop(L, 1);
    if(v == NULL){
        luaL_error(L, "v args error");
        return 0;
    }
    cxTextureAttr attr = CX_CREATE(cxTextureAttr);
    cxSprite sprite = cxViewRootGet(this->root, v);
    CX_ASSERT(sprite != NULL, "sprite is null");
    CX_RETAIN_SWAP(attr->texture, sprite->texture);
    if(k != NULL){
        attr->box = cxTextureBox(sprite->texture, k);
        attr->size = cxTextureSize(sprite->texture, k);
    }
    CX_LUA_PUSH_OBJECT(attr);
    return 1;
}
Example #2
0
cxInt cxAtlasAppendSprite(cxAny pview,cxVec2f pos,cxConstChars key)
{
    cxAtlas this = pview;
    cxColor4f color = cxColor4fv(1, 1, 1, 1);
    cxBoxTex2f tbox = cxTextureBox(this->cxSprite.texture, key);
    cxSize2f siz = cxTextureSize(this->cxSprite.texture, key);
    cxBoxPoint bp = cxAtlasCreateBoxPoint(pos, siz, tbox, color);
    cxAtlasAppend(pview, &bp);
    return this->number - 1;
}
Example #3
0
void cxSpriteSetTextureKey(cxAny pview,cxConstChars key,cxBool equSize)
{
    cxSprite this = pview;
    if(this->texture == NULL){
        cxTexture texture = cxTextureFactoryLoadFile(key);
        cxSpriteSetTexture(pview, texture);
    }else{
        this->texCoord = cxTextureBox(this->texture, key);
    }
    CX_ASSERT(this->texture != NULL, "sprite texture not load");
    if(equSize){
        cxViewSetSize(pview, cxTextureSize(this->texture, key));
    }
    this->cxView.isDirty = true;
}
Example #4
0
static cxInt cxLoadTexture(lua_State *L)
{
    cxTextureAttr rv = CX_CREATE(cxTextureAttr);
    cxConstChars str = luaL_checkstring(L, 2);
    cxUrlPath path = cxUrlPathParse(str);
    if(path->count == 0){
        lua_pushnil(L);
        return 1;
    }
    cxTexture texture = NULL;
    if(path->count > 0){
        texture = cxTextureFactoryLoadFile(path->path);
        rv->size = texture->size;
        CX_RETAIN_SWAP(rv->texture, texture);
    }
    if(path->count > 1 && texture != NULL){
        rv->box = cxTextureBox(texture, path->key);
        rv->size = cxTextureSize(texture, path->key);
    }
    CX_LUA_PUSH_OBJECT(rv);
    return 1;
}
Example #5
0
CX_SETTER_DEF(cxAtlas, layers)
{
    cxJson layers = cxJsonToArray(value);
    CX_JSON_ARRAY_EACH_BEG(layers, layer)
    {
        cxVec2f pos = cxVec2fv(0, 0);
        cxSize2f size = cxSize2fv(0, 0);
        cxBoxTex2f tex = cxBoxTex2fDefault();
        cxColor4f color = cxColor4fv(1, 1, 1, 1);
        pos = cxJsonVec2f(layer, "pos", pos);
        size = cxJsonSize2f(layer, "size", size);
        cxConstChars key = cxJsonConstChars(layer, "key");
        if(key != NULL){
            tex = cxTextureBox(this->cxSprite.texture, key);
        }else{
            tex = cxJsonBoxTex2f(layer, "coord", tex);
        }
        if(cxSize2Zero(size) && key != NULL){
            size = cxTextureSize(this->cxSprite.texture, key);
        }
        color = cxJsonColor4f(layer, "color", color);
        cxAtlasAppendBoxPoint(this, pos, size, tex, color);
    }