I'm afraid that I'm missing something. This is what I've done:
- I've made a scene using layers (Gimp), then I've exported the layers with the image size, that way I thought would be more easy to add the images and have the offsets in the right way.
- I made a spritesheet with TexturePacker, trimming the images.
Then I have in the plist file something like:
<dict> <key>frame</key> <string>{{1028,360},{326,382}}</string> <key>offset</key> <string>{-316,110}</string> <key>rotated</key> <false/> <key>sourceColorRect</key> <string>{{33,83},{326,382}}</string> <key>sourceSize</key> <string>{1024,768}</string> </dict> Then in my code I've made a CCSprite:
granero = CCSprite::createWithSpriteFrameName("04_Granero.png"); capaGrafica->addChild(granero); pDirector->getTouchDispatcher()->addTargetedDelegate(this, 0, false); And the ccTouchBegan:
bool Escena00::ccTouchBegan(CCTouch* touch, CCEvent* event) { // This point has the touch location info CCPoint touchPoint = CCPoint(touch->getLocationInView().x, touch->getLocationInView().y); // Now I want to set a rect, where a little house in the screen is located CCRect *graneroRect = new CCRect(granero->getOffsetPosition().x, granero->getOffsetPosition().y,granero->getTextureRect().size.width,granero->getTextureRect().size.height); if (graneroRect->containsPoint(touchPoint)) { CCLog("The little house in the left was touched"); } return true; } If you take a look now to the plist extract that I've posted you'll read the "sourceColorRect" key. Those coords are the right numbers that I need to use to create my CCRect (33,83, 326, 382). With those numbers I've been able to correctly get the touch over the little house. However, I don't want to use those numbers with a "hard way". Using granero->getOffsetPositionX(), I get the "33" number, and using the "getTextureRect()" I can get the third and fourth numbers (size of the rect). The big issue is the getOffsetPositionY(), or any "y" coordinate. I can't read the "83" number. How can I solve this? Or what am I doing wrong?
Thanks a lot in advance.