COCOS2DX, Adding Sprite To Parent - c++

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.

Related

QTabWidget with QGraphicsView

I have a QTabWidget and second page containing a QGraphicsView with scene. The scene canvas is larger than the QGraphicsView's viewport and I'm using QScrollBar to move objects on the scene.
On the scene I place a lot of QGraphicsItem objects. I have a horizontal and a vertical scroll bar, and some items can move only horizontally, another objects on scene can move only vertically.
My QGraphicsview coordinates start at the top left corner of QGraphicsview. After moving objects on the scene, if I change the page of the QTabWidget from second page to first and then back again, the start of coordinates is moved to the center of QGraphicsView, and all objects on the scene are moved to new positions automatically.
This happens only when I'm using a QTabWidget, if I change the parent of QGraphicsView to QWidget, all works well.
I found a solution. Just need to calculate rect of the scene, and set obviously using QGraphicsScene::setSceneRect() method. Otherwise, position of my scene in the QGraphicsView may surprise.

Ignore transformation of QGraphicsItem's shape

My reimplemented QGraphicsItem draws a circle. It has flag ItemIgnoresTransformations, so it has always the same size when scaling. Should I set transformations manually for item's shape function to be accurate or there exists easy way? I need shape function for processing mouse events for this circle in QGraphicsScene.

ccsprite texture rect changes based on parent scaling?

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...

How to draw a rectangle in an image which will only be shown when mouse moves over certain location in opencv?

In openCV, i need to do the following: when user moves mouse over certain location, a rectangle will be shown over the image but when he moves cursor out of the location , the rectangle will be gone.
i am new to opencv, i can draw rectangle on mouse move event but i can't figure out how to undo the drawing after the event.
Store the region of the original image that will be drawn over by the rectangle in a separate Mat. When the cursor is removed, copy the stored region back to its original location.

CCNode's position

This post discusses cons/pros of subclassing CCSprite or having CCSprite as member.
Suppose I have a CCNode which has a CCSprite as a member.
Then I'll add the CCNode as a child to my layer
and add CCSprite to the CCNode.
Now I want to change the position of CCSprite, should I change the position of the CCNode which contains the CCSprite or CCSprite itself?
If I change CCSprite's position, what happens to the CCNode's position?
edit
Is this considered an acceptable practice?
Am I better off setting CCNode's position and let CCSprite be positioned wherever CCNode is?
Adding a CCSprite as a child of a CCNode can be helpful when you have multiple sprites that you want to move along with the node.
Consider the example of a player sprite. Say you want to put a shadow underneath the player. Adding both the shadow sprite and the player sprite to a parent CCNode allows them both to be moved easily.
If you have a single sprite that has no other sprites you want to move along with it, then you don't need the CCNode parent.
nothing will be happened with your sprite. if you do not set content size and anchor point to your sprite's container, position of the node always will be equal to the position of node's (0.f, 0.f). so, position of your sprite will be related to it's parent (0.f, 0.f)
Basically, all Node in cocos2d-x have a parent Node (except Scene).
Changing the position of a parent Node will apply the position changes to all its child,
Changing the position of a Child Node will not affect anything unless this Child Node has its own children.
In your Example, If you change the CCSprite position, the position of CCNode will remain the same. But, if you changed the position of your CCNode, the same changes(shifting on the screen) will happen on the Sprite.
You want to set the sprite's position. The simple reason being that the node may contain other child nodes which should be able to move independently from the sprite.
Changing a node's position does not affect the parent's position at all. Likewise, changing a parent's position does not change the child node positions at all. Child node positions are an offset to their parent position, so if you move the parent they will follow along but their position property (which is relative to the parent position) remains the same.
You'd better move the CCNode's position cause the position of the CCSprite is also affected by its parent.
Although by moving the CCSprite's position you'll get the same result visually(its parent is not moved), it makes getting the position of a sprite more complicated and confusing.