2017-09-11 18 views
1

안녕하세요 저는 XCode 및 iPhone 5c로 Cocos2dx 응용 프로그램을 개발 중이며 좌표계를 세로로 변경하려고합니다. 나는이 방향을 보았다 http://www.cocos2d-x.org/wiki/Device_Orientation. 방향에 따르면 RootViewController에서 두 가지 메소드를 변경해야 코코스가 마술을하기 전에 iOS가 이미 컨테이너 회전을 처리하도록해야한다.Cocos2dx v.3.0 인물 모드

이제 내 RootViewController.mm의 적용 가능한 방법은 다음과 같습니다. 그것은 건설하고 달린다. 내가 아이폰의 가장 왼쪽에있는 점을 터치하면

#ifdef __IPHONE_6_0 
- (NSUInteger) supportedInterfaceOrientations{ 
    return UIInterfaceOrientationMaskPortrait; 
} 
#endif 

- (BOOL) shouldAutorotate { 
    return YES; 
} 

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
    return UIInterfaceOrientationIsPortrait (interfaceOrientation); 
} 

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation { 
    [super didRotateFromInterfaceOrientation:fromInterfaceOrientation]; 

    auto glview = cocos2d::Director::getInstance()->getOpenGLView(); 

    if (glview) 
    { 
     CCEAGLView *eaglview = (__bridge CCEAGLView *)glview->getEAGLView(); 

     if (eaglview) 
     { 
      CGSize s = CGSizeMake([eaglview getWidth], [eaglview getHeight]); 
      cocos2d::Application::getInstance()->applicationScreenSizeChanged((int) s.width, (int) s.height); 
     } 
    } 
} 
@end 

내 수준의 초기화() 메소드의 코드는이

bool Level1::init() 
{ 
    ////////////////////////////// 
    // 1. super init first 
    if (!Scene::init()) 
    { 
     return false; 
    } 

    auto visibleSize = Director::getInstance()->getVisibleSize(); 
    Vec2 origin = Director::getInstance()->getVisibleOrigin(); 

    for(int i= 0; i < MAX_TOUCHES; ++i) { 
     labelTouchLocations[i] = Label::createWithSystemFont("", "Arial", 42); 
     labelTouchLocations[i]->setVisible(false); 
     this->addChild(labelTouchLocations[i]); 
    } 

    auto eventListener = EventListenerTouchAllAtOnce::create(); 

    // Create an eventListener to handle multiple touches, using a lambda, cause baby, it's C++11 
    eventListener->onTouchesBegan = [=](const std::vector<Touch*>&touches, Event* event){ 

     // Clear all visible touches just in case there are less fingers touching than last time 
     std::for_each(labelTouchLocations,labelTouchLocations+MAX_TOUCHES,[](Label* touchLabel){ 
      touchLabel->setVisible(false); 
     }); 

     // For each touch in the touches vector, set a Label to display at it's location and make it visible 
     for(int i = 0; i < touches.size(); ++i){ 
      labelTouchLocations[i]->setPosition(touches[i]->getLocation()); 
      labelTouchLocations[i]->setVisible(true); 
      labelTouchLocations[i]->setString("Touched"); 
      std::cout << "(" << touches[i]->getLocation().x << "," << touches[i]->getLocation().y << ")" << std::endl; 

     } 
    }; 

    _eventDispatcher->addEventListenerWithSceneGraphPriority(eventListener, this); 

    return true; 
} 

처럼 보인다,는 x 터치 포인트 I의 좌표 y 좌표는 예상대로 0입니다. 왜 x 좌표가 0이 아닌가? 현장 창작에 내가 빠진 것이 있습니까? 나는 코코스 문서가 요구하는 모든 변화를했다고 믿는다. 자신의 문서가 오래된 것입니까?

답변

1

좌표계가 설명서 왼쪽에 (0,0)부터 시작하지 않습니다. 그러나 기본 장면에 포함 된 컨테이너의 원본 및 크기를 가져 오는 데 사용할 수있는 간단한 메서드가 있습니다.

auto visibleSize = Director::getInstance()->getVisibleSize(); 
Vec2 origin = Director::getInstance()->getVisibleOrigin();