How To Tile (from Cache)?

Hi, I have lots of tiles need putting up and grouting.
In my game I need to put a border around a subsection of the screen. To do this I have 3 10x10 tiles that I intended to use by loading each and “blitting” it several times to a blank canvas.

//ne,se,sw,nw light Outside
    Sprite lOSCorners[4];
    //ne,se,sw,nw dark Outside
    Sprite dOSCorners[4];
    //n,e,s,w light outside
    Sprite lOSWalls[4];
    //n, e, s, w dark outside
    Sprite dOSWalls[4];
    for (int i = 0; i < 4; ++i) {
        lOSCorners[i] = Sprite::create(“peachyBorders.png”, Rect(0, 0, 10, 10));
        dOSCorners[i] = Sprite::create(“peachyBorders.png”, Rect(10, 0, 10, 10));
        lOSWalls[i] = Sprite::create(“peachyBorders.png”, Rect(20, 0, 10, 10));
        dOSWalls[i] = Sprite::create(“peachyBorders.png”, Rect(20, 0, 10, 10));
        lOSCorners[i]->setRotation(i
90);
        dOSCorners[i]->setRotation(i
90);
        lOSWalls[i]->setRotation(i
90);
        dOSWalls[i]->setRotation(i
90+180);
    }

I never found a way to reliably duplicate sprites like this so repeated a lot of my graphics for the intro screens. I’d prefer not to import plists, the sheet is only 30x10! Should I create a new sprite each time I blit 10sq pixels? Can I create a blank node of say 480*10 and stretch?

ANSWER: rotate and stretch, create again from file and repeat a coupla times.

But I’m not sure the rotate and stretch are getting mixed up, or worse, my corner tiles appear smeared lengthwise accros half the screen.

Also the left and right borders are not being added to the screen despite calling SetPosition on the stretched and rotated Sprites.

07-10 14:00:02.410: D/cocos2d-x debug info(1197): setPos lOSW[0] 0.000000, 740.000000

As you, er, may, see, only a couple of complete horizontal walls get drawn, light or dark, they are mirrors, or should be. The corners are a mess.

Thanks again in advance.

The problem was my anchor points, set to Vec2::ZERO to ease the positioning on canvas, the rotations had moved a number off screen, my bad!
Another interesting phenomena was the ordering of scaling and rotation commands, the rotation appears to be the final transformation applied only at blit time, ie it occurs after scaling dimensions.

Yet another “phenomena” (okay it’s late and my vision is narrowing) is that the stretching/scaling operation is imperfect, I haven’t tried with GIMP or anything but what I observed:

shows that colour fades towards the end of the stretch, it is darker. It might not be a 100% effective hack but I would have prefered 20x20 tiles to begin with :frowning:

I fixed it up a bit by extending the stretch and reprioritising my drawing (addChild) calls. The image degradation could not be entirely eliminated and I accept a bit is due to floating point rounding and all the scaling going on. I tried dragging a central section over the end and a length of at least 9 pixels was noticeably affected.

Now I come full circle on my original question. Are the textures obtained through calls to Sprite::create("peachyBorders.png", Rect(0, 0, TI_SZ, TI_SZ)); cached (TextureCache) or would the original image need reloading since only a (anonymous) subsection was used?

This is strange… I tried again, this time leaving a blank 1 pixel between the three 10x10 blocks (scaled in screenshots).

The distortion is even more pronounced at the edges! Wasn’t expecting that.

The solution, was to break the 3 sprites into their own files and do away with sub rectangles. This is what I always used to do but is a bit pants for animation these days, which I thought was cocos2d-x’s forte. Anyway fixed now, but I dislike having 3 400byte files cluttering up clusters of flash memory, here I defer to the dev’s superior knowledge of phone internals and wear leveling.