Ok, I have this switch statement set up so that the graphics will alternate depending on the direction that is pressed, but what I'm doing now is just not working correctly. If you could take a look at my switch statement and give me your opinion as to why my dpadright.png is always the image displayed no matter what that would be great. I have the switch set up in two different locations for trial and error in my GameplayLayer class and the SneakyJoystick.m and header (it is currently commented out in the SneakyJoystick.m class). This right here is a snippet from my GameplayLayer class:
// GameplayLayer.m
#import "GameplayLayer.h"
@implementation GameplayLayer
//-(void)dealloc {
// [leftDPad release];
// [actionButton release];
// [super dealloc];
//}
-(void)initDPadAndButtons {
CGSize screenSize = [CCDirector sharedDirector].winSize;
CGRect dpadBaseDimensions = CGRectMake(0, 0, 100.0f, 100.0f);
CGRect actionButtonDimensions = CGRectMake(0, 0, 65.0f, 65.0f);
CGPoint dpadBasePosition;
CGPoint actionButtonPosition;
CCLOG(@"Setting up D-Pad and Action Button");
dpadBasePosition = ccp(screenSize.width * 0.13f,
screenSize.height * 0.17f);
actionButtonPosition = ccp(screenSize.width * 0.90f,
screenSize.height * 0.13f);
SneakyJoystickSkinnedBase * dpadBase =
[[[SneakyJoystickSkinnedBase alloc] init] autorelease];
SneakyJoystick * joystick =
[[[SneakyJoystick alloc] init] autorelease];
dpadBase.position = dpadBasePosition;
dpadBase.backgroundSprite = [CCSprite spriteWithFile:@"dpad.png"];
// This is what is giving me a lot of trouble
switch (joystick.currentDirection) { // currentDirection is declared in SneakyJoystick.m
case 0: // which tells the game which direction is being pressed
dpadBase.thumbSprite = [CCSprite spriteWithFile:@"dpadright.png"];
CCLOG(@"Altering Direction right");
break;
case 1:
dpadBase.thumbSprite = [CCSprite spriteWithFile:@"dpadup.png"];
CCLOG(@"Altering Direction up");
break;
case 2:
dpadBase.thumbSprite = [CCSprite spriteWithFile:@"dpadleft.png"];
CCLOG(@"Altering Direction left");
break;
case 3:
dpadBase.thumbSprite = [CCSprite spriteWithFile:@"dpaddown.png"];
CCLOG(@"Altering Direction down");
break;
default:
dpadBase.thumbSprite = [CCSprite spriteWithFile:@"dpaddefault.png"];
CCLOG(@"Altering Direction default");
break;
}
//dpadBase.thumbSprite = [CCSprite spriteWithFile:@"dpaddefault.png"];
dpadBase.joystick = [[SneakyJoystick alloc] initWithRect:dpadBaseDimensions];
leftDPad = [dpadBase.joystick retain];