Adding Accelerometer Data

So easy.

Add to the init method

self.isAccelerometerEnabled = YES;

Then somewhere in your class, stick the following

- (void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration {
NSLog(@"tilting %f", acceleration.z);
//accelerator x
//So tilting to the left goes towards -1, tilting to the right goes towards 1;
//accelerator y
// tiling forward goes towards -1, tilting backwards goes towards 1;
//accelerator z
// flicking it upwards it goes towards and past 2, flicking it downwards it goes towards and past -2;
}

NSLog CCLOG Format Specifiers

I can never remember which one to use, so here’s the list

%@     Object
%d, %i signed int
%u     unsigned int
%f     float/double

%x, %X hexadecimal int
%o     octal int
%zu    size_t
%p     pointer
%e     float/double (in scientific notation)
%g     float/double (as %f or %e, depending on value)
%s     C string (bytes)
%S     C string (unichar)
%.*s   Pascal string (requires two arguments, pass pstr[0] as the first, pstr+1 as the second)
%c     character
%C     unichar

%lld   long long
%llu   unsigned long long
%Lf    long double

Detecting touch of a sprite in a sprite sheet

Because I’m going to be doing this a lot, I’m making a note of it.

So at the top of my page.m

enum {
kTagSpriteSheet = 1,
kTagSprite = 2,
};

In my init function

mySheet = [CCSpriteSheet spriteSheetWithFile:@"myatlas.png"];
[self addChild:mySheet z:0 tag:kTagSpriteSheet];

// create the sprite
mySprite = [CCSprite spriteWithTexture:mySheet.texture rect:CGRectMake(0, 0, 200,200)];
[mySheet addChild:mySprite z:0 tag:kTagSprite];

Then in ccTouchesEnded method

BOOL *isSpriteTouched = NO;

UITouch *touch = [touches anyObject];
CGPoint location = [touch locationInView:[touch view]];
location = [[CCDirector sharedDirector] convertToGL:location];
CCSpriteSheet *mySheet = (CCSpriteSheet*) [self getChildByTag: kTagSpriteSheet];
CCSprite *mySprite = (CCSprite*) [mySheet getChildByTag: kTagSprite];
CGRect myRect = CGRectMake(mySprite.position.x, mySprite.position.y, mySprite.contentSize.width,
mySprite.contentSize.height);

if(CGRectContainsPoint(myRect, location)) {
isSpriteTouched = YES;
}

Photoshop Keyboard Shortcuts

Since I’m doing the background plates I have to do a bit of photoshop work, and I’m a big one for keyboard shortcuts, so I’m putting them here in case I forget.

[ Decrease brush size

] Increase brush size

Shift [ Decrease brush softness

Shift ] Increase brush softness

Apple  Shift  N New layer