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

Member
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];
p.x=(panLayer.position.x+(240-p.x));
p.y=(panLayer.position.y+(160-p.y));
[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)
thanks
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 6,042 Mar 16, 2009 06:31 PM
Last Post: AnotherJake
  Camera work. centering mouse FreeKQuency23 5 3,937 Apr 14, 2006 01:14 AM
Last Post: akb825
  [NSWindow center] not centering maaaaark 9 7,165 Mar 13, 2005 12:34 PM
Last Post: maaaaark