Exemple #1
0
cxSprite cxSpriteCreateWithFile(cxConstChars file,cxConstChars key)
{
    cxSprite this = CX_CREATE(cxSprite);
    cxTexture texture = cxTextureFactoryLoadFile(file);
    cxSpriteSetTexture(this, texture);
    cxSpriteSetTextureKey(this, key, true);
    return this;
}
Exemple #2
0
void cxSpriteSetTextureURL(cxAny pview,cxConstChars url,cxBool useTexSize,cxBool cached)
{
    CX_RETURN(url == NULL);
    cxSprite this = pview;
    cxUrlPath path = cxUrlPathParse(url);
    CX_RETURN(path == NULL);
    cxTexture texture = cxTextureFactoryLoadFile(path->path);
    if(cached){
        texture = cxTextureFactoryLoadFile(path->path);
    }else{
        texture = cxTextureCreate(path->path);
    }
    CX_ASSERT(texture != NULL, "texture load failed %s",path->path);
    cxSpriteSetTexture(this, texture);
    //use texture size
    cxBool uts = cxViewZeroSize(this) || useTexSize;
    if(path->count > 1){
        cxSpriteSetTextureKey(this, path->key, uts);
    }else if(uts){
        cxViewSetSize(this, texture->size);
    }
}
Exemple #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;
}
Exemple #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;
}