Can CCArray contain CCScale9Sprite?

Hi.
I want to insert CCScale9Sprite image to CCArray.

This is my code.:frowning:

for (int i=0; i < BOX_WIDTH; i++) {
	for (int j=0; j < BOX_HEIGHT ; j++) {
		float boxSize = (m_winSize.width/BOX_WIDTH);
        CCScale9Sprite *box = CCScale9Sprite::create("Red_default.png", CCRectMake(0, 0, 56, 56));
        box->setContentSize(CCSizeMake(boxSize, boxSize));
        box->setAnchorPoint(ccp(0,0));
        box->setPosition(ccp((boxSize*i), 300+(boxSize*j)));

        boxArray[i+j] = *box; // ******** Error Line ********
        this->addChild(box);

	}
}

Ah, boxArray is already declared.

What should I do?
plz help me.:frowning:

You can indeed, CCArray can to hold any instances derived from CCObject.

Can you show us more code, especially the definition of boxArray?
Using boxArray[i+j] you treat it as if was an array of CCArrays, notation array[index] is equivalent to *(array + index). As the STL said:

When a C or C++ compiler sees this, the array is immediately rewritten to be a pointer. This rewriting is so immediate that sizeof and decltype will observe a pointer.

What you probably meant was: boxArray->objectAtIndex( i+j ) = box;

@kuhar wrote:

You can indeed, CCArray can to hold any instances derived from CCObject.

Can you show us more code, especially the definition of boxArray?
Using boxArray[i+j] you treat it as if was an array of CCArrays, notation array[index] is equivalent to *(array + index). As the STL said:

When a C or C++ compiler sees this, the array is immediately rewritten to be a pointer. This rewriting is so immediate that sizeof and decltype will observe a pointer.

What you probably meant was: boxArray->objectAtIndex( i+j ) = box;

Ooops.

boxArray = CCArray::createWithCapacity(BOX_WIDTH*BOX_HEIGHT);

and GameScene.h…

CCArray* boxArray;

I want to touch box…

Showed avobe code in init();

bool GameScene::ccTouchBegan(CCTouch *pTouch, CCEvent* pEvent)
{
CCPoint touchPoint = pTouch->getLocation();

CCLog("Touches Began..(%f,%f)",touchPoint.x,touchPoint.y);

for (int i = 0; i <BOX_WIDTH; i++){
	for (int j = 0; j < BOX_HEIGHT; j++) {
		CCScale9Sprite *box;
		box = (CCScale9Sprite*)boxArray[i+j];
		CCRect rect =box->boundingBox();

	    if (rect.containsPoint(touchPoint)) {
	        CCLog("Touch...");
	        return true;
	    } else {

	    }

	}
}

return true;

}

I know this code is wrong. but I don’t know what to do.

I tried to 'CCScale9Sprite::create(“Red_default.png”, CCRectMake(0, 0, 56, 56));'inserted box…and that boxes is boxArray[].
Then. boxArray[] input TOUCH!!

I want to touch box that I declared the CCScale9Sprite box.

Can I declare ‘box’ global variable?:frowning:

Can you present us whole .h and .cpp file?