серьезная проблема мультитач - PullRequest
0 голосов
/ 27 июня 2011

Я почти закончил свою игру, но у меня не работает мультитач:

Я попал в мой appdelegate

[glView setMultipleTouchEnabled:YES];
(also tried [window setMultiTouchEnabled:YES];)

В моей бомбе.

@interface Bomb : CCLayer (I also tried CCNode with <ccTargetTouchDelegate>)

Bomb.m

-(void)onEnter
{
[[CCTouchDispatcher sharedDispatcher] addTargetedDelegate:self priority:kCCMenuTouchPriority swallowsTouches:YES];
[super onEnter];
}

-(void)onExit
{
[[CCTouchDispatcher sharedDispatcher] removeDelegate:self];
[super onExit];
}

(Also tried registerWithTouchDispatcher withouth onEnter and onExit and also tried with [super registerWithTouchDispatcher])

-(BOOL) ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event
{
if(isPaused || !canBeDragged || LOST)
return NO;

//take the coordinates of the touch and transform them into the OpenGL system.
CGPoint location = [touch locationInView: [touch view]];
location = [[CCDirector sharedDirector] convertToGL: location];

CGRect frame = CGRectMake(self.position.x, self.position.y, self.contentSize.width, self.contentSize.height);

if(!CGRectContainsPoint(frame, location))
return NO;

location.x *= factor;
location.y *= factor;

if(BombShape)
{
offsetX = BombShape->body->p.x – location.x;
offsetY = BombShape->body->p.y – location.y;

BombShape->body->v = cpvzero;
BombShape->collision_type++; //make it ‘Dragged’. For example RedNinja++ is DraggedRedNinja
}
return YES;
}
//****************************************************************************************
- (void) ccTouchMoved:(UITouch *)touch withEvent:(UIEvent *)event
{
if(isPaused || !canBeDragged)
return;

CGPoint location = [touch locationInView: [touch view]];
location = [[CCDirector sharedDirector] convertToGL: location];

CGPoint prevLocation = [touch previousLocationInView: [touch view]];
prevLocation = [[CCDirector sharedDirector] convertToGL: prevLocation];

location.x *= factor;
location.y *= factor;

prevLocation.x *= factor;
prevLocation.y *= factor;

if(BombBody)
{
//during the dragging, the bomb must not have velocity. Otherwise, it will “run” beneath your finger.
//so we are constantly calculating the velocity and ,when you end the draging, assign that value to the velocity of the bomb.
velocity = cpv((location.x – prevLocation.x) * 30 , (location.y – prevLocation.y)*30);

CGPoint newPosition = cpv(location.x + offsetX, location.y + offsetY);
//test per X

canMoveOnX = CheckOnX(BombBody->p , newPosition,radius);
canMoveOnY = CheckOnY(BombBody->p , newPosition,radius);

if(canMoveOnX)
BombBody->p.x = newPosition.x;

if(canMoveOnY)
BombBody->p.y = newPosition.y;
}
}

//****************************************************************************************
- (void) ccTouchEnded:(UITouch *)touch withEvent:(UIEvent *)event
{
if(!canBeDragged || isPaused)
return;

//set velocity back
BombShape->body->v = velocity;
BombShape->collision_type–;

offsetX = 0;
offsetY = 0;
}
//****************************************************************************************
-(void) ccTouchCancelled:(UITouch *)touch withEvent:(UIEvent *)event
{

}

Каким-то образом я не могу обнаружить свое второе прикосновение: S.

Я загружаю свой Bomb.h в GameScene, который является CCLayer без касаний.

Пожалуйста, помогите. Спасибо.

1 Ответ

1 голос
/ 29 августа 2011

У меня была такая же проблема.

Если у вас есть другой вид, например, вид для рекламы, вы должны сделать то же самое с этим.

отл.

[yourAnotherView setMultipleTouchEnabled: YES];

Если нет, извините, я не могу больше отвечать ...

...