centering a sprite in the middle of the screen convertToWorldSpace / NodeSpace

Posts: 164
Joined: 2010.10
Post: #1
i have passed many many days on this problem, i've not very clear in mind what convertToWorldSpace, convertToNodeSpace does...

i have 2 layer (CCNode) one that i can scale, one for panning the screen, so i scale always what is displayed makeing the center of scaling the middle of the screen:
scaleLayer=[CCNode node];
scaleLayer.position= ccp( size.width /2 , size.height/2 );
[self addChild:scaleLayer z:-2000];

panLayer=[CCNode node];
panLayer.position= ccp( -size.width /2 , -size.height/2 );
[scaleLayer addChild:panLayer z:-2000];

now i add sprites to panlayer:
[panLayer addChild:mysprite z:2];

i'd like to have a button that, when pressed, moves panlayer to make the sprite in the middle of the screen.
i have wrote this but works only if scaleLayer.scale=1
CGPoint p;
p=[panLayer convertToWorldSpace:mysprite.position];
[panLayer runAction:[CCMoveTo actionWithDuration:0.5 positionRasp]];

how can i make the sprite to be at center of the screen with different scales?
i thought to find the distance in pixels in scaleLayer coordinates while convertToWorldSpace find the absolute coordinates (if i had understood well)
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Have Hierarchical Sprite Tree, Need To Transform Screen X,Y To Determine Which Sprite kalimba 5 8,798 Mar 16, 2009 06:31 PM
Last Post: AnotherJake
  Camera work. centering mouse FreeKQuency23 5 6,015 Apr 14, 2006 01:14 AM
Last Post: akb825
  [NSWindow center] not centering maaaaark 9 10,927 Mar 13, 2005 12:34 PM
Last Post: maaaaark