Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- I am having a problem with coordinate systems...
- I create my wheel layer, I stick it in the centre of the screen
- -(id) init
- {
- if( (self=[super init] )) {
- Wheel * wheel = [ [ [Wheel alloc] init] autorelease];
- [wheel setupWithMagnets: 3];
- // takes orientation into account
- CGSize winSize = [[CCDirector sharedDirector] winSizeInPixels];
- printf("%f, %f\n", (float) winSize.width, (float) winSize.height);
- wheel.position = ccp ( winSize.width / 2 - 1, winSize.height / 2 - 1 );
- printf("%f, %f\n", (float) wheel.position.x, (float) wheel.position.y);
- [self addChild: wheel];
- // - - -
- }
- return self;
- }
- Now straightaway I don't understand why it positions itself correctly with the centre of the layer in the centre of the screen
- surely it would only do this if the wheel's self.anchorPoint = ccp (.5, .5);
- but I never explicitly set it, and the default is 0,0
- - (void) setupWithMagnets: (int) in_magnets
- {
- self.magnets = in_magnets;
- self.magnetOffset = 0;
- //self.anchorPoint = ccp (.5, .5);
- CCLayerColor* colorLayer = [CCLayerColor layerWithColor: ccc4(0, 67, 67, 67)];
- colorLayer.anchorPoint = ccp (.5, .5); // << makes no diff
- [self addChild:colorLayer z: -1];
- thetaWheel = 0.;
- dTheta_dt = 0.;
- mass = K_WHEEL_MASS;
- tracking = NO;
- [self schedule: @selector(displayLinkIsCallingBack:)];
- [[CCTouchDispatcher sharedDispatcher] addTargetedDelegate: self
- priority: 0
- swallowsTouches: YES];
- //displayLink = [CADisplayLink displayLinkWithTarget: self
- // selector:
- // @selector(displayLinkIsCallingBack:) ];
- //[displayLink addToRunLoop: [NSRunLoop currentRunLoop]
- // forMode: NSDefaultRunLoopMode ];
- CCSprite * centerMarker = [CCSprite spriteWithFile: @"Icon.png"];
- centerMarker.anchorPoint = ccp (.5, .5);
- centerMarker.position = ccp(0, 0);
- [self addChild: centerMarker];
- for (int i=0; i<3; i++)
- {
- CCSprite * button = [CCSprite spriteWithFile: @"seeker.png"];
- float RADIUS = 150.;
- float theta = M_TWO_PI * (i / 3.) - M_PI / 2.;
- button.anchorPoint = ccp (.5, .5);
- button.position = fromPolar(RADIUS, theta);
- [self addChild: button];
- }
- }
- - (void) displayLinkIsCallingBack: (ccTime) deltaT
- {
- // Display link fires every time the screen is to be refreshed
- // The wheel remembers its angle and its velocity
- // Each time display link fires, potentially TWO forces act upon the wheel
- // (1) When user initiated contact, fingerprint position on wheel was recorded
- // as finger moves, invisible elastic stretches between finger and fingerprint,
- // pulling wheel towards finger
- BLA
- // (2) imagine a magnet sitting behind the centre of each button.
- // These magnets encourage the wheel to settle exactly in
- // one of its preset positions
- BLA
- // using CATransaction like this goes from 14fps to 19fps
- //[CATransaction begin];
- //[CATransaction setDisableActions: YES];
- // NEG, as coord system is flipped/fucked
- //self.transform = CGAffineTransformMakeRotation(-thetaWheel);
- #define FAC (-360. / M_TWO_PI)
- self.rotation = FAC * (-thetaWheel);
- //[CATransaction commit];
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement