开发者

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

开发者 https://www.devze.com 2023-02-16 04:03 出处:网络
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 开发者_JAVA百科me out with this?Any help will

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 开发者_JAVA百科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);
0

精彩评论

暂无评论...
验证码 换一张
取 消