cocos2d::Data class

Hi, I’m not quite fond of how Data class works

all I know is that I can load data from a file into a Data* object

but how can I load an std::string into a Data* object?

I can ask engineering once they return from holiday. What version are you using?

Cocos2dx v0.4
btw i’m using the adxe 1.0.0b2 fork of cocos2dx

I haven’t heard of or used this fork. I’d suggest you ask the author as I don’t know what modifications they have made.

You should really check the header file where the Data class is defined (CCData.h in Cocos2d-x), since all the documentation is in there:

/** Copies the buffer pointer and its size.
     *  @note This method will copy the whole buffer.
     *        Developer should free the pointer after invoking this method.
     *  @see Data::fastSet
     * @return The size of bytes copied, return 0 if size <= 0
    ssize_t copy(const unsigned char* bytes, const ssize_t size);

    uint8_t* resize(ssize_t size);

    /** Fast set the buffer pointer and its size. Please use it carefully.
     *  @param bytes The buffer pointer, note that it have to be allocated by 'malloc' or 'calloc',
     *         since in the destructor of Data, the buffer will be deleted by 'free'.
     *  @note 1. This method will move the ownship of 'bytes'pointer to Data,
     *        2. The pointer should not be used outside after it was passed to this method.
     *  @see Data::copy
    void fastSet(uint8_t* bytes, const ssize_t size);

Also, the cpp-tests project has samples on how to use it. Check FileUtilsTest.cpp::TestWriteData.

really? its this fork

it made cocos2d more powerful and modern

I remember it slightly. It changed names because it was using our branding. In any event it’s a fork I think @r101 had the perfect approach.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.