0
我的ccTouchMoved方法存在問題。我有3個ccSprites,我想用手指在屏幕上移動。事情是,運動是生澀的,有時甚至在拖動圖像時,如果我將鼠標指針移動到快速,它甚至會失去ccSprites的「抓地力」。COCOS2D。使用ccTouchMoved拖動屏幕上的CCSprite會使運動干擾
我錯過了什麼?
,我使用有以下任務三個touchmethods:
ccTouchBegan:擴大正被感動
ccTouchMoved的ccSprite:移動是在屏幕上
ccTouchEnded觸及ccSprite:按比例縮小ccSprite到原來的大小和停止運動(有縮小的ccSprite到它的原始大小的更好的辦法?)
- (BOOL)ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event{
CCLOG(@"ccTouchBeganRuby");
CGPoint location = [self convertTouchToNodeSpace: touch];
if(CGRectContainsPoint([animatingRuby1 boundingBox], location)){
CCLOG(@"ccTouchEndedRubyScaleUp1");
id ScaleAction1 = [CCScaleBy actionWithDuration:1 scale:1.2f ];
[animatingRuby1 runAction:ScaleAction1];
}
if(CGRectContainsPoint([animatingRuby2 boundingBox], location)){
CCLOG(@"ccTouchEndedRubyScaleUp2");
id ScaleAction2 = [CCScaleBy actionWithDuration:1 scale:1.2f ];
[animatingRuby2 runAction:ScaleAction2];
}
if(CGRectContainsPoint([animatingRuby3 boundingBox], location)){
CCLOG(@"ccTouchEndedRubyScaleUp3");
id ScaleAction3 = [CCScaleBy actionWithDuration:1 scale:1.2f ];
[animatingRuby3 runAction:ScaleAction3];
}
return YES;
}
- (void)ccTouchMoved:(UITouch *)touches withEvent:(UIEvent *) event{
CCLOG(@"ccTouchMovedRuby");
if (CGRectContainsPoint([animatingRuby1 boundingBox], location)) {
CCLOG (@"moveRubies1");
if((CGRectContainsPoint([animatingRuby2 boundingBox], location))|| (CGRectContainsPoint([animatingRuby1 boundingBox], location))) {
return;
}
animatingRuby1.position = location;
}
if (CGRectContainsPoint([animatingRuby2 boundingBox], location)) {
CCLOG (@"moveRubies2");
if((CGRectContainsPoint([animatingRuby1 boundingBox], location))|| (CGRectContainsPoint([animatingRuby3 boundingBox], location))) {
return;
}
animatingRuby2.position = location;
}
if (CGRectContainsPoint([animatingRuby3 boundingBox], location)) {
CCLOG (@"moveRubies3");
if((CGRectContainsPoint([animatingRuby1 boundingBox], location))|| (CGRectContainsPoint([animatingRuby2 boundingBox], location))) {
return;
}
animatingRuby3.position = location;
}
[self collidableWithEachOther:location];
}
- (void)ccTouchEnded:(UITouch *)touch withEvent:(UIEvent *) event{
CGSize screenSize = [[CCDirector sharedDirector] winSize];
CCLOG(@"ccTouchEndedRuby");
CGPoint location = [self convertTouchToNodeSpace: touch];
if(CGRectContainsPoint([animatingRuby1 boundingBox], location)){
CCLOG(@"ccTouchEndedRubyScaleDown1");
[animatingRuby1 setScaleX:screenSize.width/14850.0f];
[animatingRuby1 setScaleY:screenSize.height/9552.0f];
}
if(CGRectContainsPoint([animatingRuby2 boundingBox], location)){
CCLOG(@"ccTouchEndedRubyScaleDown2");
[animatingRuby2 setScaleX:screenSize.width/14850.0f];
[animatingRuby2 setScaleY:screenSize.height/9552.0f];
}
if(CGRectContainsPoint([animatingRuby3 boundingBox], location)){
CCLOG(@"ccTouchEndedRubyScaleDown3");
[animatingRuby3 setScaleX:screenSize.width/14850.0f];
[animatingRuby3 setScaleY:screenSize.height/9552.0f];
}
}
對不起,如果我聽起來像一個完全noob(雖然我是一個noob),但我不明白你的意思。我仍然在學習,所以你可以用一個例子來展示我...... – peteriphonenoob