views:

83

answers:

1

Hi, all! I'm developing a game in which I have a bow and arrow. I have to move both bow and arrow imageViews on touch through different angles for which I'm applying CGAffineTransform.

The problem is this that after rotation, bow and arrow change their positions, so the arrow does not stay at the center of the bow. I want to fix this arrow at the center point of bow and move along with the bow.

I'm applying the same angles to both bow and arrow, but it seems that the bow is changing its center after transform. While detecting touch, I'm needed to provide the touch position to arrow throgh its center, so I even cant use the center property of arrow to fix it at a certain point.

Can anybody please help me? It's really urgent.

A: 

I would place both UIImageViews in a container UIView and rotate that instead. This will keep the bow and arrow together. I hope I'm understanding your requirements correctly. You can also look into the CALayer anchorPoint property which will affect which point the view is rotated around. Changing it will move the view though, so you do need to compensate for this.

David Kanarek
David, actually I'm not using CALayer. Also, I want to move the arrow along the touch position so I cant keep them in a view. So, it's like the bow is simply rotating and arrow is rotating as well as moving along the touches but at the same angle. How to make this happen "move arrow along the touches but keep the angle same".
neha
UIImageViews actually have a CALayer (the UIView's layer property). It sounds like adjusting the anchorPoint will help, but I'm not sure exactly what's going on. Take a look at http://developer.apple.com/iphone/library/documentation/Cocoa/Conceptual/CoreAnimation%5Fguide/Articles/Layers.html#//apple%5Fref/doc/uid/TP40006082
David Kanarek