2012-11-28 6 views
2

저는 C++과 cocos2d-x에서 초보자입니다. 그래서 왜 잘못 된 것인지 이해하지 못합니다. 코드"cocos2d :: CCPoint"를 "cocos2d :: CCPoint"로 변환 할 수 없습니다.

void 
MainLayer::ccTouchesBegan(CCSet *pTouches, CCEvent *pEvent) 
{ 
    // Get any touch and convert the touch position to in-game position. 
    CCTouch* touch = (CCTouch*)pTouches->anyObject(); 
    CCPoint position = touch->locationInView(); 
    position = CCDirector::sharedDirector()->convertToGL(position); 

    __pShip->setMove(position); 
} 

이 기능의 코드입니다.

Ship::setMove(CCPoint *newPosition) 
{ 
    __move=*newPosition; 
} 

당신이 그것을 매개 변수로 CCPoint 유형을 사용하여 볼 수 있지만이 위치 헤더와 함께 실패로 : 내가 잘못 뭐하는 거지

class Ship : public AnimatedObject 
{ 
public: 
    Ship(); 
    bool init(const char* frameName, CCSpriteBatchNode* pSpriteSheet); 
    void setMove(CCPoint* newPosition); 
    void move(); 

private: 
    /** 
    * A CCMoveTo action set in the move() method. 
    */ 
    cocos2d::CCFiniteTimeAction* __pMoveAction; 

    /** 
    * This value specifies the ship's speed. 
    */ 
    float __speed; 

    /** 
    * This value specifies position to which the ship should move. 
    * It's set in touch events callbacks in MainLayer class. 
    */ 
    CCPoint __move;  
}; 

? 왜이 코드가 CCPoint 변환에 실패합니까?

+0

정확한 오류는 어디에서 언급 할 수 있습니까? – Ajay

+0

__pShip-> setMove (position); – Sugar

+0

포인터 또는 참조에 문제가 있습니까? – Sugar

답변

1

사용 :

__pShip->setMove(&position); // Address-of 

또는 함수 자체 변경 : CCPoint은 (그림과 같이) 값을 기준으로 작은 클래스, 사용, 또는이 큰 경우 (복사 비싼 경우

Ship::setMove(CCPoint newPosition) // better: const CCPoint& newPosition 
{ 
    __move = newPosition; 
} 

을), 주석 처리 된 프로토 타입을 사용하십시오.