Whats wrong with this sdl code???

Started by
15 comments, last by MPG 20 years ago
From the SDL Docs SDL_MouseButtonEvent is a structure - not a function, if you want to respond to mouse button clicks try this:

SDL_PollEvent(&Event);if(Event.type == SDL_MOUSEBUTTONDOWN){   //check to see which button was pressed   if(Event.button.button == SDL_BUTTON_LEFT)   {      //do whatever you want to do here   }} 


Check out this page on the SDL docs site which lists the SDL_MouseButtonEvent structure.
Advertisement
#ifdef WIN32#pragma comment(lib, "SDL.lib")#pragma comment(lib, "SDLmain.lib")#endif#include "SDL.h"int main( int argc, char* argv[] ){  SDL_Init( SDL_INIT_VIDEO );    atexit( SDL_Quit );    SDL_Surface * screen = SDL_SetVideoMode( 640, 480, 24, SDL_ANYFORMAT|SDL_DOUBLEBUF );    SDL_Surface * img = SDL_LoadBMP( "filename.bmp" );     SDL_Rect dest;    dest.x = 200;    dest.y = 300;    SDL_Event event;  SDL_Event a;  SDL_Event b;  SDL_Event Event              	 ;SDL_Rect coord;			 coord.x = 100;			 coord.y = 100;  while(true);  {SDL_BlitSurface(img,NULL,screen, &dest);    SDL_Flip( screen );   // wait for user exit    while( !( SDL_PollEvent(&event) && event.type == SDL_QUIT ) )  {}   SDL_PollEvent(&Event);if(Event.type == SDL_MOUSEBUTTONDOWN){      	if(Event.button.button == SDL_BUTTON_LEFT)            {			 SDL_Surface *imi =SDL_LoadBMP("ad.bmp")                       ;while(true);			 {				 SDL_BlitSurface(imi,NULL,screen,&coord)				;SDL_Flip(screen);			 }		 }         }        return 0;}

c:\Documents and Settings\Randle\Desktop\randyx''s stuff\PROJECTS\SDL\opp2604957sdl.cpp(44): fatal error C1075: end of file found before the left brace ''{'' at ''c:\Documents and Settings\Randle\Desktop\randyx''s stuff\PROJECTS\SDL\opp2604957sdl.cpp(8)'' was matched
quote:Original post by MPG
c:\Documents and Settings\Randle\Desktop\randyx''s stuff\PROJECTS\SDL\opp2604957sdl.cpp(44): fatal error C1075: end of file found before the left brace ''{'' at ''c:\Documents and Settings\Randle\Desktop\randyx''s stuff\PROJECTS\SDL\opp2604957sdl.cpp(8)'' was matched



I highly suggest you start reading, and learning how to understand, the error messages your compiler outputs.

Seriously. If you really cannot figure out what the problem is simply from the information given by the error message, then I sure hope you''re good looking.
I keep trying and it still dosnrt work.I need to knnow how many semicolons i need at the end.
I don''t intend to be rude to you at all, but what you really need is to buy a book and learn the fundamentals of C++ programming. It''s clear from your posts and your sample code that you don''t have a good handle on what you''re trying to do, and to be honest, I don''t get the impression that you''re really reading and trying to understand the posts from people who are trying to help you.

With that said, here''s some constructive advice: forget about semicolons and braces for a minute, and try to put into plain english what it is that you''re trying to DO. I think you''ll get a lot more help that way.
I''m trying to check if the left button is clicked then load an image.I''ve fixed eveything else except the last error
Ok, good. So, you''ll want to lay your code out something like this meta code:

InitDisplay();while(true) {    if (PollEvent) {        if (TypeOfEvent == QUIT) { Exit Program; }        if (TypeOfEvent == LEFTMOUSEBUTTONCLICKED) {            BlitImage();            UpdateDisplay();        }    }} 


I''ll leave it up to you to translate this into actual C++ code using SDL. At the very least, you should see the differences between the strucutre of my sample and what you posted.

This topic is closed to new replies.

Advertisement