1

I have a problem in using touches in my scene. I’ ve created a sprite (player.ccb) working in Sprite Builder that has a name =player in CCnode section. Here it is the main code written in GameScene : So after opening the simulator nothing doesn’t happen and in the Debug area there is nothing written. Thank you in advance for your help!

//
//  GameScene.m
//  MIOGIOCO18
//
//  Created by Fabio Tavanti on 12/12/15.
//  Copyright (c) 2015 Apportable. All rights reserved.
//

#import "GameScene.h"

@implementation GameScene

{
    __weak CCNode* _levelNode;
    __weak CCPhysicsNode* _physicsNode;
    __weak CCNode* _playerNode;
    __weak CCNode* _backgroundNode;
}
-(void) didLoadFromCCB
{
    // enable receiving input events
    self.userInteractionEnabled = YES;
    // load the current level
    [self loadLevelNamed:nil];
}

-(void) loadLevelNamed:(NSString*)levelCCB
{
    // get the current level's player in the scene by searching for it recursively
    _playerNode = [self getChildByName:@"player" recursively:YES];
    NSAssert1(_playerNode, @"player node not found in level: %@", levelCCB);
}
//-(void) touchBegan:(CCTouch *)touch withEvent:(UIEvent *)event
-(void) touchBegan:(CCTouch *)touch withEvent:(CCTouchEvent *)event


{
    NSLog(@"okaay pressed");
    _playerNode.position = [touch locationInNode:self];


}

@end
fabi8
  • 11
  • 2

1 Answers1

0

I don't know how you structured your ccb file and if you made proper relation to your actual GameScene, so best thing for you would be to put

self.userInteractionEnabled = YES;

in the GameScene's onEnter method...