即时通讯使用SneakyJoystick和ccTouchEnded东西有一些麻烦。Cocos2D:SneakyJoystick +触摸事件,问题
我的目标是什么,使用操纵杆走动和触摸与周围地区互动。我有两个图层,ControlLayer(z:2)和GamePlayLayer(z:1) Im使用TiledMap作为我的地面和地图。 由它的游戏杆自我工作正常,它附加到ControlLayer。我可以走路,冒险和东西。
当我将触摸事件添加到GamePlayLayer时,触摸可以工作,我可以点击“地面”上的某些东西并与其进行交互。但我的操纵杆dosent工作,然后,如果我运行使用触摸操纵杆只是坐在那里没有响应。
这里是我的一些代码,如果你们需要更多,请问。在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
感谢您的帮助!