• (4 Pages)
  • +
  • « First
  • 2
  • 3
  • 4

Beginning SDL Part 4 - State Manager

#46 stayscrisp  Icon User is offline

  • フカユ
  • member icon

Reputation: 998
  • View blog
  • Posts: 4,173
  • Joined: 14-February 08

Posted 06 December 2012 - 04:16 AM

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?
Was This Post Helpful? 0
  • +
  • -

#47 sandmaster  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 06-December 12

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 :/
Was This Post Helpful? 0
  • +
  • -

#48 DoNotWant  Icon User is offline

  • D.I.C Head

Reputation: 11
  • View blog
  • Posts: 59
  • Joined: 03-November 11

Posted 06 December 2012 - 05:22 AM

Could you post your sprite class?
Was This Post Helpful? 0
  • +
  • -

#49 sandmaster  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 06-December 12

Posted 06 December 2012 - 06:16 AM

View PostDoNotWant, 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;

 }

Was This Post Helpful? 0
  • +
  • -

#50 DoNotWant  Icon User is offline

  • D.I.C Head

Reputation: 11
  • View blog
  • Posts: 59
  • Joined: 03-November 11

Posted 06 December 2012 - 06:29 AM

Where is your load function in the cpp file?
Was This Post Helpful? 0
  • +
  • -

#51 sandmaster  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 06-December 12

Posted 06 December 2012 - 06:38 AM

Thats the problem, it isnt there :S
Was This Post Helpful? 0
  • +
  • -

#52 stayscrisp  Icon User is offline

  • フカユ
  • member icon

Reputation: 998
  • View blog
  • Posts: 4,173
  • Joined: 14-February 08

Posted 06 December 2012 - 06:38 AM

DoNotWant is right, you've missed a function out. it's declared but never defined.
Was This Post Helpful? 0
  • +
  • -

#53 sandmaster  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 06-December 12

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 :P

Thanks!
Was This Post Helpful? 0
  • +
  • -

#54 DoNotWant  Icon User is offline

  • D.I.C Head

Reputation: 11
  • View blog
  • Posts: 59
  • Joined: 03-November 11

Posted 06 December 2012 - 06:52 AM

I do those kind of renaming mistakes all the time too. Probably should start following tutorials verbatim. :P
Was This Post Helpful? 0
  • +
  • -

#55 dannydoomno1  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 26-June 13

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

#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 :)
Was This Post Helpful? 0
  • +
  • -

#56 stayscrisp  Icon User is offline

  • フカユ
  • member icon

Reputation: 998
  • View blog
  • Posts: 4,173
  • Joined: 14-February 08

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.
Was This Post Helpful? 0
  • +
  • -

#57 gamer27lv  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 11-May 12

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
Was This Post Helpful? 0
  • +
  • -

#58 stayscrisp  Icon User is offline

  • フカユ
  • member icon

Reputation: 998
  • View blog
  • Posts: 4,173
  • Joined: 14-February 08

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


Was This Post Helpful? 0
  • +
  • -

  • (4 Pages)
  • +
  • « First
  • 2
  • 3
  • 4