Difference between using event.type and event->type |
M-374 LX
|
By using event.type, you refer to an event object directly. On the other hand, by using event->type, you have a pointer, which points to the location of an event object, which is not the same as the location of the pointer itself.
What is the scope of your event object? Can you show some code examples? |
|||||||||||
|
blazed
|
Thanks for the reply, but which one should I be using and which one is more efficient? And I just started the tutorials so I'm afraid there is not much code to show. Although this is my header file and onEvent function which simply creates a window and draws an image to it.
class game { private: bool running; SDL_Window *window; SDL_Renderer *renderer; SDL_Event event; SDL_Texture *Track,*Car; SDL_Rect rectTrack,rectCar; public: game(); int OnExecute(); bool OnInit(); bool LoadContent(); void OnEvent(); void OnLoop(); void OnRender(); void OnCleanup(); }; void game::OnEvent() { if (event.type == SDL_QUIT) running = false; if (event.type == SDL_KEYDOWN) { if (event.key.keysym.sym == SDLK_ESCAPE) running = false; } } |
|||||||||||
|
M-374 LX
|
In your case, the best idea is the OnEvent() method without the event as an argument. As the method has access to the event object, which is in the class scope, an argument is unnecessary.
|
|||||||||||
|
blazed
|
Thanks a lot again.
|
|||||||||||
|