Odd, irritating problem

Started by
4 comments, last by zlatko_bre_1985 18 years, 9 months ago
Hi, I'm currently re-writing my Pong clone to make a version that's actually worth its salt. Thing is, there's a really bizarre problem I'm getting, and it's irritating too. I've got a Sprite wrapper class set up, and I just put in a function for transparency of certain colours of pixel - it's parameterised, you just use the object and pass in the RGB values to make them transparent. But, I'm getting an error saying that the class doesn't have the function as a member. pBall is an instance of the SpriteManager class, within spritewrapper.h. Here's the lines in main.cpp:
#include "spritewrapper.h"

pBall.LoadSprite("data/ball.bmp",GameWindow.MainWindow); // This works fine
pBall.SetTrans(0,0,0); // Won't compile - highlighted by IDE and says that
//the class SpriteManager (in spritewrapper.h) - doesn't have SetTrans as a member.  It does, as you can see below.




Here's the appropriate part of spritewrapper.h:
void LoadSprite(char *pFileName,SDL_Surface *surface); // No problem
void SetTrans(int r,int g,int b); // No error flagged here




And here's spritewrapper.cpp - contains the actual implementations:
void SpriteManager::LoadSprite(char *pFileName,SDL_Surface *surface)
{
//Lots of code - no problem, works fine: compiles and works fine at runtime
}

void SpriteManager::SetTrans(int r,int g,int b)
{
 
 SDL_SetColorKey(sprite,SDL_SRCCOLORKEY,SDL_MapRGB(sprite->format,r,g,b));

//No compiler errors here
 
}




What am I missing that's crashingly obvious? It all looks fine to me, everything is included where it should be, and this niggling problem in the first source box is the only one I have. Everything else compiles perfectly. Can anybody help? It's driving me nuts, there seems no reason for this error to occur. It only seems to occur in main.cpp - and if I comment it out it compiles perfectly (but no transparency when it runs - only because the code to do it won't compile!) Thanks in advance, ukdeveloper.
Advertisement
you should show your whole spritewrapper.h, are those functions maybe private or protected? how did you declare pBall?

Here's spritewrapper.h:
#include <SDL/SDL.h>class SpriteManager{            public:                          SDL_Surface *sprite; // The sprite itself                          SDL_Surface *sprite_location; // The surface onto which it will go                          void LoadSprite(char *pFileName,SDL_Surface *surface);                          void SpriteError(char *pFileName); // Calls for an error generation if the file couldn't be loaded                          void DrawSprite(int xloc, int yloc); // Draws and blits it to the specified surface                          void SetTrans(int r,int g,int b); // Sets the transparency for a given colour                          void FreeSprite(); // Frees the surface once we're done with it                         private:                            int dest_locx; // The x co-ordinate on the destination                            int dest_locy; // The y co-ordinate on the destination              };


pBall was declared in main.cpp by
SpriteManager pBall;


Hope that helps.
Try a "Rebuild All". It's possible your dependencies are out-dated.

Toolmaker

It once happend to me and I found out that I had two headers of the same class (each in a different directory) and the older version was used automatically.

So if by any chance you wrote two versions of this class, make sure which header is used.
There is nothing that can't be solved. Just people that can't solve it. :)
try this in your spritewrapper.cpp

void SpriteManager::SetTrans(int r,int g,int b)
{
//SDL_SetColorKey(sprite,SDL_SRCCOLORKEY,SDL_MapRGB(sprite->format,r,g,b));
}

and then compile.If it compiles ok there is error in sdl library you must solve.
If not look for other errors.it reports then.And watch for includes IDE gets dizzy when you forgot required include.
I dont know sdl but why you does not pass pointer to sprite used in that func?
Serbia,Zrenjanin

This topic is closed to new replies.

Advertisement