2013-05-01 2 views
0

Iam new to cocos2d-x и проблема с запуском спрайт-анимации из файла .plist в android. Ниже приведен код IAM с помощью анимировать мой спрайт в ccTouchesBegancocos2d-x sprite animation using .plist

У меня есть свой файл Plist в папке ресурсов

void HelloWorld::ccTouchesBegan(cocos2d::CCSet *pTouches, cocos2d::CCEvent *pEvent) 
{ 
    mole->stopAllActions(); 

    CCArray *frames = CCArray::create(); 
    for(int i = 1; i <= 11; i++) 
    { 
     CCString *frame = CCString::createWithFormat("b%04d.png", i); 
     frames->addObject(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(frame->getCString())); 
    } 
    mole->runAction(CCAnimate::create(CCAnimation::create(frames,.15))); 
} 

и получать следующий журнал:

05-01 16:02:33.328: D/dalvikvm(3506): Added shared lib /data/data/com.cocos.moleit/lib/libgame.so 0x405167e0 
05-01 16:02:33.328: I/ApplicationPackageManager(3506): cscCountry is not German : PAK 
05-01 16:02:33.359: I/GLThread(3506): noticed surfaceView surface lost tid=10 
05-01 16:02:33.367: D/SensorManager(3506): ====>>>>>Num Sensor: 1 
05-01 16:02:33.367: D/SensorManager(3506): ====>>>>>Num Sensor: 2 
05-01 16:02:33.367: D/SensorManager(3506): ====>>>>>Num Sensor: 3 
05-01 16:02:33.367: D/SensorManager(3506): ====>>>>>Num Sensor: 4 
05-01 16:02:33.367: D/SensorManager(3506): ====>>>>>Num Sensor: 5 
05-01 16:02:33.367: D/SensorManager(3506): ====>>>>>Num Sensor: 6 
05-01 16:02:33.367: D/SensorManager(3506): ====>>>>>Num Sensor: 0 
05-01 16:02:33.375: I/GLThread(3506): onResume tid=10 
05-01 16:02:33.375: D/cocos2d-x debug info(3506): cocos2d: cocos2d-2.1rc0-x-2.1.2 
05-01 16:02:33.453: I/GLThread(3506): noticed surfaceView surface acquired tid=10 
05-01 16:02:33.453: W/EglHelper(3506): start() tid=10 
05-01 16:02:33.523: D/libEGL(3506): loaded /system/lib/egl/libGLES_hgl.so 
05-01 16:02:33.531: D/BRCM_EGL(3506): eglCreateContext() context: 0x1ba388, VC context 1, Thread 3515 
05-01 16:02:33.531: W/EglHelper(3506): createContext [email protected] tid=10 
05-01 16:02:33.531: I/GLThread(3506): noticing that we want render notification tid=10 
05-01 16:02:33.531: W/GLThread(3506): egl createSurface 
05-01 16:02:33.531: W/EglHelper(3506): createSurface() tid=10 
05-01 16:02:33.531: D/BRCM_EGL(3506): eglCreateWindowSurface() surface: 0x1ba3f8, VC surface: 1, Thread: 3515 
05-01 16:02:33.531: D/BRCM_EGL(3506): eglMakeCurrent(0x1ba388, 0x1ba3f8, 0x1ba3f8) Thread: 3515 
05-01 16:02:33.531: W/GLThreadManager(3506): checkGLESVersion mGLESVersion = 131072 mMultipleGLESContextsAllowed = true 
05-01 16:02:33.531: W/GLThread(3506): onSurfaceCreated 
05-01 16:02:33.601: D/cocos2d-x debug info(3506): cocos2d: GL_VENDOR:  Broadcom 
05-01 16:02:33.601: D/cocos2d-x debug info(3506): cocos2d: GL_RENDERER: VideoCore IV HW 
05-01 16:02:33.601: D/cocos2d-x debug info(3506): cocos2d: GL_VERSION: OpenGL ES 2.0 
05-01 16:02:33.601: D/cocos2d-x debug info(3506): cocos2d: GL_MAX_TEXTURE_SIZE: 2048 
05-01 16:02:33.601: D/cocos2d-x debug info(3506): cocos2d: GL_MAX_TEXTURE_UNITS: 8 
05-01 16:02:33.601: D/cocos2d-x debug info(3506): cocos2d: GL supports PVRTC: NO 
05-01 16:02:33.601: D/cocos2d-x debug info(3506): cocos2d: GL supports BGRA8888 textures: NO 
05-01 16:02:33.601: D/cocos2d-x debug info(3506): cocos2d: GL supports NPOT textures: YES 
05-01 16:02:33.601: D/cocos2d-x debug info(3506): cocos2d: GL supports discard_framebuffer: YES 
05-01 16:02:33.601: D/cocos2d-x debug info(3506): cocos2d: GL supports shareable VAO: NO 
05-01 16:02:33.601: D/cocos2d-x debug info(3506): cocos2d: compiled with Profiling Support: NO 
05-01 16:02:34.484: W/GLThread(3506): onSurfaceChanged(320, 240) 
05-01 16:02:34.687: I/GLThread(3506): sending render notification tid=10 
05-01 16:02:50.335: E/cocos2d-x assert(3506): C:/tahir/cocos2dx_zip/cocos2d-2.1rc0-x-2.1.2/cocos2d-2.1rc0-x-2.1.2/moleitx/proj.android/../../cocos2dx/sprite_nodes/CCAnimation.cpp function:initWithAnimationFrames line:144 
05-01 16:02:50.335: E/cocos2d-x assert(3506): C:/tahir/cocos2dx_zip/cocos2d-2.1rc0-x-2.1.2/cocos2d-2.1rc0-x-2.1.2/moleitx/proj.android/../../cocos2dx/sprite_nodes/CCAnimation.cpp function:initWithAnimationFrames line:144 
05-01 16:02:50.335: E/cocos2d-x assert(3506): C:/tahir/cocos2dx_zip/cocos2d-2.1rc0-x-2.1.2/cocos2d-2.1rc0-x-2.1.2/moleitx/proj.android/../../cocos2dx/sprite_nodes/CCAnimation.cpp function:initWithAnimationFrames line:144 
05-01 16:02:50.343: E/cocos2d-x assert(3506): C:/tahir/cocos2dx_zip/cocos2d-2.1rc0-x-2.1.2/cocos2d-2.1rc0-x-2.1.2/moleitx/proj.android/../../cocos2dx/sprite_nodes/CCAnimation.cpp function:initWithAnimationFrames line:144 
05-01 16:02:50.343: E/cocos2d-x assert(3506): C:/tahir/cocos2dx_zip/cocos2d-2.1rc0-x-2.1.2/cocos2d-2.1rc0-x-2.1.2/moleitx/proj.android/../../cocos2dx/sprite_nodes/CCAnimation.cpp function:initWithAnimationFrames line:144 
05-01 16:02:50.343: E/cocos2d-x assert(3506): C:/tahir/cocos2dx_zip/cocos2d-2.1rc0-x-2.1.2/cocos2d-2.1rc0-x-2.1.2/moleitx/proj.android/../../cocos2dx/sprite_nodes/CCAnimation.cpp function:initWithAnimationFrames line:144 
05-01 16:02:50.343: E/cocos2d-x assert(3506): C:/tahir/cocos2dx_zip/cocos2d-2.1rc0-x-2.1.2/cocos2d-2.1rc0-x-2.1.2/moleitx/proj.android/../../cocos2dx/sprite_nodes/CCAnimation.cpp function:initWithAnimationFrames line:144 
05-01 16:02:50.343: E/cocos2d-x assert(3506): C:/tahir/cocos2dx_zip/cocos2d-2.1rc0-x-2.1.2/cocos2d-2.1rc0-x-2.1.2/moleitx/proj.android/../../cocos2dx/sprite_nodes/CCAnimation.cpp function:initWithAnimationFrames line:144 
05-01 16:02:50.343: E/cocos2d-x assert(3506): C:/tahir/cocos2dx_zip/cocos2d-2.1rc0-x-2.1.2/cocos2d-2.1rc0-x-2.1.2/moleitx/proj.android/../../cocos2dx/sprite_nodes/CCAnimation.cpp function:initWithAnimationFrames line:144 
05-01 16:02:50.343: E/cocos2d-x assert(3506): C:/tahir/cocos2dx_zip/cocos2d-2.1rc0-x-2.1.2/cocos2d-2.1rc0-x-2.1.2/moleitx/proj.android/../../cocos2dx/sprite_nodes/CCAnimation.cpp function:initWithAnimationFrames line:144 
05-01 16:02:50.343: E/cocos2d-x assert(3506): C:/tahir/cocos2dx_zip/cocos2d-2.1rc0-x-2.1.2/cocos2d-2.1rc0-x-2.1.2/moleitx/proj.android/../../cocos2dx/sprite_nodes/CCAnimation.cpp function:initWithAnimationFrames line:144 

