在cocos 2dx中获取Sprite的纹理

时间:2016-04-07 07:49:30

标签: ios cocos2d-x game-engine

我开发了 { "entityInfo": { "entity": "", "tenantId": "", "timeStamp": "2016-04-07T07:25:49.711Z" }, "collections": { "Customer29Jan16": { "meta": { "parentreference": "***", "pkname": "***", "fkname": "***" }, "rowset": [ { "CuId": "test", "Name": "test", "Quantity": "test", "Rate": "test", "Amount": "test" }, { "CuId": "test", "Name": "test", "Quantity": "test", "Rate": "test", "Amount": "test" }, { "CuId": "test", "Name": "test", "Quantity": "test", "Rate": "test", "Amount": "test" }, { "CuId": "test", "Name": "test", "Quantity": "test", "Rate": "test", "Amount": "test" }, { "CuId": "test", "Name": "test", "Quantity": "test", "Rate": "test", "Amount": "test" } ], "rowfilter": [] } } } 游戏,我在cocos 2dx中运行animation,我希望获得当前的Sprite,我尝试了以下代码:

texture name

但是它给了我CCSpriteFrame *frameN = fisherManBoat->displayFrame(); frameName = frameN->_textureFilename; 受到保护的错误,所以我该如何解决呢?如果它不起作用那么我还能尝试什么?因为屏幕上有一个按钮,我点击并动画运行,我想让它流畅。因此,如果动画介于两者之间再次录制,则它不会再次从其当前点开始。

1 个答案:

答案 0 :(得分:0)

如果要访问_textureFilename变量,则需要修改CCSpriteFrame.h文件。

首先,您需要在CCSpriteFrame.h文件中找到此代码

protected:
    Vec2 _offset;
    Size _originalSize;
    Rect _rectInPixels;
    bool   _rotated;
    Rect _rect;
    Vec2 _offsetInPixels;
    Size _originalSizeInPixels;
    Texture2D *_texture;
    std::string  _textureFilename;
    PolygonInfo _polygonInfo;

从此代码中删除以下行

std::string  _textureFilename;

现在你必须将它粘贴在CCSpriteFrame.h文件的顶部,其中定义了公共范围。

class CC_DLL SpriteFrame : public Ref, public Clonable
{
public:

    std::string  _textureFilename;

我希望它会对你有所帮助。感谢。