• Content count

  • Joined

  • Last visited

Community Reputation

122 Neutral

About charlando

  • Rank
  1. SDL_ttf RenderText Problem

    Quote: To increase your warning level to see the error this should cause, go to project->project options->parameters and add -Wall to both the C and C++ compile settings. This means "warn me about all possible errors in my code". It helps avoid mistakes like the one you made there. Thanks a lot, that's a great tip :) You fixed my error and taught me even more about pointers :) Thank you.
  2. SDL_ttf RenderText Problem

    hmmm, i don't quite understand what your saying there, are you saying to pass the Font class as a pointer? And i don't know what you mean by warning level - i'm using it in dev-cpp.
  3. I made the following two functions in a class Text. class Text { private: string text; Font *font; //this points to a class that holds the SDL_Color and TTF_Font int x, y; SDL_Surface *Texting; public: Text( string context, Font fonting, int X, int Y ); void Change_Text( string context ); void Update_Text( int render_method ); void Display_Text( int method ); }; Text::Text( string context, Font fonting, int X, int Y ) { text = context; font = &fonting; x = X; y = Y; } void Text::Change_Text( string context ) { text = context; } void Text::Update_Text( int render_method ) { SDL_FreeSurface( Texting ); switch(render_method) { case SOLID: Texting = TTF_RenderText_Solid( font->Get_Font(), text.c_str(), font->Get_Colour() ); case BLENDED: Texting = TTF_RenderText_Blended( font->Get_Font(), text.c_str(), font->Get_Colour() ); case SHADED: Texting = TTF_RenderText_Blended( font->Get_Font(), text.c_str(), font->Get_Colour() ); } } void Text::Display_Text( int method ) { Apply_Surface( x, y, Texting, screen ); }//font is a pointer to a class which holds the TTF_Font and SDL_Color. If in main.cpp i put //main.cpp //yes yes, //includes using namespace std; //adv is the font that works fine ;) Text writing( "Hello Charlie Banks!!! It works!!!", adv, 16, 16 ); writing.Update_Text( SOLID ); Text writing2( "Hello Charlie Banks!!! It works!!!", adv, 16, 16 ); writing2.Change_Text( "fgdg" ); writing2.Update_Text( SOLID ); Text writing3( "Hello Charlie Banks!!! It works!!!", adv, 16, 16 ); writing3.Update_Text( SOLID ); writing3.Change_Text( "fgdg" ); writing3.Update_Text( SOLID ); while( quit = false ) { //so and so... writing.Display_Text(); writing2.Display_Text(); writing3.Display_Text(); } that code, writing works ok (as expected). writing2 doesn't show and writing3 delivers a MAV... So i can't update the text which is what i want to do... and i don't know why though... any help apreciated :)
  4. C++ storing function for later

    Darn it, C++ has a weakness... But i'm so fond of it :/ I think i'll find a different way to do things... typdef might be a way... As for learning a new language, i don't think SDL works with those languages. I might work with them for other things though :) Thanks for all the help.
  5. C++ storing function for later

    In C++. I've been reading about function pointers. But what i want to know is if it's possible to store a function for later use. Also, how would i store a function without knowing the parameters? Any info is greatly apreciated, thanks.
  6. puzzling class error thingy C++

    GENIUS! I'm a bad fool! Thanks a lot, it's solved! You can expect a 1up rating ;)
  7. puzzling class error thingy C++

    The errors is as follows: request for member 'Start' in 'bob', which is of non-class type 'Timer()()' request for member 'Get_Ticks' in 'bob', which is of non-class type 'Timer()()' the code for main.cpp is: //yes, everything is included correctly (i think) #include <Time.h> main(int argc, char *argv[]) { Timer bob(); bob.Start(); while( bob.Get_Ticks() < 30 ); { } return 0; } the code in Time.h is: //yes everything is included class Timer { private: int startTicks; int pausedTicks; bool paused; bool started; public: Timer(); void Start(); void Stop(); void Pause(); void Unpause(); int Get_Ticks(); bool Is_Started(); bool Is_Paused(); }; Timer::Timer() { startTicks = 0; pausedTicks = 0; paused = false; started = false; } void Timer::Start() { started = true; paused = false; startTicks = SDL_GetTicks(); } int Timer::Get_Ticks() { if( started == true ) { if( paused == true ) { return pausedTicks; } else { return SDL_GetTicks() - startTicks; } } return 0; } //i cut out the bits that were'nt really important So why is it giving me that error? Everything is included and initalized as it should be... I'm using dev-cpp, any help is apreciated...
  8. C++ directory / file help plz

    I'm using Dev-cpp, and in reply to ImperfectFreak, this is the file opening function, and i'm using namespace std so i don't need to use std:: However, i changed the flag to fstream::trunc and got the desired affect, it now works. Thanks for all the help anyway.
  9. C++ directory / file help plz

    Thanks for the help, i'll give you a possitive rating seeing how you're in need :) But after changing the code to: ("bob.txt", fstream::in | fstream::out | fstream::app); and having previousley created bob.txt in the same directory, it still doesn't write to it. Any help apreciated
  10. C++ directory / file help plz

    #include <greetings & intro> How in C++ do i get the directory of the application? Is it automatic? Also, in the following code: //where char name = "bob.txt" (name, fstream::in | fstream::out | fstream::app); does this create the file if it doesn't exist? thanks.
  11. vector and pointer help C++

    aaah now i see :) thanks. and thanks for the function idea, i'll use that.
  12. vector and pointer help C++

    I have two things on my mind at the moment that i wish we be resolved. The first one is the initialization of vectors of structures and setting their variables. For instance i wanted to use the following code: vector<SDL_Rect> fred(1); fred[0] = {0, 3, 32, 45}; For those that don't know SDL_Rect is a structure of 4 variables. This code doesn't work. I was wondering if there was a way to do this as i see it is possible to do: SDL_Rect newRect = {0, 3, 32, 45}; So what is the difference? or the problem? Please help. Also i was wondering if anyone has any good links to a tutorial on pointers. I've been looking but i've not found anything 'exceptional'. Thanks...
  13. class vector pointers help!

    Well thanks a lot for your help, it nearly worked after i changed 'vector<SDL_Rect> * Colpix;' to 'vector<SDL_Rect * > Colpix;'. I've come up with a better solution of using integers to refer to vectors - it should use less memory aswell. I've learned more about pointers and although i didn't succeed i thanks you all for your help.
  14. class vector pointers help!

    Although the title is vague, have no fear, i will explain it now. I've been trying to get this class to work, i'm trying to make a vector pointer inside a class to point to a given vector outside the class. This is C++, it looks something like this. class CTile { private: vector<SDL_Rect> * Colpix; public: CTile( int x, int y, vector<SDL_Rect> BoxType ); }; CTile::CTile( int x, int y, vector<SDL_Rect> BoxType ) { for( int i = 0; i < BoxType.size(); i++ ) { *Colpix.push_back( &BoxType[i] ); } } ...yea i'm using SDL too, the error for this is: 'push_back' has not been declaired request for member of non-aggregate type before '(' token Am i allowed to resize a pointer? I don't know what the problem is atall. - i am including all the right header files and i deleted some irrelevant stuff from the class to make it easier to see. Thanks for any help :)
  15. Access violation (segment fault)

    Well i'll be daamned... I read your posts and thanks for the great response :) After a bit of fiddling i changed: if( PausedTime == AnimationSpeed ) to: if( PausedTime >= AnimationSpeed ) I'm not sure why that worked but i guess i'll look into it more. Thanks a lot.