2014-11-18 9 views
1

스크롤하는 배경을 만드는 데 문제가 있습니다. 저는 2 년 전 C++을 C++로 번역하려고 시도하고 있습니다. 'newb'(그대로)로 문제가 있습니다.스크롤 배경 만들기 (위에서 아래로 스크롤)

다음은 현재 사용하고있는 변수 및 개체입니다.

//ScrollingBackground Inits from the Contructor/Main Method 
_screenHeight = Graphics::GetViewportHeight(); 
_screenWidth = Graphics::GetViewportWidth(); 

//ScrollingBackground Content from the Load Content Method 
_backgroundPosition = new Vector2(_screenWidth/2, _screenHeight/2); 
_origin = new Vector2(_backgroundTexture->GetHeight()/2, 0); 
_textureSize = new Vector2(0, _backgroundTexture->GetHeight()); 
_backgroundTexture->Load("background.dds", false); 

이것은 스크롤이 발생하는 곳을 만드는 방법입니다. 이것에

여전히
void Player::Scrolling(float deltaX) 
{ 
    //This is where the scrolling happens 
    _backgroundPosition->X += deltaX; 
    _backgroundPosition->X = _backgroundPosition->X % _textureSize->Y; 
} 

비교적 새로운 그래서 나는 막연 해요 경우에 저를 용서 나 나는 내가 무슨 말 단서가없는 같은 소리하시기 바랍니다.

많은 감사,

Ryan.

+0

내가, LOL 잘못되어 가고 내 사과 ... 무슨 설명하지 않는 습관을 유지 _backgroundPosition-> X = _backgroundPosition-> X % _textureSize-> Y; '% : 불법, 왼쪽 피연산자 유형이'float '이고 오른쪽 피연산자와 동일합니다. –

답변

0

% 연산자는 float에 사용할 수 없습니다. 다음은 문제를 해결하지만 실제로 남은 것은 아닙니다. 정밀도가 문제가되지 않는다면 다음 코드를 사용하여 스크롤하는 배경에 큰 문제는 볼 수 없습니다.

void Player::Scrolling(float deltaX) 
{ 
    //This is where the scrolling happens 
    _backgroundPosition->X += deltaX; 
    _backgroundPosition->X = static_cast<int>(_backgroundPosition->X) % static_cast<int>(_textureSize->Y); 
} 
+0

실은 ... 그냥 테스트했습니다. %는 부동 소수점 유형에서는 작동하지 않습니다. – user2970916

+0

입력 해 주셔서 감사합니다. 이것은 'syntax error : identifier _backgroundPosition' 'Syntax Error :;', intellisense는 각각 1, 1, 45 및 86 열에 ')'및 '>'오류가 반환되었습니다. –

+0

테스트 후 코드가 업데이트되었습니다. – user2970916