Have you added the SDL.lib and SDLmain.lib to linked libraries? Do you have the SDL.dll in the same folder as the executable?
Beginning SDL Part 4 - State Manager
#47
Posted 06 December 2012 - 04:40 AM
Yea, got all of them lionked, and the files in the folder where i run the program.
It worked before in the last tutorials to run, i really hate when it happens for no specific reason
It worked before in the last tutorials to run, i really hate when it happens for no specific reason

#49
Posted 06 December 2012 - 06:16 AM
DoNotWant, on 06 December 2012 - 05:22 AM, said:
Could you post your sprite class?
Sprite.h
#ifndef SPRITE_H #define SPRITE_H #include <SDL.h> class Sprite { public: Sprite(); static SDL_Surface* Load (char* pFile); static bool Draw(SDL_Surface* dest, SDL_Surface* src, int x, int y); static bool Draw(SDL_Surface* dest, SDL_Surface* src, int x, int y, int x2, int y2, int width, int height); }; #endif
Sprite.cpp
#include "Sprite.h" Sprite::Sprite() { } bool Sprite::Draw(SDL_Surface* dest, SDL_Surface* src, int x, int y) { if(dest == NULL || src == NULL) return false; SDL_Rect offset; offset.x = x; offset.y = y; SDL_BlitSurface( src, NULL, dest, &offset ); return true; } bool Sprite::Draw(SDL_Surface* dest, SDL_Surface* src, int x, int y, int x2, int y2, int width, int height) { if(dest == NULL || src == NULL) return false; SDL_Rect offset; offset.x = x; offset.y = y; SDL_Rect sourceRect; sourceRect.x = x2; sourceRect.y = y2; sourceRect.w = width; sourceRect.h = height; SDL_BlitSurface(src, &sourceRect, dest, &offset); return true; }
#52
Posted 06 December 2012 - 06:38 AM
DoNotWant is right, you've missed a function out. it's declared but never defined.
#53
Posted 06 December 2012 - 06:43 AM
BUT i do call load from gamestate... Ah! there we go, thanks, I checked it up and i use it in gamestate, but i got my own method to load images, and when i replaced load with that method, it worked
thats what i get when i follow tutorials and use diffent names 
Thanks!


Thanks!
#54
Posted 06 December 2012 - 06:52 AM
I do those kind of renaming mistakes all the time too. Probably should start following tutorials verbatim.

#55
Posted 27 June 2013 - 04:18 AM
heya i got a small error that i probably have created myself because im an idiot but im getting this error when i run my code
C:\game\MenuState.cpp|13|undefined reference to `Sprite::Load(char*)'|
in this file
menustate.cpp
iv been through all of your tutorial many times and tried to fix it a hundred times but im new to C / C++ iv only been using it just over a week so sorry if im being a noob
C:\game\MenuState.cpp|13|undefined reference to `Sprite::Load(char*)'|
in this file
menustate.cpp
#include <stdio.h> #include "SDL\SDL.h" #include "Game.h" #include "MenuState.h" #include "sprite.h" MenuState MenuState::m_MenuState; void MenuState::Init() { menuSprite = NULL; // set pointer to NULL; menuSprite = Sprite::Load("menustate.bmp"); // load menu state bitmap printf("MenuState Init Successful\n"); } void MenuState::Clean() { printf("MenuState Clean Successful\n"); } void MenuState::Pause() { printf("MenuState Paused\n"); } void MenuState::Resume() { printf("MenuState Resumed\n"); } #include "PlayState.h" // include PlayState.h // now we will go into the MenuState::HandleEvents(Game* game) void MenuState::HandleEvents(Game* game) { SDL_Event event; if (SDL_PollEvent(&event)) { switch (event.type) { case SDL_QUIT: game->Quit(); break; case SDL_KEYDOWN: switch(event.key.keysym.sym){ case SDLK_SPACE: game->ChangeState(PlayState::Instance()); break; } } } } void MenuState::Update(Game* game) { } void MenuState::Draw(Game* game) { Sprite::Draw(game->GetScreen(), menuSprite, 0, 0); // we will write // GetScreen() in a second SDL_Flip(game->GetScreen()); }
iv been through all of your tutorial many times and tried to fix it a hundred times but im new to C / C++ iv only been using it just over a week so sorry if im being a noob

#56
Posted 02 July 2013 - 01:19 AM
Can you post more of your project please, looks like you have not defined your sprite load function.
#57
Posted 20 July 2013 - 08:31 PM
Hi I am using CodeBlocks to follow these tutorials. not really having any problems with the code but I would like to be able to see the printf text.. where does it output to? It doesn't show up in the build log... and when I put the build target as Release instead of Debug, a black consol type window shows up but nothing outputs there either.
Would appreciate if someone can point out where to see it! thank you
Would appreciate if someone can point out where to see it! thank you
#58
Posted 23 July 2013 - 04:17 AM
Code blocks prints to the files stdout.txt/stderr.txt but you can redirect them using these lines:
freopen("CON", "w", stdout); // redirects stdout freopen("CON", "w", stderr); // redirects stderr