Hi,
I have a problem with my images. I have a image to “iphone” and other to “iphone hd”, but when i apply animation, instead of get the sprite for HD in iphone 4, it is changing to normal sprite, iphone 3gs, but if i comment the animation lines, it work with iphone 4 images (iphonehd directoy).
My project:
— resources
—- iphone
—— player_playersheet.png
—— player_playersheet.plist
—- iphonehd
—— player_playersheet.png
—— player_playersheet.plist
My resource loader method (if can be better, please, say to me):
APP DELEGATE H
typedef struct tagResource
{
cocos2d::CCSize size;
char directory[100];
} Resource;
>
static Resource resPhone = { cocos2d::CCSizeMake(480, 320), “iphone” };
static Resource resPhoneRetina = { cocos2d::CCSizeMake(960, 640), “iphonehd” };
static Resource resTablet = { cocos2d::CCSizeMake(1024, 768), “ipad” };
static Resource resTabletRetina = { cocos2d::CCSizeMake(2048, 1536), “ipadhd” };
static cocos2d::CCSize designResolutionSize = cocos2d::CCSizeMake(480, 320);
>
/*
@brief The cocos2d Application.
>
The reason for implement as private inheritance is to hide some interface call by CCDirector.
>/
class AppDelegate : private cocos2d::CCApplication
APP DELEGATE CPP
bool AppDelegate::applicationDidFinishLaunching() {
// initialize director
CCDirector* pDirector = CCDirector::sharedDirector();
CCEGLView* pEGLView = CCEGLView::sharedOpenGLView();
>
pDirector~~>setOpenGLView;
pEGLView~~>setDesignResolutionSize(designResolutionSize.width, designResolutionSize.height, kResolutionNoBorder);
>
CCSize frameSize = pEGLView~~>getFrameSize;
>
if
{
CCFileUtils::sharedFileUtils~~>addSearchPath;
pDirector~~>setContentScaleFactor;
}
else if
{
CCFileUtils::sharedFileUtils~~>addSearchPath;
pDirector~~>setContentScaleFactor;
}
else if
{
CCFileUtils::sharedFileUtils~~>addSearchPath;
pDirector~~>setContentScaleFactor;
}
else
{
CCFileUtils::sharedFileUtils~~>addSearchPath;
pDirector~~>setContentScaleFactor;
}
>
// turn on display FPS
pDirector~~>setDisplayStats(true);
>
// set FPS. the default value is 1.0/60 if you don’t call this
pDirector~~>setAnimationInterval;
>
// create a scene. it’s an autorelease object
CCScene pScene = HelloWorld::scene;
>
// run
pDirector~~>runWithScene;
>
return true;
}
MY LOAD SPRITE CODE
// SPRITE SHEET
batchNodeParent = CCSpriteBatchNode::create;
this~~>addChild;
>
// SPRITE PLIST
CCSpriteFrameCache::sharedSpriteFrameCache~~>addSpriteFramesWithFile;
CCSprite m_pSprite1 = CCSprite::createWithSpriteFrameName;
>
// ANIMATION
CCAnimationCachecache = CCAnimationCache::sharedAnimationCache; // “caches” are always singletons in cocos2d
cache~~>addAnimationsWithFile;
CCAnimationanimation = cache~~>animationByName(“walk”); // I apologize for this method name, it should be getAnimationByName(…) in future versions
CCAnimate animate = CCAnimate::create; // Don’t confused between CCAnimation and CCAnimate
CCRepeatForeverfora = CCRepeatForever::create(animate);
m_pSprite1~~>runAction;
>
m_pSprite1~~>setPosition(ccp(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y));
this~~>addChild;
The correct behavior only happen when i change lines:
CCRepeatForever *fora = CCRepeatForever::create;
m_pSprite1~~>runAction(fora);
By line:
m_pSprite1->runAction(animate);
The first image attached is the normal behavior, loading image from iphonehd directory on my iphone4, and the second image is loading the sprites from iphone directory, instead of iphonehd.
Im using cocos 2.1.4.
THANKS.
IMG_0067.PNG (55.3 KB)
IMG_0066.PNG (38.2 KB)