создание прозрачной кнопки в cocos2d iphone - PullRequest
0 голосов
/ 07 февраля 2012

Я занимаюсь разработкой игры cocos2d. В этой игре у меня есть персонаж, и в соответствии с позициями касания на персонаже должны быть запущены различные действия, как я могу реализовать это в моей игре cocos2d. Есть ли способ реализовать прозрачную кнопку в cocos2d.

Заранее спасибо

Ответы [ 2 ]

3 голосов
/ 07 февраля 2012

Когда вы создаете CCMenuItemSprite (кнопка), вы назначаете ему спрайт для использования для отображения.

Затем вы можете изменить внешний вид кнопки, изменив свойство непрозрачности спрайта или сделав его вообще невидимым.

CCSprite *buttonSpr = [CCSprite spriteWithSpriteFrameName:@"spr.png"];

CCMenuItem *button = [CCMenuItemSprite itemFromNormalSprite:buttonSpr selectedSprite:buttonSpr target:self selector:@selector(buttonTapped:)];

//opacity
buttonSpr.opacity = 50;

//invisible
buttonSpr.visible = false;
0 голосов
/ 07 февраля 2012

Я не совсем уверен, что понимаю вопрос, и будет полезна дополнительная информация, но я отвечу на него как можно лучше.

Предполагая, что у вас есть класс символов, я бы реализовал checkTouchesBegan и сделал бы что-то вроде этого:

-(BOOL) checkTouchesBegan: (CGPoint*) location
{
//conver the touch coordinates to fit your system
int converty = location->y-160;
int convertx = location->x-240;

//determine where the touch is in relation to the center of the character
float ydif = (1.0)*(converty - character_y);
float xdif = (1.0)*(convertx - character_x);

//determine the angle of the touch
float degrees = atan2f(xdif, ydif) * 57;
//determine the distance between the character and the touch
float squared = xdif*xdif + ydif*ydif;

//if the touch is above the character and within a certain distance
if(degrees >= 45 && degrees < 135 && sqrt(squared) < 100)
{
  doSomething;
  return YES;
}
//if the touch is below the character and within a certain distance
else if(degrees < -45 && degrees >= -135 && sqrt(squared) < 100)
{
 doSomething;
 return YES;
}
//if the touch is to the right of the character and within a certain distance
else if(degrees >= -45 && degrees < 45 && sqrt(squared) < 100)
{
 doSomething;
 return YES;
}
//if the touch is to the left of the character and within a certain distance
else if(sqrt(squared) < 100)
{
 doSomething;
 return YES;
}
return NO;
}

Надеюсь, это поможет некоторым!

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...