1

so im trying to make a game with just a simple static background at the moment, but when i draw it to the screen (no scaling being done as the resolution of the image is the same as the screen) it draws the bottom portion of the image incorrectly where the bottom few hundred pixels of the image are exactly the same going down the image. Sorry it's so difficult to explain but being new here i cant actually post an image of what is going wrong.

Now im just using a simple sprite to render this background image. Here is the code being used:

    // background layer: another image
    background = CCSprite.sprite("WaterBackground.png");
    // change the transform anchor point (optional)
    background.setPosition(CGPoint.make(GAME_WIDTH/2, GAME_HEIGHT/2));
    addChild(background);

am i doing something wrong here? Does Cocos2D not support such large images for sprites? (resolution of 800*1280) Any help would be greatly appreciated!

Since i am now able to upload images, here are visuals of what is going wrong:

The image as it is supposed to look

And the problem in my game:

enter image description here

As you can see, the problem is hard to describe. The problem only exists with this larger image; i scaled it down manually in GIMP and then scaled it up for the game and it looked fine (except for being a lower resolution). I also tried scaling down this larger image which still resulted in the same problem. Hopefully you guys can help me as I have no clue what could possibly cause this error. Especially since i read that Cocos2D's max supported image size is 2048*2048 and my image is well within that.

Thanks for any help you guys can provide!

Intrivix
  • 159
  • 3
  • 15

3 Answers3

1

This is due to limitations on the size of textures. Coсos2d-android supports images with a maximum size of 1024 x 1024 pixels.

I faced the same problem and looking for a way to solve it.

EDIT

I found the solution In cocos2d project open file CCTexture2d.java in org.cocos2d.opengl package and change kMaxTextureSize from 1024 to 2048

rstk
  • 414
  • 5
  • 14
0

I'm not certain, as from your code and looking at the cocos2d code I can't see a definite reason why this would be happening, but given the number of sprites you've got on the screen, i'd definitely take a look at my answer to this question as you may well be hitting one of cocos2d's quirky little rendering faults around multiple sprites. can't hurt to try spritesheets, and it's certainly the correct way to actually do sprites in cocos.

also, definitely create yourself a helper utility to determine the scaling ratio of a device compared to your original image sizes, as unlike on iphone, android does have a pretty much unlimited variation of screen resolutions, and a simple bit of "scale as you load" utility code now will save you lots of time in the future if you want to use this on any other device.

Community
  • 1
  • 1
rspython
  • 229
  • 1
  • 9
  • do you have any guides or help as to using that sprite sheet program? as far as i can tell it only links images and i basically use just 2 images for the moving sprites and one for the background so i need a bit more explanation as to how this sprite sheet works inside Cocos2D. Also, i do tell Cocos2D to scale the render size and maintain aspect ratio, but i already tried scaling the background image programatically and that didnt really work to well. do you mean that i should scale down the physical image texture when i load it? – Intrivix May 22 '12 at 16:51
  • Also, even just 75% physical down scale then upscale for rendering has the image working nicely... – Intrivix May 22 '12 at 17:35
0

you should try to make one method for adding background,i am doing this this like this way try this hope it will help full for you...here addBackGroundScene is my method and i am adding my background with this method,scrXScaleFactor is maintaining scaling part of my screen try this...

private void addBackGroundScene() {
        CCSprite bgForLevel1 = addBackgroundAtOrigin("prelevel1/bgMenu.jpg");
        bgForLevel1 .setScaleX(scrXScaleFactor);
            bgForLevel1 .setAnchorPoint(0, 0);          
            addChild(bgForLevel1 );

    }
  • Thanks, but this doesnt seem very different from just making the background inside the constructor. I am indeed scaling up the image, but my preference is to be able to use the full size image for the background instead of having to scale up a smaller image. – Intrivix Jun 07 '12 at 16:40