I've been stuck on this for ages, so I'd really appreciate any insight into the problem.
I tried to add a camera class to the game I'm currently working on, but when I try to compile I juts get this error messages:
In function `ZN6Sprite4blitEP11SDL_Surface':
[Linker error] undefined reference to `camera'
[Linker error] undefined reference to `camera'
Here is the sprite class
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
//sprite.cpp
#include "SDL/SDL.h"
#include "sprite.h"
#include "image.h"
#include "camera.h"
#include "globals.h"
#include <string>
usingnamespace std;
void Sprite::blit (SDL_Surface* setDest) {
blit_image(camera.getXOffset(x), camera.getYOffset(y), image, setDest);
}
/*Some other sprite functions as well, but none of them reference "camera" */
Here is the globals file, where camera is declared:
#ifndef CAMERA_H
#define CAMERA_H
class Camera {
private:
int worldW;
int worldH;
int posX;
int posY;
public:
int getXOffset (int);
int getYOffset (int);
Camera (int, int);
};
#endif
And here is camera.cpp:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
#include "camera.h"
Camera::Camera (int getWorldW, int getWorldH) {
worldW = getWorldW;
worldH = getWorldH;
posX = 0;
posY = 0;
}
int Camera::getXOffset (int oldX) {
int newX = oldX-posX;
return newX;
}
int Camera::getYOffset (int oldY) {
int newY = oldY-posY;
return newY;
}
Sorry is that's a lot of code to sift through.
Any ideas, anybody?