У меня возникли проблемы с использованием SneakyJoystick и ccTouchEnded.
Какова моя цель, использовать джойстик для обхода и касания для взаимодействия с окружающей областью.
У меня есть два слоя, ControlLayer (z: 2) и GamePlayLayer (z: 1) Я использую TiledMap для моей земли и карты.Сам джойстик работает нормально, он присоединен к ControlLayer.Я могу ходить, сталкиваться и все такое.
Когда я добавляю события Touch в GamePlayLayer, сенсор работает, я могу нажать на что-нибудь на «земле» и взаимодействовать с ним.НО мой джойстик не работает, тогда, если я бегу, используя сенсорный, джойстик просто сидит там, не реагируя.
Вот часть моего кода, если вам, ребята, нужно больше, просто спросите.
Нажмитеметоды в GameplayLayer
-(void) registerWithTouchDispatcher
{
[[CCTouchDispatcher sharedDispatcher] addTargetedDelegate:self
priority:0 swallowsTouches:YES];
}
-(BOOL) ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event
{
return YES;
}
-(void) ccTouchEnded:(UITouch *)touch withEvent:(UIEvent *)event
{
CGPoint touchLocation = [touch locationInView: [touch view]];
touchLocation = [[CCDirector sharedDirector] convertToGL: touchLocation];
touchLocation = [self convertToNodeSpace:touchLocation];
CGPoint tileCoord = [self tileCoordForPosition:touchLocation];
int tileGid = [meta tileGIDAt:tileCoord];
if (tileGid) {
NSDictionary *properties = [tileMap propertiesForGID:tileGid];
if (properties) {
NSString *collectable = [properties valueForKey:@"Collectable"];
if (collectable && [collectable compare:@"True"] == NSOrderedSame) {
[meta removeTileAt:tileCoord];
[foreground removeTileAt:tileCoord];
}
}
}
}
И как устроена моя сцена:
@implementation SandBoxScene
-(id)init {
self = [super init];
if (self!=nil) {
//Control Layer
controlLayer = [GameControlLayer node];
[self addChild:controlLayer z:2 tag:2];
//GamePlayLayer
GameplayLayer *gameplayLayer = [GameplayLayer node];
[gameplayLayer connectControlsWithJoystick:[controlLayer leftJoyStick]
andJumpButton:[controlLayer jumpButton]
andAttackButton:[controlLayer attackButton]];
[self addChild:gameplayLayer z:1 tag:1];
}
return self;
}
@end
Спасибо за помощь!