私はlazyfoo.netのチュートリアルの一部をマウスイベントで書き直そうとしています。私はこのサイトの誰かが私に提案した後に私のデザインを再考しました。私はグラフィックスクラスを追加しようと決めました。また、クラスのメンバがクラスに継承されないようにすることを決めました。これは前回質問を投稿したときの問題の1つでした。経験豊富なプログラマーではないので、私は辛抱強くお待ちください。私はSDL2.0を学ぶ途中です。正しいファイルがインクルードされていても、このスコープでは宣言されていません。
私は64ビットDellラップトップで、Code :: Blocks 16.01を使用してWindows 10を実行しています。
私はこの問題を見つけようとしましたが、特定の問題に関連する質問は一切ないと思いますので、他のエラーを修正した後、ついにエラーになりました。修正する。
次のコードをコンパイルしようとすると、「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"に含まれる2番目のファイルは表示されません。 – Shiping