на линии 144: У меня есть это

bool CCAnimation::initWithAnimationFrames(CCArray* arrayOfAnimationFrames, float delayPerUnit, unsigned int loops){ 

    CCARRAY_VERIFY_TYPE(arrayOfAnimationFrames, CCAnimationFrame*); // line 144 error: 

    m_fDelayPerUnit = delayPerUnit; 
    m_uLoops = loops; 

    setFrames(CCArray::createWithArray(arrayOfAnimationFrames)); 

    CCObject* pObj = NULL; 
    CCARRAY_FOREACH(m_pFrames, pObj) 
    { 
     CCAnimationFrame* animFrame = (CCAnimationFrame*)pObj; 
     m_fTotalDelayUnits += animFrame->getDelayUnits(); 
    } 
    return true; 
} 

, пожалуйста, помогите!

С уважением, Мухаммад Тахир Ашраф

ответ

2

Кажется, что я добавлял кадров в массив, а не имена используют метод createWithSpriteFrames из CCAnimation решает проблему.

Ex.

CCAnimation::createWithSpriteFrames(frames,.15) 

может быть кому-то полезен!

1

Наслаждайтесь классом, который я написал на C++ для cocos2d-x, он может создать объект CCAnimate с помощью plist.

создать CCAnimate с классом хелпер ниже прост:

