Bug with image resolution when animate

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
CCAnimationCache
cache = CCAnimationCache::sharedAnimationCache; // “caches” are always singletons in cocos2d
cache~~>addAnimationsWithFile;
CCAnimation
animation = 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 :slight_smile:
CCRepeatForever
fora = 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)

Hi,
Can anyone help me pls :frowning:

Hi,

My problems are solved when i migrate to version 3. So it is a bug in version 2.1.4.

But when i used version 3 and test on android, i got errors:

08-23 22:12:32.234: D/dalvikvm(337): Trying to load lib /data/data/com.prsolucoes.MagicAndZombie/lib/libcocos2dcpp.so 0x40514b90
08-23 22:12:32.595: D/dalvikvm(337): Added shared lib /data/data/com.prsolucoes.MagicAndZombie/lib/libcocos2dcpp.so 0x40514b90
08-23 22:12:32.744: D/Cocos2dxActivity(337): model=sdk
08-23 22:12:32.744: D/Cocos2dxActivity(337): product=sdk
08-23 22:12:32.744: D/Cocos2dxActivity(337): isEmulator=true
08-23 22:12:33.174: D/libEGL(337): egl.cfg not found, using default config
08-23 22:12:33.174: D/libEGL(337): loaded /system/lib/egl/libGLES_android.so
08-23 22:12:33.254: W/dalvikvm(337): threadid=9: thread exiting with uncaught exception (group=0x40015560)
08-23 22:12:33.254: E/AndroidRuntime(337): FATAL EXCEPTION: GLThread 10
08-23 22:12:33.254: E/AndroidRuntime(337): java.lang.IllegalArgumentException: No configs match configSpec
08-23 22:12:33.254: E/AndroidRuntime(337): at android.opengl.GLSurfaceView$BaseConfigChooser.chooseConfig(GLSurfaceView.java:763)
08-23 22:12:33.254: E/AndroidRuntime(337): at android.opengl.GLSurfaceView$EglHelper.start(GLSurfaceView.java:919)
08-23 22:12:33.254: E/AndroidRuntime(337): at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1264)
08-23 22:12:33.254: E/AndroidRuntime(337): at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1118)
>

Can anyone help me?

Sorry, the problem still continue in v3.

I dont know what happen.

It dont get the image in the correct directory.

I am seeing this same issue, using cocos2d-x v3 alpha

If I create an animation using individual files, the scale is double what it should be:

Example:

texture = TextureCache::sharedTextureCache()->addImage(*it);
textSize = texture->getContentSize(); // the contentSize reports correctly
textRect = Rect(0, 0, textSize.width, textSize.height);
frame = SpriteFrame::createWithTexture(texture, textRect);
frames->addObject(frame);
Animation* animation = Animation::createWithSpriteFrames(frames, delay);

Above, when loading the texture, the content size is correct, but when drawn in the game, it is rendered double the size.

If I use a texture atlas and load via sprite frames, it works correctly:

 frame = SpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(*it);
 frames->addObject(frame);
 Animation* animation = Animation::createWithSpriteFrames(frames, delay);

Ok, my issue was that I had a SpriteBatchNode loading a texture atlas with an image of the same name. When I fixed that, the animation issue went away. Though the image in the spritebatchnode was the same dimensions as the individual file, so I am still a bit unsure why it would display double the size