I am extremely new to programing and I apologize in advance for any inconvenience my ignorance may cause someone. Also thank you in advance. I have a sprite that represents the bullet holster on a revolver, The effect I am looking to accomplish is to have touch effect the rotation of the holster. I have all of the trig figured out and am almost accomplishing the desired result. Upon the very first instance of ccTouchMoved the bullet holster jumps to conform its rotation to the touch, almost like there is a point on the holster that is synched with the touch. After that it spins like you would expect. How do I get it to rotate relative to where I left off on my last touch?`
#import "MainScene.h"
@implementation MainScene
+(id) scene
{
CCScene *scene = [CCScene node];
MainScene *layer = [MainScene node];
[scene addChild: layer];
return scene;
}
-(id) init
{
if ((self=[super init])) {
CGSize size = [[CCDirector sharedDirector] winSize];
dial = [CCSprite spriteWithFile:@"dial.png"];
dial.position = ccp(size.width/2, dial.contentSize.height/2);
[self addChild:dial];
self.isTouchEnabled = YES;
[self scheduleUpdate];
}
return self;
}
-(void) ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
NSLog(@"Touch begun");
}
-(void)update:(ccTime) dt{
dial.rotation = cocosAngle;
}
-(void) ccTouchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
NSLog(@"Touch moved");
UITouch *touch = [touches anyObject];
CGPoint touchLocation = [touch locationInView:[touch view]];
CGPoint touchingPoint = [[CCDirector sharedDirector] convertToGL:touchLocation];
CGPoint vector = ccpSub(touchingPoint, dial.position);
CGFloat rotateAngle = -ccpToAngle(vector);
deltaAngle = CC_RADIANS_TO_DEGREES( rotateAngle);
}
...
@end`
`
This is the scene. I am trying to keep it as simple as possible for now. I just began prototyping and already hit this speed bump. I have searched everywhere and tried everything I could think of but cannot get it to do what I want.