COCOS2D: ScrollView внутри анимации блоков CCScene - PullRequest
1 голос
/ 13 ноября 2011

У меня есть CCScene.В правой части мне нужно иметь UIScrollView с некоторыми элементами меню.Я сделал это так, как я объяснил в предыдущем вопросе Cocos2d и UIScrollView

. Вот метод создания моей сцены

  +(id) scene: (int) wld{
    CCScene *scene = [CCScene node];
    LevelsMenu *layer = [LevelsMenu node];
    layer = [layer init:wld];
    [scene addChild: layer];
    [layer setScrollView:[LevelMenuControlView alloc]];
    [[[CCDirector sharedDirector] openGLView] addSubview:layer.scrollView.view];
    return scene;
 }

. Обратите внимание, что LevelMenuControlView - это простоUIViewController реализован следующим образом:

 - (void)loadView{
 LevelMenuView *scrollView = [[LevelMenuView alloc] initWithFrame:[UIScreen 
    mainScreen].applicationFrame];

scrollView.contentSize = CGSizeMake(862, 480);

scrollView.delegate = scrollView;
[scrollView setUserInteractionEnabled:TRUE];
[scrollView setScrollEnabled:TRUE];
[scrollView setShowsVerticalScrollIndicator:FALSE];
[scrollView setShowsHorizontalScrollIndicator:FALSE];
self.view = scrollView;

[scrollView release];
 }

Хотя LevelMenuView - это UIScrollView, содержащий элементы меню

Он работает довольно хорошо.Теперь проблема в том, что в левой части сцены у меня есть спрайт-анимация, которая, если я не касаюсь экрана нормально, но как только я перетаскиваю вид прокрутки вверх или вниз, останавливается или идет с той же скоростью, что и мой прокручивающий палец.!!!

Есть идеи?

1 Ответ

1 голос
/ 15 ноября 2011

Я нашел эту ссылку, где кто-то уже сталкивался с той же проблемой и опубликовал решение, которое действительно работает

http://www.cocos2d -iphone.org / forum / topic / 11645

Это в основном состоит в добавлении этого кода в представление прокрутки:

// This should go in your interface.
 NSTimer *timer;

// Override
- (void)setContentOffset:(CGPoint)contentOffset {
// UIScrollView uses UITrackingRunLoopMode.
// NSLog([[NSRunLoop currentRunLoop] currentMode]);

// If we're dragging, mainLoop is going to freeze.
if (self.dragging && !self.decelerating) {

// Make sure we haven't already created our timer.
if (timer == nil) {

 // Schedule a new UITrackingRunLoopModes timer, to fill in for    
 CCDirector while we drag.
        timer = [NSTimer scheduledTimerWithTimeInterval:[[CCDirector sharedDirector] animationInterval] target:self selector:@selector(animateWhileDragging) userInfo:nil repeats:YES];

                    // This could also be NSRunLoopCommonModes
        [[NSRunLoop currentRunLoop] addTimer:timer forMode:UITrackingRunLoopModes];
    }
}

// If we're decelerating, mainLoop is going to stutter.
if (self.decelerating && !self.dragging) {

    // Make sure we haven't already created our timer.
    if (timer == nil) {

        // Schedule a new UITrackingRunLoopMode timer, to fill in for CCDirector while we decellerate.
        timer = [NSTimer scheduledTimerWithTimeInterval:[[CCDirector sharedDirector] animationInterval] target:self selector:@selector(animateWhileDecellerating) userInfo:nil repeats:YES];
        [[NSRunLoop currentRunLoop] addTimer:timer forMode:UITrackingRunLoopMode];
    }
}

[super setContentOffset:contentOffset];
}
- (void)animateWhileDragging {

// Draw.
[[CCDirector sharedDirector] drawScene];

if (!self.dragging) {

    // Don't need this timer anymore.
    [timer invalidate];
    timer = nil;
}
}
- (void)animateWhileDecellerating {

// Draw.
[[CCDirector sharedDirector] drawScene];

if (!self.decelerating) {

    // Don't need this timer anymore.
    [timer invalidate];
    timer = nil;
}
}

Большое спасибо этим парням

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