ccTouchBegan doesnt work-iOS - cocos2d-iphone

- (BOOL)ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event {
if (_nextProjectile != nil) return;
CGPoint location = [touch locationInView:[touch view]];
location = [[CCDirector sharedDirector] convertToGL:location];
[[SimpleAudioEngine sharedEngine] playEffect:#"pew-pew-lei.caf"];
CGSize winSize = [[CCDirector sharedDirector] winSize];
CGRect rect = CGRectMake(imgArrow.position.x, imgArrow.position.y,imgArrow.contentSize.width, imgArrow.contentSize.height);
if(CGRectContainsPoint(rect, location))
{
**_nextProjectile = [[CCSprite spriteWithFile:#"newarrow.png"]retain];
_nextProjectile.position = ccp(430,190);**
[imgArrow runAction:[CCSequence actions:
[CCRotateTo actionWithDuration:0 angle:0],
[CCCallFunc actionWithTarget:self selector:#selector(finishShoot)],
nil]];
[blankBow setVisible:true];
[imgArrow setVisible:false];
[walkAnimFrames addObject:
[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:
[NSString stringWithFormat:#"bow1.png", 0]]];
[walkAnimFrames addObject:
[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:
[NSString stringWithFormat:#"bow2.png", 1]]];
[walkAnimFrames addObject:
[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:
[NSString stringWithFormat:#"bow3.png", 2]]];
walkAnim = [CCAnimation animationWithFrames:walkAnimFrames delay:0.2f];
self.walkAction = [CCRepeatForever actionWithAction:
[CCAnimate actionWithAnimation:walkAnim restoreOriginalFrame:NO]];
self.walkAction.tag = 1;
[blankBow runAction:_walkAction];
CCSprite *sprite = blankBow;
CCCallBlock *block = [CCCallBlock actionWithBlock:^{
[sprite stopActionByTag:1];
}];
CCDelayTime *time = [CCDelayTime actionWithDuration:0.3];
[sprite runAction:[CCSequence actions:time, block, nil]];
if(flagmultitouch == TRUE)
{
id actionMove = [CCMoveTo actionWithDuration:1.5
position:ccp(-48,160)];
id actionMoveDone = [CCCallFuncN actionWithTarget:self
selector:#selector(spriteMoveFinished:)];
[_nextProjectile runAction:[CCSequence actions:actionMove, actionMoveDone, nil]];
flagmultitouch = FALSE;
}
if(_nextProjectile !=nil)
_nextProjectile.tag = 2;
}
else
{
}
return YES;
}
Problem is with
_nextProjectile = [[CCSprite spriteWithFile:#"newarrow.png"]retain];
_nextProjectile.position = ccp(430,190);
when i am initializing __nextProjectile in init method ccTouchBegan method doesn't work..
and by puting _nextProjectile = [[CCSprite spriteWithFile:#"newarrow.png"]retain];
_nextProjectile.position = ccp(430,190);
in ccTouchBegan it initialize every time when Touch performs.
any help ?!!

Enable touch for same layer.
-(void)onEnter
{
[super onEnter];
self.touchEnabled = YES; //In Cocos2d 1.0: self.isTouchEnabled
}
- (void)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
CGPoint location = [touch locationInView: [touch view]];
location = [[CCDirector sharedDirector] convertToGL:location];
}

Related

trying to touch an item in an array not working

I have An Array inside my touches began method (I would like to be able to touch the sprite
and for it to NSlog the touch) is there something im forgetting to do or am doing something wrong?
I can log the touch on the screen but when I touch the bubbles nothing happens.
any help would be great.
-(id) init
{
if((self=[super initWithColor:ccc4(10, 10, 10,10)]) ) //sand 101, 116, 88
{
size = [[CCDirector sharedDirector] winSize];
self.touchEnabled = YES;
//other stuff here
Bubble01 = [[Bubble alloc]initWithBubbleWithLabel:#"_Bubble.png" opacity:255 gloss:#"_Bubble_overlay.png" posX:0 posY:0 data:[NSString stringWithFormat:#"%#", [Sortingarray objectAtIndex:BubbleAnswerBubble_1_IndexValue]]];
Bubble02 = [[Bubble alloc]initWithBubbleWithLabel:#"_Bubble.png" opacity:255 gloss:#"_Bubble_overlay.png" posX:0 posY:0 data:[NSString stringWithFormat:#"%#", [Sortingarray objectAtIndex:BubbleAnswerBubble_2_IndexValue]]];
Bubble03 = [[Bubble alloc]initWithBubbleWithLabel:#"_Bubble.png" opacity:255 gloss:#"_Bubble_overlay.png" posX:0 posY:0 data:[NSString stringWithFormat:#"%#", [Sortingarray objectAtIndex:BubbleAnswerBubble_3_IndexValue]]];
Bubble04 = [[Bubble alloc]initWithBubbleWithLabel:#"_Bubble.png" opacity:255 gloss:#"_Bubble_overlay.png" posX:0 posY:0 data:[NSString stringWithFormat:#"%#", [Sortingarray objectAtIndex:BubbleAnswerBubble_4_IndexValue]]];
Bubble05 = [[Bubble alloc]initWithBubbleWithLabel:#"_Bubble.png" opacity:255 gloss:#"_Bubble_overlay.png" posX:0 posY:0 data:[NSString stringWithFormat:#"%#", [Sortingarray objectAtIndex:BubbleAnswerBubble_5_IndexValue]]];
Bubble06 = [[Bubble alloc]initWithBubbleWithLabel:#"_Bubble.png" opacity:255 gloss:#"_Bubble_overlay.png" posX:0 posY:0 data:[NSString stringWithFormat:#"%#", [Sortingarray objectAtIndex:AnswerBubble_6_IndexValue]]];
//other stuff here
}
return self;
}
touchesbegan
-(void) ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
//set up touches
NSSet *allTouch = [event allTouches];
UITouch *touch = [[allTouch allObjects]objectAtIndex:0];
CGPoint location = [touch locationInView:[touch view]];
location = [[CCDirector sharedDirector]convertToGL:location];
//log if touches are working if I touch the screen area
NSLog(#"touches screen");
//create an array from bubble class (CCSprites with labels,
//I need to be able to determine which sprite was touched and run an action on it)
BubbleArray = [[NSMutableArray alloc]initWithObjects:Bubble01,
Bubble02,
Bubble03,
Bubble04,
Bubble05,
Bubble06,
nil];
for(int i = 0; i < [BubbleArray count]; i++)
{
Bubble *sprite = (Bubble *)[BubbleArray objectAtIndex:i];
//create a rect to find the position and size of the sprite
//BackBubble is a sprite that i'm using to detect the content size
CGRect targetRect = CGRectMake(
sprite.BackBubble.position.x - (sprite.BackBubble.contentSize.width/2),
sprite.BackBubble.position.y - (sprite.BackBubble.contentSize.height/2),
sprite.BackBubble.contentSize.width,
sprite.BackBubble.contentSize.height);
//use the rect and touch location to determine hit
if(CGRectContainsPoint(targetRect, location))
//this doesn't work possibly because Bubble class is a CClayer?
//if(CGRectContainsPoint([sprite boundingBox], location))
{
selectedSprite = sprite;
NSLog(#"touches bubble sprite");
}
}
}
Any insight would be great to help me understand what i'm doing wrong.
cheers :)
new array code (getting the height and width of the sprite through the custom class
for(int i = 0; i < [DragItems count]; i++)
{
Bubble *sprite = (Bubble *)[BubbleArray objectAtIndex:i];
location = [sprite convertToNodeSpace:location];
if(CGRectContainsPoint([sprite.BackBubble boundingBox], location))
{
selectedSprite = sprite;
NSLog(#"touches bubble");
}
}
Bubble.m
#import "Bubble.h"
#import "Common.h"
#define ButtonFlashTime .4
#define KBubbleColourTurqoiseBlueFlash 2323
#define ScrollSpeed 5.2f
#define DecoyTextY 5
#define DecoyTextX -2
#implementation Bubble
#synthesize BackBubble,FrontShine,BubbleLabel,startX,startY,currentY,currentX,isNotTouchActivated,myInt,bubblespeed,tagNumber; //isTouched
-(id)init
{
self=[super init];
{
//touches
[[[CCDirector sharedDirector] touchDispatcher] addTargetedDelegate:self priority:0 swallowsTouches:YES];
isNotTouchActivated = false;
isTouched = NO;
bubblespeed = 0;
//start scrolling
[self MoveWithoutProblem];
[self setAnchorPoint:ccp(0.5,0.5)];
BackBubble = [CCSprite spriteWithSpriteFrameName:Bubblepng];
BackBubble.position = ccp(X,Y);
[BackBubble setAnchorPoint:ccp(0,0)];
[self addChild: BackBubble z:5];
NSLog(#"BackBubble, %f %f",BackBubble.position.x,BackBubble.position.y);
//other code here
[self setContentSize:[BackBubble boundingBox].size];
}
return self;
}
-(BOOL) isTouchOnSprite:(CGPoint)touch{
CGPoint local = [self convertToNodeSpace:touch];
CGRect r = self.boundingBox;
r.origin = CGPointZero;
Boolean b = CGRectContainsPoint( r, local );
//CCLOG(#"touch %f : %f : %d",touch.x,touch.y,b);
if (b) {
return YES;
}else {
return NO;
}
}
- (BOOL)ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event{
CGPoint touchPoint = [touch locationInView:[touch view]];
touchPoint = [[CCDirector sharedDirector] convertToGL:touchPoint];
if([self isTouchOnSprite:touchPoint]){
//CGPoint move = [self convertTouchToNodeSpace:touch];
isNotTouchActivated = TRUE;
//isTouched = YES;
//NSLog(#"isTouched = %#", self.isTouched ? #"YES" : #"NO");
currentX = touchPoint.x;
currentY = touchPoint.y;
self.position = touchPoint;
return YES;
}
// NSLog(#"isTouched = %#", self.isTouched ? #"YES" : #"NO");
return NO;
}
- (void)ccTouchMoved:(UITouch *)touch withEvent:(UIEvent *)event{
CGPoint touchPoint = [touch locationInView:[touch view]];
touchPoint = [[CCDirector sharedDirector] convertToGL:touchPoint];
if (isNotTouchActivated) {
currentX = touchPoint.x;
currentY = touchPoint.y;
self.position = touchPoint;
}
}
- (void)ccTouchEnded:(UITouch *)touch withEvent:(UIEvent *)event{
isNotTouchActivated = FALSE;
//isTouched = NO;
}
-(void)MoveWithoutProblem{
CGSize size = [[CCDirector sharedDirector] winSize];
int MaxHeightofBubbles = 350;
int minHeightofBubbles = 150;
int RandomNumber = [self generateRandomNumberBetweenMin:minHeightofBubbles Max:MaxHeightofBubbles];
float ConvertedRandom = [[NSNumber numberWithInt: RandomNumber] floatValue];
int MaxWidthofBubbles = 0;
int minWidthofBubbles = 900;
int RandomNumber02 = [self generateRandomNumberBetweenMin:MaxWidthofBubbles Max:minWidthofBubbles];
float ConvertedRandom02 = [[NSNumber numberWithInt: RandomNumber02] floatValue];
startX = ConvertedRandom02;
startY = ConvertedRandom;
currentX = startX+myInt;
currentY = startY;
self.position = ccp(startX,startY);
[self schedule:#selector(startMoving)];
}
-(void)startMoving{
if (!isNotTouchActivated) {
currentX+=bubblespeed;
[self setPosition:ccp(currentX,currentY)];
}
if (self.position.x >= 1024+50) {
//NSLog(#"off screen");
isrestartscrolling = YES;
}
if (isrestartscrolling == YES) {
//[self RandomYPOs];
[self scheduleOnce:#selector(newRandomX) delay:0.2];
isrestartscrolling = NO;
}
}
#end
Your code is a little hard to read but your immediate problem to why the touch doesn't work is because you are assuming your layer (Bubble) has a content width and height. If you did not set this, it wouldn't have it which is why your commented out line for [sprite boundingBox] does not work. Try [sprite.BackBubble boundingBox]. Adding items to a layer does not adjust that layer's content size automatically.
Another thing you can try is to add:
location = [sprite convertToNodeSpace:location];
If your bubble layer or that back bubble is moved at any point then simply adding the back bubble's position to a CGRect is not likely to work. Try the first idea first then try this if it doesn't work.
Hope this helped you Natalie.

Having trouble deselecting my CCSprite on drag event, selectedSprite = nil not working

I'm using code that has previously worked in other project the only difference is that this time I'm using a custom sprite class which seems to be not deselecting itself
Ive made a video here of the problem
https://www.youtube.com/watch?v=VHaTpiVPP_w&feature=youtu.be
-(void) ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
NSSet *allTouch = [event allTouches];
UITouch *touch = [[allTouch allObjects]objectAtIndex:0];
CGPoint location = [touch locationInView:[touch view]];
location = [[CCDirector sharedDirector]convertToGL:location];
DragItems = [[NSMutableArray alloc]initWithObjects:
Bubble01,
Bubble02,
Bubble03,
Bubble04,
Bubble05,
Bubble06,
nil];
for(int i = 0; i < [DragItems count]; i++)
{
sprite = (Bubble *)[DragItems objectAtIndex:i];
//if(sprite.tag ==12 && CGRectContainsPoint([sprite boundingBox],location))
if(CGRectContainsPoint([sprite boundingBox], location))
{
selectedSprite = sprite;
}
}
}
-(void)ccTouchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
//Move touched sprite
NSSet *allTouch = [event allTouches];
UITouch *touch = [[allTouch allObjects]objectAtIndex:0];
CGPoint location = [touch locationInView:[touch view]];
location = [[CCDirector sharedDirector]convertToGL:location];
selectedSprite.position = ccp(location.x, location.y);
NSLog(#"Position: %f %f",location.x, location.y);
}
-(void) ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
NSSet *allTouch = [event allTouches];
UITouch *touch = [[allTouch allObjects]objectAtIndex:0];
CGPoint location = [touch locationInView:[touch view]];
location = [[CCDirector sharedDirector]convertToGL:location];
selectedSprite = nil;
}
drag on CCLayer sometimes working
With the very kind help of rahul_send89 we solved the problem,
firstly the custom class a cclayer was changed to accept its own touches, then in the init
[self setContentSize:[BackBubble boundingBox].size]; was used to size the layer
(so other touches fire, this is what was probably messing up the touches for me)
the link above contains all the code. thanks again for the help!

Cocos2d CCTouchBegan

I'm trying to create a program where when the user touches the screen, a sprite will appear. However, if the user keeps their finger on that Sprite, the sprite will grow bigger until the user lets it go.
Now, I created this program in Cocos2d 1.x and it worked fine. However, when I attempted it in 2.x, the sprite gets created but it doesn't help the Sprite Grow.
The code is the following:
-(BOOL) ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event{
CGPoint touchLocation = [self convertTouchToNodeSpace:touch];
redBall = [CCSprite spriteWithFile:#"Circle.png"];
redBall.position = ccp(touchLocation.x, touchLocation.y);
redBallRect = CGRectMake(redBall.anchorPoint.x, redBall.anchorPoint.y, redBall.contentSize.width, redBall.contentSize.height);
[self addChild:redBall];
if (CGRectContainsPoint(redBallRect, touchLocation )) {
NSLog(#"Hello");
growForever = [CCRepeatForever actionWithAction: [CCScaleBy actionWithDuration: .5 scale: 1.2]];
[growForever setTag:1];
[redBall runAction:growForever];
}
return YES;
}
What might be the problem and how do I solve it?
Make sure you enabled touch:
-(void)onEnter
{
[super onEnter];
self.touchEnabled = YES;
}
Use boundingBox to get rect.
- (void)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *myTouch = [touches anyObject];
CGPoint touchLocation = [myTouch locationInView:[myTouch view]];
touchLocation = [[CCDirector sharedDirector] convertToGL:touchLocation];
if(CGRectContainsPoint([redBall boundingBox], touchLocation))
{
NSLog(#"Hello");
growForever = [CCRepeatForever actionWithAction: [CCScaleBy actionWithDuration: .5 scale: 1.2]];
[growForever setTag:1];
[redBall runAction:growForever];
}
}

Rotating sprite with finger in Cocos2d

I need help figuring out the rotation of a sprite with my finger. The sprite is rotating fine but on the initial touch of my finger it somehow rotates by a few degrees by itself.
Also the rotations only work when the finger is rotated around the center of the sprite.
I am trying to simulate the bicycle wheel and have a gear sprite and a pedal sprite as a child of the gear sprite. I want the bicycle wheel to rotate as I touch the pedal and rotate it. I haven't got that far yet. Right now I am trying to figure out how to get rid of the initial shift the gear makes.
Here is the complete code
#import "BicycleScene.h"
#implementation BicycleScene
+(id) scene
{
// 'scene' is an autorelease object.
CCScene *scene = [CCScene node];
// 'layer' is an autorelease object.
BicycleScene *layer = [BicycleScene node];
// add layer as a child to scene
[scene addChild: layer];
// return the scene
return scene;
}
-(id) init
{
if ((self=[super init])) {
CGSize winSize = [[CCDirector sharedDirector] winSize];
//place the bicycle sprite
bicycleSprite = [CCSprite spriteWithFile:#"bike_gear.png"];
bicycleSprite.position = ccp(bicycleSprite.contentSize.width/2 + 100, winSize.height/2);
[self addChild:bicycleSprite z:1];
//place the pedal sprite
pedalSprite = [CCSprite spriteWithFile:#"bike_pedal.png"];
[bicycleSprite addChild:pedalSprite z:1];
pedalSprite.position = ccp(150, 15);
//enable touch
self.isTouchEnabled = YES;
[self schedule:#selector(gameLoop:) interval:.1/100];
}
return self;
}
-(void) ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
NSLog(#"Touch begun");
}
-(void)gameLoop:(ccTime) dt{
bicycleSprite.rotation = cocosAngle;
}
-(void) ccTouchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
NSLog(#"Touch moved");
UITouch *touch = [touches anyObject];
CGPoint location = [touch locationInView:[touch view]];
CGPoint previousLocation = [touch previousLocationInView:[touch view]];
CGPoint touchingPoint = [[CCDirector sharedDirector] convertToGL:location];
CGPoint previousTouchingPoint = [[CCDirector sharedDirector] convertToGL:previousLocation];
CGPoint vector = ccpSub(touchingPoint, bicycleSprite.position);
CGFloat rotateAngle = -ccpToAngle(vector);
previousAngle = cocosAngle;
cocosAngle = CC_RADIANS_TO_DEGREES( rotateAngle);
//bicycleSprite.rotation = cocosAngle;
}
#end
I am slightly confused if the line:
CGPoint vector = ccpSub(touchingPoint, bicycleSprite.position);
should actually be:
CGPoint vector = ccpSub(touchingPoint, previousTouchingPoint );
I tried that as well but it didn't work.
I have also uploaded my complete xcodeproj to 4shared for anyone who wants to take a look here: http://www.4shared.com/file/5BaeW4oe/Healthy.html
#interface MainScene : CCLayer {
CCSprite *dial;
CGFloat dialRotation;
}
+ (id)scene;
#end
---------------------------------
#implementation MainScene
+ (id)scene
{
CCScene *scene = [CCScene node];
CCLayer *layer = [MainScene node];
[scene addChild:layer];
return scene;
}
- (id)init
{
if((self = [super init])) {
CCLOG(#"MainScene init");
CGSize size = [[CCDirector sharedDirector]winSize];
dial = [CCSprite spriteWithFile:#"dial.png"];
dial.position = ccp(size.width/2,dial.contentSize.height/2);
[self addChild:dial];
self.isTouchEnabled = YES;
[self scheduleUpdate];
}
return self;
}
- (void)dealloc
{
[super dealloc];
}
- (void)update:(ccTime)delta
{
dial.rotation = dialRotation;
}
- (void)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
}
- (void)ccTouchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
//acquire the previous touch location
CGPoint firstLocation = [touch previousLocationInView:[touch view]];
CGPoint location = [touch locationInView:[touch view]];
//preform all the same basic rig on both the current touch and previous touch
CGPoint touchingPoint = [[CCDirector sharedDirector] convertToGL:location];
CGPoint firstTouchingPoint = [[CCDirector sharedDirector] convertToGL:firstLocation];
CGPoint firstVector = ccpSub(firstTouchingPoint, dial.position);
CGFloat firstRotateAngle = -ccpToAngle(firstVector);
CGFloat previousTouch = CC_RADIANS_TO_DEGREES(firstRotateAngle);
CGPoint vector = ccpSub(touchingPoint, dial.position);
CGFloat rotateAngle = -ccpToAngle(vector);
CGFloat currentTouch = CC_RADIANS_TO_DEGREES(rotateAngle);
//keep adding the difference of the two angles to the dial rotation
dialRotation += currentTouch - previousTouch;
}
- (void)ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
}
EDIT: I am sorry I can't get this to stay in code mode. But this is the solution and it should be easy to implement in your code. cheers!
In ccTouchesBegan, use the same code as what you've got in ccTouchesMoved to determine the angle, then move to that angle using CCRotateTo. You will need some handling of the user moving his finger while CCRotateTo is active, perhaps stopping the current action and kicking off another one to move to the new angle.

Change color of a line on a button click event in cocos2d

I am a newbie at Cocos2D and i'm just getting started. I have set up a scene, and I have to change the color of a line in Cocos2D. Please can anyone help me out with this? Any help will be appreciated.
This should work:
-(id) init{
if((self = [super init])){
//CGSize winSize = [[CCDirector sharedDirector] winSize];
naughtytoucharray = [[NSMutableArray alloc] init];
self.isTouchEnabled = YES;
CCMenuItem *starMenuItem = [CCMenuItemImage itemFromNormalImage:#"ButtonStar.png" selectedImage:#"ButtonStarSel.png"
target:self selector:#selector(starButtonTapped:)];
CCMenuItem *starMenuItem1 = [CCMenuItemImage itemFromNormalImage:#"ButtonPlus.png" selectedImage:#"ButtonPlusSel.png"
target:self selector:#selector(starButtonTapped1:)];
CCMenuItem *menuItem1 = [CCMenuItemImage itemFromNormalImage:#"Button1.png" selectedImage:#"Button1Sel.png" target:self selector:#selector(button1Tapped:)];
CCMenuItem *menuItem2 = [CCMenuItemImage itemFromNormalImage:#"Button2.png" selectedImage:#"Button2Sel.png" target:self selector:#selector(button2Tapped:)];
CCMenuItem *menuItem3 = [CCMenuItemImage itemFromNormalImage:#"Button3.png" selectedImage:#"Button3Sel.png" target:self selector:#selector(button3Tapped:)];
_scoreLabel = [CCLabelTTF labelWithString:#" MyScore" dimensions:CGSizeMake(150, 30) alignment:UITextAlignmentLeft fontName:#"Arial" fontSize:15];
_scoreLabel.color = ccc3(255, 0, 0);
[_scoreLabel setPosition:ccp(80, 300)];
CCMenu *starMenu = [CCMenu menuWithItems:starMenuItem, nil];
CCMenu *starMenu1 = [CCMenu menuWithItems:starMenuItem1, nil];
CCRadioMenu *radioMenu = [CCRadioMenu menuWithItems:menuItem1, menuItem2, menuItem3, nil];
starMenuItem.position = ccp(60, 60);
starMenuItem1.position = ccp(60, 120);
radioMenu.position = ccp(120, 120);
[radioMenu alignItemsVertically];
radioMenu.selectedItem_ = menuItem1;
[menuItem1 selected];
starMenu.position = CGPointZero;
starMenu1.position = CGPointZero;
[self addChild:starMenu];
[self addChild:starMenu1];
[self addChild:radioMenu];
[self addChild:_scoreLabel];
}
[_scoreLabel setString:[NSString stringWithFormat:#"MyScore: %d", score]];
return self;
}
-(void)ccTouchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
CGPoint new_location = [touch locationInView:[touch view]];
new_location = [[CCDirector sharedDirector] convertToGL:new_location];
CGPoint oldTouchLocation = [touch previousLocationInView:touch.view];
oldTouchLocation = [[CCDirector sharedDirector] convertToGL:oldTouchLocation];
oldTouchLocation = [self convertToNodeSpace:oldTouchLocation];
[naughtytoucharray addObject:NSStringFromCGPoint(new_location)];
[naughtytoucharray addObject:NSStringFromCGPoint(oldTouchLocation)];
}
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex == 0)
{
exit(0);
NSLog(#"exit");
}
else if(buttonIndex == 1)
{
//CCScene *scene = [CCScene node];
[[CCDirector sharedDirector] replaceScene:[GameScene scene1]];
NSLog(#"Play again");
}
}
-(void)draw
{
glEnable(GL_LINE_SMOOTH);
for (int i = 0; i < [naughtytoucharray count]; i+=2)
{
CGPoint start = CGPointFromString([naughtytoucharray objectAtIndex:i]);
CGPoint end = CGPointFromString([naughtytoucharray objectAtIndex:i+1]);
ccDrawLine(start, end);
glColor4ub(200, 120, 120, 255);