Sprite cropped on Android - v3.11.1

Hi,

Im trying launch a new version of my game on android too:

But after update to last cocos2d-x version and compile on android, i got this error on image uploaded. I think that the image is cropped of something like this.

The problem is that it only happens on Android. I dont have this problem on mac, ios, etc.

Both player and coin class inherit from cocos2d::sprite.

My player code creation:

bool Player::init()
{
    CCLOG("Player::init");    
    
    speed        = 1.0f;
	speedMax     = 4.0f;
	acceleration = 1.0f;
	speedMin     = -4.0f;		
	playerGoDown = false;
    canMove      = true;
    width        = 106;
    height       = 66;
    
    spriteSheet = SpriteBatchNode::create("res/player.png");
    initWithTexture(spriteSheet->getTexture(), Rect(0, 0, width, height));
    spriteSheet->addChild(this, 0);
    
    setTag(GameObjects::TAG_PLAYER);
    
    // cria animação para cima
    Animation *animationUpFrames = Animation::create();
    animationUpFrames->setDelayPerUnit(0.05f);    
    Rect rectAnimationUp = Rect(0*width, 1*height, width, height);
    SpriteFrame *frameUp = SpriteFrame::createWithTexture(spriteSheet->getTexture(), rectAnimationUp);
    Rect rectAnimationUp2 = Rect(1*width, 1*height, width, height);
    SpriteFrame *frameUp2 = SpriteFrame::createWithTexture(spriteSheet->getTexture(), rectAnimationUp2);
    Rect rectAnimationUp3 = Rect(2*width, 1*height, width, height);
    SpriteFrame *frameUp3 = SpriteFrame::createWithTexture(spriteSheet->getTexture(), rectAnimationUp3);
    animationUpFrames->addSpriteFrame(frameUp);
    animationUpFrames->addSpriteFrame(frameUp2);
    animationUpFrames->addSpriteFrame(frameUp3);
    animationUp = Animate::create(animationUpFrames);
    animationUp = RepeatForever::create((Sequence*)animationUp);
    CC_SAFE_RETAIN(animationUp);
    ...

The coin have the same problem:

bool Coin::init()
{
    CCLOG("Coin::init");    
    
    width  = 50;
    height = 50;
    speed  = GameObjects::gameSpeed;
    
    char imageName[128] = {0};
    sprintf(imageName, "res/coins.png");
    
    spriteSheet = SpriteBatchNode::create(imageName);
    initWithTexture(spriteSheet->getTexture(), Rect(0, 0, width, height));
    spriteSheet->addChild(this, 0);
    
    setTag(GameObjects::TAG_COIN);
    
    // cria animação
    Animation *animationFrames = Animation::create();
    animationFrames->setDelayPerUnit(0.08f);    
    
    int animationRectHeight = 0;

    if (points == 50)
    {
        animationRectHeight = 0;
    }
    else if (points == 25)
    {
        animationRectHeight = 50;
    }
    else if (points == 10)
    {
        animationRectHeight = 100;
    }
    else if (points == 5)
    {
        animationRectHeight = 150;
    }
    else if (points == 2)
    {
        animationRectHeight = 200;
    }
    else if (points == 1)
    {
        animationRectHeight = 250;
    }

    for(int x = 0; x < 5; x++)
    {
        Rect rectAnimation = Rect(x*width, animationRectHeight, width, height);
        SpriteFrame *frame = SpriteFrame::createWithTexture(spriteSheet->getTexture(), rectAnimation);
        animationFrames->addSpriteFrame(frame);        
    }
    
    animation = Animate::create(animationFrames);
    animation = RepeatForever::create((Sequence*)animation);
    CC_SAFE_RETAIN(animation);
        
    stopAllActions();
    runAction(animation);
    
    setTag(GameObjects::TAG_COIN);
    
    return true;
}

Can anyone help me please?

Can anyone help me please?

It still making a different size on Android.

Can be resolution? How i can solve it?

As you can see, only on Android the images are cutted wrong.

And the code:

// carrega a imagem
char imageName[128] = {0};
sprintf(imageName, "res/coins.png");

spriteSheet = SpriteBatchNode::create(imageName);
width       = (spriteSheet->getTexture()->getContentSize().width / 5);
height      = spriteSheet->getTexture()->getContentSize().height / 6;

initWithTexture(spriteSheet->getTexture(), Rect(0, 0, width, height));
spriteSheet->addChild(this, 0);

setTag(GameObjects::TAG_COIN);

// cria animação
Animation *animationFrames = Animation::create();
animationFrames->setDelayPerUnit(0.08f);    

int animationRectHeight = 0;

if (points == 50)
{
    animationRectHeight = 0;
}
else if (points == 25)
{
    animationRectHeight = height;
}
else if (points == 10)
{
    animationRectHeight = height * 2;
}
else if (points == 5)
{
    animationRectHeight = height * 3;
}
else if (points == 2)
{
    animationRectHeight = height * 4;
}
else if (points == 1)
{
    animationRectHeight = height * 5;
}

for(int x = 0; x < 5; x++)
{
    Rect rectAnimation = Rect(x*width, animationRectHeight, width, height);
    SpriteFrame *frame = SpriteFrame::createWithTexture(spriteSheet->getTexture(), rectAnimation);
    animationFrames->addSpriteFrame(frame);        
}

animation = Animate::create(animationFrames);
animation = RepeatForever::create((Sequence*)animation);
CC_SAFE_RETAIN(animation);
    
stopAllActions();
runAction(animation);

setTag(GameObjects::TAG_COIN);

Looking into the code i think that the problem is here:

Rect rectAnimation = Rect(x*width, animationRectHeight, width, height);
SpriteFrame *frame = SpriteFrame::createWithTexture(spriteSheet->getTexture(), rectAnimation);
animationFrames->addSpriteFrame(frame);

Because with function (createWithTexture) convert the Rect from Points to pixels, but i set the pixels in Rect.

Cocos Code:

bool SpriteFrame::initWithTexture(Texture2D* texture, const Rect& rect)
{
    Rect rectInPixels = CC_RECT_POINTS_TO_PIXELS(rect);
    return initWithTexture(texture, rectInPixels, false, Vec2::ZERO, rectInPixels.size);
}

I think the problem is here, but i dont know if it is correct and if have any way to solve it. How i can work with spritesheets using pixels?

Hi ,

Anyone can help me please?

Thanks.

Can anyone help me with this problem?