, если у вас есть последовательность кадров имени NODE0 node1 .... node4, вы можете создать объект CCAnimate использовать код последующей выше:

CCAnimateManager::animateWithFrame("node", 5, 0.17,"node"); 
CCAnimate * anima = CCAnimateManager::getAnimate("node"); 

это заголовочный файл.

#include <iostream> 
#include "cocos2d.h" 

using namespace std; 
using namespace cocos2d; 

class CCAnimateManager:public CCAnimation 
{ 
public: 
    static CCAnimate * getAnimate(string name); 
    static void animateWithFile(string name, int frameCount, float delay, string animateName, const char * format = "%s%04d.png"); 
    static void animateWithFrame(string frame,int frameCount, float delay, string animateName,const char * format = "%s%04d.png"); 
}; 

и вот файл CPP:

#include "CCAnimateManager.h" 
#include "cocos2d.h" 

using namespace cocos2d; 

CCAnimate * CCAnimateManager::getAnimate(string name) 
{ 
    return CCAnimate::create(CCAnimationCache::sharedAnimationCache()->animationByName(name.c_str())); 
} 

void CCAnimateManager::animateWithFrame(string frame, int frameCount, float delay, string animateName, const char * format) 
{ 
    CCAnimation* animation = CCAnimation::create(); 
    animation->setDelayPerUnit(delay); 
    char str[64] = {0}; 
    for (int i = 0; i < frameCount; i++) 
    { 
     sprintf(str, format,frame.c_str(), i); 
     CCSpriteFrameCache* cache = CCSpriteFrameCache::sharedSpriteFrameCache(); 
     CCSpriteFrame* frame = cache->spriteFrameByName(str); 
     animation->addSpriteFrame(frame); 
    } 
    CCAnimationCache::sharedAnimationCache()->addAnimation(animation, animateName.c_str()); 
} 

void CCAnimateManager::animateWithFile(string name, int frameCount, float delay, string animateName, const char * format) 
{ 
    CCAnimation* animation = CCAnimation::create(); 
    animation->setDelayPerUnit(delay); 
    char str[64] = {0}; 
    for (int i = 0; i < frameCount; i++) 
    { 
     sprintf(str, format,name.c_str(), i); 
     CCTexture2D * texture = CCTextureCache::sharedTextureCache()->addImage(str); 
     CCSize size = texture->getContentSize(); 
     CCRect rect = CCRectMake(0, 0, size.width, size.height); 
     CCSpriteFrame * frame = CCSpriteFrame::createWithTexture(texture, rect); 
     animation->addSpriteFrame(frame); 
    } 
    CCAnimationCache::sharedAnimationCache()->addAnimation(animation, animateName.c_str()); 
} 
0
RepeatForever* HelloWorld::moving() 
    { 
     // 3. repeat the frame 
     int numFrame = 8; 

     cocos2d::Vector<cocos2d::SpriteFrame *> frames; 
     SpriteFrameCache *frameCache = SpriteFrameCache::getInstance(); 

     char file[100] = {0}; 

     for (int i = 0; i < numFrame; i++) 
     { 
      sprintf(file, "bear%d.png", i+1); 
      SpriteFrame *frame = frameCache->getSpriteFrameByName(file); 
      frames.pushBack(frame); 
     } 

     Animation *animation = Animation::createWithSpriteFrames(frames, 0.07); 
     Animate *animate = Animate::create(animation); 

     RepeatForever *repeat = RepeatForever::create(animate); 

     return repeat; 
    } 
    sprite->runAction(moving()); 

First add PNG file created from SpriteBulder(In many images Animation) 
second add plist file