ccsprite texture rect changes based on parent scaling? - cocos2d-iphone

I am using Cocos2d 2.2, and am experiencing the following:
I have a sprite added as a child to a CCNode. The sprite's anchor point is 0,0. The CCNode's anchor point is 0,0. I've got a CCNode with an anchor point of 0.5,0.5 and in it I add a child with the following rect: 0,363,165,231).
I then add that CCNode as a child to another CCNode with an anchor point of 0,0...
All is well.. Looks perfect.
I scale that CCNode down to 0.5
All of a sudden, I see at the top of my sprite, garbage from the texture that is not part of it's texture rect.
Why in the world does scaling down a CCNode change the texture coordinates?!
Note, if the CCNode has an anchor point of 0,0 this doesn't happen. Only when its 0.5, 0.5...

Related

COCOS2DX, Adding Sprite To Parent

I have created the ball sprite as a parent sprite and i need to add a child sprite in all the boundary of the parent sprite. by defaultly the parent image png it take as square shape, But i want to add like circle. What i can do in COCOS2d-X to add child around circle boundry?
Try drawing a circle, you can use this post as reference. This drawn circle has a perfect round boundary. Attach that to your parent circle image (the one with square boundaries) and set it to invisible. Now you can use attach the child sprites to that invisible drawn circle. It will have the illusion that the child sprites are attached to the circle image.

How to scale a CCLayer and keep its position?

At the end of the game, I want to zoom out my CCLayer to show all the sprites. When I reduce the scale, the CCLayer become smaller and centered, what I want to know is how to scale the CCLayer and keep its y=0 (Origin at the bottom of the screen). Thanks in advance.
Best regards,
I believe that all CCNode children have an anchorPoint property. CCLayer defaults to (.5,.5) , midScreen. Try setting your layer's anchor point to (0.,0.).

setTransformOriginPoint not working as expected

I inherited from the QGraphicsObject and created a new class that has a pixmap and sets its transform origin point to:
setTransformOriginPoint(boundingRect().center());
But when I call setRotation() on the my class (which is added to a QGraphicsView using the scene), the rotation doesn't use the center as the rotation anchor. How can I set the center to be the anchor of the rotation ? Thanks !
More information: calling setRotation() outside of a sceneEvent function it works, but inside a sceneEvent, upon a pinch gesture, the origin point doesn't work.
Draw pixmap at QRect(0, 0, pixmap.width(), pixmap.height(). Use this rectangle for bounding rect also. Use setPos to move the item around the scene. Use setTransformOriginPoint(pixmap.width() / 2, pixmap.height() / 2) to set the origin point. These coordinates are in the item coordinates, so they should point at the pixmap's center regardless of the item's position.

How can I display the anchorpoint for a CCNode in cocos2d?

Is there a way to display a CCNode's anchor point? This would be very useful for debugging.
Not built-in, but you could draw a point or circle at the anchor point location using the anchorPointInPoints property.
-(void) draw
{
[super draw];
ccDrawCircle(self.anchorPointInPoints, 20, 0, 8, YES);
}
Of course, I always recommend not to change the anchorPoint in the first place. The alternative is to add the node to a parent node, offset it from the parent, and then the parent's position acts like the anchorpoint for the child node. The advantage is that methods like boundingBox aren't offset from the node's position (can be an issue for hit detection), and you can rotate the child node around its center point and around its parent.
You can access the anchor point of a CCNode with
- (CGPoint) anchorPointInPixels
which is a readonly method. Afterwards, you have several ways of actually marking the spot. You could use
- ccDrawCircle()
while overriding the draw method or alternatively put up a texture on that point, if you want something fancier.

Cocos2d: Change sprite's zOrder dynamically (using CCSpriteBatchNode)

Is there a way to change the zOrder of a sprite rendered by CCSpriteBatchNode? I've tried it like this:
[self reorderChild:mySprite z:indexOfAnArray];
I get this error: 'If CCSprite is being rendered by CCSpriteBatchNode, CCSprite#draw SHOULD NOT be called'
I also tried with the zOrder property of the sprite but unfortunately is read-only.
I need to change the zOrder because, depending on the position where my sprite will appear, the zOrder needs to be changed.
self is probably not the parent of sprite. Remember that the parent is the CCSpriteBatchNode that holds it, and self is, from your point of view, probably the scene.