pan and scale the view
i have readed many topics but i'm very confused. i don't know if use camera, parallax node, move layers....? i'm trying to make a simple program for test: the 2d scene i'd like to display is: 1) background image 2) some selectable points on background 3) some other sprite 4) on touch drag and drop i'll pan all objects, on second pan event i'll pan the object from the new l开发者_运维百科ocation (not the beginning location) 5) scaling with two fingers with the center of scaling is the center of the image actually displayed which implementation should i follow? thanks
i have wrote this for now. bg is a sprite in background, layer2 is a layer with a draw method that draws rectangles (for debug) over CGRectMake areas to make some areas selectable. i've not implemented anchor point to scale it from the center displayed in the screen, need help here... and when i scale and pan the area selectable with cgrectmake are not where displayed by draw method. draw method is scaled and panned...but selecrable area remain where they were before...
-(BOOL)ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event{
oldLoc =[self convertTouchToNodeSpace: touch];
oldPosition=bg.position;
//NSLog(@"Start point: %f %f",firstPoint.x,firstPoint.y);
return YES;
}
-(void)ccTouchMoved:(UITouch *)touch withEvent:(UIEvent *)event{
CGPoint location =[self convertTouchToNodeSpace: touch];
bg.scale+=0.1;//self.anchorPoint=ccp(0,0.54);
layer2.scale+=0.1;
newLoc.x=location.x-oldLoc.x;
newLoc.y=location.y-oldLoc.y;
bg.position=CGPointMake(oldPosition.x+newLoc.x,oldPosition.y+newLoc.y);
layer2.position=bg.position;
}
-(void)ccTouchEnded:(UITouch *)touch withEvent:(UIEvent *)event{
//bg.anchorPoint=newLoc;
CGPoint pp=[self convertTouchToNodeSpace: touch];
if ( CGPointEqualToPoint(oldLoc,pp) ) {
NSLog(@"clik ");
test *cc=(test*)[self getChildByTag:888];
//NSLog(@"%@",(CGRectContainsPoint([cc getcaselle:0],pp) ? @"si":@"no"));
for (int i=0; i<[cc getnumrect]; i++) {
//NSLog(@"casella: %d", [cc getcaselle:i]);
//if(CGRectContainsPoint([[self getChildByTag:888] getcaselle:i ],pp)) NSLog(@"botton %d",i);
}//contiene
}//for
return;
}
}
精彩评论