Android 9patch Equivalent

Android 9patch Equivalent
0.0 0



I’m new to Cocos2dx and pretty new to game development in general. I was looking for some help / direction as to finding a Android 9patch equivalent.
See Android 9patch description here:
Basically you have a 1px transparent border around an image and draw black pixels in the top and left border to define which areas can be repeated (and where the content should be placed when we’re talking about control backgrounds).

In my case I’m trying to stretch an image to become my game’s background. In the corners there’s some complicated lines that I want to keep at px size, while a range of pixels along X and Y can be repeated without causing issues.

I’ve been playing with CCScale9Sprite, from what I could tell it was the closest to what I was looking for with no luck.
Everytime I setCapInsets the image goes invisible.

Can anyone help me with this or have some code examples achieving something similar?


bgTest2.9.png (25.5 KB)


Hm, ok. This isn’t perfect but I’m on my way to “getting it”. I originally was lacking the setContentSize call, so content size was 0 and there was no need to show the image.
The CCRect inset params are the X location of the stretching pixel, the Y location of the stretching pixel, a number that’s not 0 because it was playing up * 2.

@ CCScale9Sprite *bgQuestion = CCScale9Sprite::create(“bg_question.png”, CCRectZero, CCRect(208.75f, 211.25f, 0.01f, 0.01f));
bgQuestion~~>setPosition(ccp(winSize.width / 2.0f, winSize.height / 2.0f));@

If anyone has suggestions on how to improve this (I’m guessing the cap insets are way off what they should be) let me know! :slight_smile:
I’m still fiddling but thought I’d post in case someone finds this later in same position I was.