CAShapeLayer for Drawing Lines; Animations Skewed

2009-09-10 Thread Christopher J Kemsley

Hi all,

In my current development project, I have numerous dots that will be  
moved around periodically, each connected by a line.


The dots are represented as CALayers, with the contents set to a  
simple 20x20 dot, and they are moved around by animating the  
position property.


The connecting lines will be drawn between the centers of two dots,  
and will be moved via an animations whenever the dots change position.


This is where I'm running into trouble. Any suggestions on how to fix  
what I've done so far or suggestions for a different, easier approach  
are more than welcome.



What I've tried:

CALayer with 50x1 Square as Contents

In this method, I used a 50x1 square. For every animation, I set the  
bounds to:


CGRectMake ( 0 , 0 , absoluteDistanceBetweenPoints , 1 ) ;

and the transform to

CATransform3DMakeRotation ( angleBetweenPoints , 0 , 0 , 1 ) ;

This worked, but had the unfortunate side-effect of, during some of  
the moves, rotating too far around in the wrong direction, making the  
endpoints come out from under the points.  (For example, instead of  
rotating 90º, it would rotate 270º in the wrong direction. This, in  
theory, is easy to fix, but isn't as easy as it sounds.



CAShapeLayer with Path from PointA to PointB

In this method, I used a CAShapeLayer with the correct color and a 1px  
width. I made a path between the two points.


For moves, I created another path representing the new position and  
used a CABasicAnimation to animate the path property.


This also 'works,' but also has a side-effect: A line, instead of  
animating from (oldPointA,oldPointB) to (newPointA,newPointB) would  
animate to (oldPointA,oldPointB) to (randomPoint,randomPoint) to  
(newPointA,newPointB)   (Note:  (aPoint,bPoint) represents a line/ 
path from aPoint to bPoint)




Any suggestions for improving these methods (especially fixing the  
CAShapeLayer, which would be optimal) would be greatly appreciated!


Thanks,
-Christopher___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: CAShapeLayer for Drawing Lines; Animations Skewed

2009-09-10 Thread John Harper


On Sep 10, 2009, at 7:20 PM, Christopher J Kemsley wrote:


CAShapeLayer with Path from PointA to PointB

In this method, I used a CAShapeLayer with the correct color and a  
1px width. I made a path between the two points.


For moves, I created another path representing the new position and  
used a CABasicAnimation to animate the path property.


This also 'works,' but also has a side-effect: A line, instead of  
animating from (oldPointA,oldPointB) to (newPointA,newPointB) would  
animate to (oldPointA,oldPointB) to (randomPoint,randomPoint) to  
(newPointA,newPointB)   (Note:  (aPoint,bPoint) represents a  
line/path from aPoint to bPoint)


yes, that looks like a bug, please file a radar so we can track it. (bugreport.apple.com 
)


for now I think you can get the right result by giving each line three  
points instead of two, the easiest way to do that is just add an extra  
point with the same coordinates as the end point.


John


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com