Question

I have just started to looking at cocos2d and much interested to learn.
Basically i just want to draw a little solid circle (like a dot around 20 radius) where i touch the screen and it can only enable after pressing a button. How can i do this ?

For button i am using CCMenuItem. This is the code.

-(id) init
{

    CCMenuItem *enableBtn = [CCMenuItemImage itemFromNormalImage:@"refresh-icon.jpg" selectedImage:@"Button1.png" target:self selector:@selector(drawEnable:)];

    enableBtn.position = ccp(10, 60);
    enableBtn.scale = 0.1;

    CCMenu *menu = [CCMenu menuWithItems:enableBtn, nil];
    menu.position = ccp(30, 10);
    [self addChild:menu];
}

- (void) drawEnable:(id)sender{

}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {


}

After tapping this button only , i want a circle where ever i touch on the screen.

Please help me in this. I have searched and tried many thing but not able to achieve the clear knowledge or idea about this thing.
Your suggestions are welcome.

Thank you ,

Was it helpful?

Solution

Here what you can do :

  1. When the button is tapped set one boolean variable to true.

  2. In touchesBegan method first check if that boolean variable is true, If it is then only insert the sprite/Dot or what ever you are willing to insert.

  3. and then just set that boolean variable to false.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top