연습용 마우스 이벤트에 대한 lazyfoo.net 튜토리얼의 일부를 다시 작성하려고합니다. 이 사이트의 누군가가 제안한 후에 디자인을 다시 생각했습니다. 나는 그래픽 클래스를 추가하고 클래스의 멤버가 클래스의 멤버가되지 않도록 확실히하기로 결정했다. 마지막으로 질문을 올렸을 때 문제가되었다. 경험이 많은 프로그래머가 아니기 때문에 SDL2.0을 배우는 중입니다.올바른 파일 포함 포함에도 불구하고이 범위에서 선언되지 않았습니다.
저는 64 비트 Dell 랩톱에서 Windows 10을 실행하고 Code :: Blocks 16.01을 사용하고 있습니다.
나는이 문제에 대한 인터넷 검색을 시도했는데 발견 된 질문 중 하나가 내 특정 문제와 관련이 있다고 생각하지 않으므로 여러 가지 오류를 수정 한 후에 마침내 어떻게 해야할지 모르는 오류가 발생했습니다. 고치다.
다음 코드를 컴파일하려고하면 "mSpriteClips가있는 CentralClass가 내 cpp 파일에 포함되어 있다는 사실에도 불구하고" 'mSpriteClips'가이 범위에서 선언되지 않았습니다. '라는 오류 메시지가 나타납니다.
다음은 코드입니다.
lbutton.cpp
#include "lbutton.h"
#include "lButtonSprite.h"
#include "global.h"
#include "graphics.h"
#include "ltexture.h"
#include "central_class.h"
LButton::LButton()
{
mButtonPosition.x = 0;
mButtonPosition.y = 0;
mCurrentSprite = button::MOUSE_OUT;
}
void LButton::setPosition(int x, int y)
{
mButtonPosition.x = x;
mButtonPosition.y = y;
}
void LButton::handleEvent(SDL_Event* e)
{
//If mouse event happened
if(e->type == SDL_MOUSEMOTION || e->type == SDL_MOUSEBUTTONDOWN || e->type == SDL_MOUSEBUTTONUP)
{
//Get mouse position
int x, y;
SDL_GetMouseState(&x, &y);
//Check if mouse is in button
bool inside = true;
//Mouse is left of the button
if(x < mButtonPosition.x)
inside = false;
//Mouse is right of the button
else if(x > mButtonPosition.x + global::BUTTON_WIDTH)
inside = false;
//Mouse above the button
else if(y < mButtonPosition.y)
inside = false;
//Mouse below the button
else if(y > mButtonPosition.y + global::BUTTON_HEIGHT)
inside = false;
//Mouse is outside button
if(!inside)
mCurrentSprite = button::MOUSE_OUT;
}
//Mouse is inside button
else
{
//Set mouse over sprite
switch(e->type)
{
case SDL_MOUSEMOTION:
mCurrentSprite = button::MOUSE_OVER_MOTION;
break;
case SDL_MOUSEBUTTONDOWN:
mCurrentSprite = button::MOUSE_DOWN;
break;
case SDL_MOUSEBUTTONUP:
mCurrentSprite = button::MOUSE_UP;
break;
}
}
}
void LButton::render(Graphics &graphics)
{
//Show current button sprite
mButtonSpriteSheet->render(mButtonPosition.x, mButtonPosition.y, graphics, &mSpriteClips[mCurrentSprite]);
}
와 컴파일러가 선언되지 않았습니다라는 멤버가 파일.
#ifndef CENTRAL_CLASS_H_INCLUDED
#define CENTRAL_CLASS_H_INCLUDED
#include <SDL.h>
#include "lButtonSprite.h"
#include "global.h"
#include "graphics.h"
class LButton;
class CentralClass : public Graphics
{
// Button objects
LButton *mButtons[global::TOTAL_BUTTONS];
// Mouse button sprite rectangles
SDL_Rect mSpriteClips[button::TOTAL];
public:
// Call all functions
CentralClass();
// Starts up SDL and creates window
bool init();
// Loads media
//bool loadMedia();
// Main part of the program
void mainLoop();
// Frees media and shuts down SDL
void close();
// Clean up
~CentralClass();
};
#endif // CENTRAL_CLASS_H_INCLUDED
도움을 주시면 감사하겠습니다. 이 오류 메시지가 실제로 문제가 무엇인지 알려주시기 바랍니다. 그러면 훨씬 더 즐겁게 코딩 할 수 있습니다.
"central_class.h"에 포함 된 두 번째 파일이 표시되지 않습니다. – Shiping