Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Cocos2d iphone 严重的多点触控问题_Cocos2d Iphone_Multi Touch - Fatal编程技术网

Cocos2d iphone 严重的多点触控问题

Cocos2d iphone 严重的多点触控问题,cocos2d-iphone,multi-touch,Cocos2d Iphone,Multi Touch,我的游戏快玩完了,但我的多点触控功能无法正常工作: 我进了我的办公室 [glView setMultipleTouchEnabled:YES]; (also tried [window setMultiTouchEnabled:YES];) 在我的炸弹里 @interface Bomb : CCLayer (I also tried CCNode with <ccTargetTouchDelegate>) Bomb.m -(void)onEnter { [[CCTouchDis

我的游戏快玩完了,但我的多点触控功能无法正常工作:

我进了我的办公室

[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
{

}
@interface Bomb:CCLayer(我也试过使用CCNode)
炸弹
-(void)onEnter
{
[[CCTouchDispatcher sharedDispatcher]addTargetedElegate:自优先级:kCCMenuTouchPriority吞咽接触:是];
[超级合一];
}
-(无效)onExit
{
[[CCTouchDispatcher sharedDispatcher]removeDelegate:self];
[超级脱欧];
}
(还尝试了registerWithTouchDispatcher withouth OnNet和onExit,还尝试了[super registerWithTouchDispatcher])
-(BOOL)cctouch开始:(UITouch*)触摸事件:(UIEvent*)事件
{
如果(有理由| | | | | | | | |丢失)
返回否;
//获取触摸屏的坐标并将其转换为OpenGL系统。
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);
如果(!CGRectContainsPoint(帧,位置))
返回否;
位置x*=系数;
位置y*=系数;
if(BombShape)
{
offsetX=BombShape->body->p.x–location.x;
offsetY=BombShape->body->p.y–location.y;
BombShape->body->v=cpvzero;
BombShape->collision_type++;//使其“被拖动”。例如,RedNinja++是Dragedrednija
}
返回YES;
}
//****************************************************************************************
-(无效)ccTouchMoved:(UITouch*)触摸事件:(UIEvent*)事件
{
如果(是由| | | | | |引起的!可以破烂的)
返回;
CGPoint location=[touch locationInView:[touch view]];
location=[[CCDirector sharedDirector]convertToGL:location];
CGPoint prevLocation=[touch previousLocationInView:[touch view]];
prevLocation=[[CCDirector sharedDirector]convertToGL:prevLocation];
位置x*=系数;
位置y*=系数;
prevLocation.x*=系数;
prevLocation.y*=系数;
如果(炸弹体)
{
//在拖动过程中,炸弹不能有速度。否则,它会在你的手指下“跑”。
//所以我们一直在计算速度,当你结束拖拽时,把这个值赋给炸弹的速度。
速度=cpv((位置.x–prevLocation.x)*30,(位置.y–prevLocation.y)*30);
CGPoint newPosition=cpv(location.x+offsetX,location.y+offsetY);
//每X测试
canMoveOnX=CheckOnX(炸弹体->p,新位置,半径);
canMoveOnY=CheckOnY(BombBody->p,newPosition,radius);
if(canMoveOnX)
BombBody->p.x=newPosition.x;
if(canMoveOnY)
BombBody->p.y=newPosition.y;
}
}
//****************************************************************************************
-(无效)ccTouchEnded:(UITouch*)触摸事件:(UIEvent*)事件
{
如果(!canbedraged | | isPaused)
返回;
//放慢速度
BombShape->body->v=速度;
BombShape->collision_type–;
offsetX=0;
offsetY=0;
}
//****************************************************************************************
-(无效)ccTouchCancelled:(UITouch*)触摸事件:(UIEvent*)事件
{
}
不知何故,我似乎无法察觉我的第二次触摸:S

我正在一个游戏场景中加载我的Bomb.h,这是一个没有接触的游戏场景


请帮忙。谢谢。

我也有同样的问题

如果你有另一个视图,比如广告视图,你应该对它做同样的事情

[您的另一个视图集MultipleTouched:是]

如果你不知道,对不起,我不能再回答了