Hi,
I am making a small game.
The requirement is that an image will be displayed for some time (say 1000
ms), and the user has to click on it.
After the click, we must check for click coordinates.
the general structure I follows goes like this:
draw();
checkForInput();
delay for 1000 ms();
The problem is that mouse clicks are not getting detected. I guess it is
because the mouse clicks happen when the game is waiting through
SDL_Delay(1000), so we miss the input.
The delay MUST be there because the image has to stay for a certain amount
of time.
Please help me out.
Delay is a bad way to do that. What you need is a timer instead. Your
game loop should look more like this:
set timer for how long to display card
while game is playing
if display time not expired
redraw screen
check for mouse clicked
if click is detected
check for click coordinates in the right place
decrement display time by amount of time passed since last loop
Hope that helps you.
-JOn Mon, Apr 7, 2008 at 12:39 PM, Ankush Thakur <ankush.gamedev at gmail.com> wrote:
Hi,
I am making a small game.
The requirement is that an image will be displayed for some time (say 1000
ms), and the user has to click on it.
After the click, we must check for click coordinates.
the general structure I follows goes like this:
draw();
checkForInput();
delay for 1000 ms();
The problem is that mouse clicks are not getting detected. I guess it is
because the mouse clicks happen when the game is waiting through
SDL_Delay(1000), so we miss the input.
The delay MUST be there because the image has to stay for a certain amount
of time.
Please help me out.
SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
OK, thanks for the idea. Implementing it will take some time, so I’ll tell
you later.
By the way, I would REALLY appreciate a COMPLETE game tutorial for SDL. It
should be for a simple 2D game and must discuss ALL the aspects involved
right from start to finish. I’m particularly interested in class design and
game flow.
As I’m new to game dev. + OOP, I am having lots of troubles. 
Please help me find some tutorials.On Mon, Apr 7, 2008 at 10:14 PM, Justin Coleman wrote:
Delay is a bad way to do that. What you need is a timer instead. Your
game loop should look more like this:
set timer for how long to display card
while game is playing
if display time not expired
redraw screen
check for mouse clicked
if click is detected
check for click coordinates in the right place
decrement display time by amount of time passed since last loop
Hope that helps you.
-J
On Mon, Apr 7, 2008 at 12:39 PM, Ankush Thakur <@Ankush_Thakur> wrote:
Hi,
I am making a small game.
The requirement is that an image will be displayed for some time (say
1000
ms), and the user has to click on it.
After the click, we must check for click coordinates.
the general structure I follows goes like this:
draw();
checkForInput();
delay for 1000 ms();
The problem is that mouse clicks are not getting detected. I guess it
is
because the mouse clicks happen when the game is waiting through
SDL_Delay(1000), so we miss the input.
The delay MUST be there because the image has to stay for a certain
amount
of time.
Please help me out.
SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
Have you ever tried “Programming Linux Games”, from Loki’s games?
It covers well SDL and a simple 2D game is crerated through the book.
If you search “Programming Linux Games” in google you’ll eventualy find a
link to it. It’s an e-book.
Good Luck!
2008/4/7, Ankush Thakur <ankush.gamedev at gmail.com>:>
OK, thanks for the idea. Implementing it will take some time, so I’ll tell
you later.
By the way, I would REALLY appreciate a COMPLETE game tutorial for SDL.
It should be for a simple 2D game and must discuss ALL the aspects involved
right from start to finish. I’m particularly interested in class design and
game flow.
As I’m new to game dev. + OOP, I am having lots of troubles. 
Please help me find some tutorials.
On Mon, Apr 7, 2008 at 10:14 PM, Justin Coleman wrote:
Delay is a bad way to do that. What you need is a timer instead. Your
game loop should look more like this:
set timer for how long to display card
while game is playing
if display time not expired
redraw screen
check for mouse clicked
if click is detected
check for click coordinates in the right place
decrement display time by amount of time passed since last loop
Hope that helps you.
-J
On Mon, Apr 7, 2008 at 12:39 PM, Ankush Thakur <ankush.gamedev at gmail.com> wrote:
Hi,
I am making a small game.
The requirement is that an image will be displayed for some time (say
1000
ms), and the user has to click on it.
After the click, we must check for click coordinates.
the general structure I follows goes like this:
draw();
checkForInput();
delay for 1000 ms();
The problem is that mouse clicks are not getting detected. I guess it
is
because the mouse clicks happen when the game is waiting through
SDL_Delay(1000), so we miss the input.
The delay MUST be there because the image has to stay for a certain
amount
of time.
Please help me out.
SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
I’m attaching my main.cpp source file with this mail.
The trouble is that I have to handle a game variable called gameRunning.
So, the structure now is…
main()
while gameRunning
while frame time not elasped…
draw
check for clicks
........... etc etc.
The problem is that the game in eating increasing amounts of RAM per second.
I guess the reason is the two while loops or maybe I’m wrong.
My programming is not so good, so please feel free to scold me for any
concept/design errors in my program.
Any questions related to code, please ask.
Please help me out with this.
-------------- next part --------------
A non-text attachment was scrubbed…
Name: main.cpp
Type: application/octet-stream
Size: 9970 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20080407/a3dc1be5/attachment.obj
Thanks a lot.
The book does look good, but follows C code 
I would have been more happy with an object oriented approach, which I
believe is the basic for modern games.On Mon, Apr 7, 2008 at 11:01 PM, Leonardo Guilherme < leonardo.guilherme at gmail.com> wrote:
Have you ever tried “Programming Linux Games”, from Loki’s games?
It covers well SDL and a simple 2D game is crerated through the book.
If you search “Programming Linux Games” in google you’ll eventualy find a
link to it. It’s an e-book.
Good Luck!
2008/4/7, Ankush Thakur <@Ankush_Thakur>:
OK, thanks for the idea. Implementing it will take some time, so I’ll
tell you later.
By the way, I would REALLY appreciate a COMPLETE game tutorial for
SDL. It should be for a simple 2D game and must discuss ALL the aspects
involved right from start to finish. I’m particularly interested in class
design and game flow.
As I’m new to game dev. + OOP, I am having lots of troubles. 
Please help me find some tutorials.
On Mon, Apr 7, 2008 at 10:14 PM, Justin Coleman wrote:
Delay is a bad way to do that. What you need is a timer instead. Your
game loop should look more like this:
set timer for how long to display card
while game is playing
if display time not expired
redraw screen
check for mouse clicked
if click is detected
check for click coordinates in the right place
decrement display time by amount of time passed since last loop
Hope that helps you.
-J
On Mon, Apr 7, 2008 at 12:39 PM, Ankush Thakur < @Ankush_Thakur> wrote:
Hi,
I am making a small game.
The requirement is that an image will be displayed for some time
(say 1000
ms), and the user has to click on it.
After the click, we must check for click coordinates.
the general structure I follows goes like this:
draw();
checkForInput();
delay for 1000 ms();
The problem is that mouse clicks are not getting detected. I guess
it is
because the mouse clicks happen when the game is waiting through
SDL_Delay(1000), so we miss the input.
The delay MUST be there because the image has to stay for a certain
amount
of time.
Please help me out.
SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
Well, at least you can have a good look at the SDL functions… I think that
the converting the C approach into C++ code ins’t that hard… or it is?
You can find some good game concepts in the book, so its worth some
attention.
2008/4/7, Ankush Thakur <ankush.gamedev at gmail.com>:>
Thanks a lot.
The book does look good, but follows C code 
I would have been more happy with an object oriented approach, which I
believe is the basic for modern games.
On Mon, Apr 7, 2008 at 11:01 PM, Leonardo Guilherme < @Leonardo_Guilherme> wrote:
Have you ever tried “Programming Linux Games”, from Loki’s games?
It covers well SDL and a simple 2D game is crerated through the book.
If you search “Programming Linux Games” in google you’ll eventualy find
a link to it. It’s an e-book.
Good Luck!
2008/4/7, Ankush Thakur <ankush.gamedev at gmail.com>:
OK, thanks for the idea. Implementing it will take some time, so I’ll
tell you later.
By the way, I would REALLY appreciate a COMPLETE game tutorial for
SDL. It should be for a simple 2D game and must discuss ALL the aspects
involved right from start to finish. I’m particularly interested in class
design and game flow.
As I’m new to game dev. + OOP, I am having lots of troubles. 
Please help me find some tutorials.
On Mon, Apr 7, 2008 at 10:14 PM, Justin Coleman wrote:
Delay is a bad way to do that. What you need is a timer instead.
Your
game loop should look more like this:
set timer for how long to display card
while game is playing
if display time not expired
redraw screen
check for mouse clicked
if click is detected
check for click coordinates in the right place
decrement display time by amount of time passed since last
loop
Hope that helps you.
-J
On Mon, Apr 7, 2008 at 12:39 PM, Ankush Thakur < ankush.gamedev at gmail.com> wrote:
Hi,
I am making a small game.
The requirement is that an image will be displayed for some time
(say 1000
ms), and the user has to click on it.
After the click, we must check for click coordinates.
the general structure I follows goes like this:
draw();
checkForInput();
delay for 1000 ms();
The problem is that mouse clicks are not getting detected. I
guess it is
because the mouse clicks happen when the game is waiting through
SDL_Delay(1000), so we miss the input.
The delay MUST be there because the image has to stay for a
certain amount
of time.
Please help me out.
SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
The C language family isn’t my strong suit, so this may be completely wrong, but it looks to me like you’re declaring variables within the body of your while loop. If so, it’s no surprise that you’re leaking memory. Try declaring all variables at the very top of the function, before any actual lines of code, so they only get allocated once. See if that fixes it.> ----- Original Message -----
From: ankush.gamedev@gmail.com (Ankush Thakur)
To: A list for developers using the SDL library. (includes SDL-announce)
Sent: Monday, April 7, 2008 10:33:42 AM
Subject: Re: [SDL] Mouse Input + Delay problem
I’m attaching my main.cpp source file with this mail.
The trouble is that I have to handle a game variable called gameRunning.
So, the structure now is…
main()
while gameRunning
while frame time not elasped…
draw
check for clicks
........... etc etc.
The problem is that the game in eating increasing amounts of RAM per second. I guess the reason is the two while loops or maybe I’m wrong.
My programming is not so good, so please feel free to scold me for any concept/design errors in my program.
Any questions related to code, please ask.
Please help me out with this.
You’re using a lot of operator new and I don’t see any deletes to
accompany them. Your program seems to be allocating new memory for
everything each frame. Try checking whether the pointer is valid
first, and only new it if it’s null.
-J
Ankush Thakur wrote:
I’m attaching my main.cpp source file with this mail.
The trouble is that I have to handle a game variable called gameRunning.
So, the structure now is…
main()
while gameRunning
while frame time not elasped…
draw
check for clicks
........... etc etc.
The problem is that the game in eating increasing amounts of RAM per
second. I guess the reason is the two while loops or maybe I’m wrong.
The reason you’re leaking memory is that you’re creating a new SDL_Rect
everytime you use one. You only need one … ie
SDL_Rect temp_Rect;
// set rect params
// pass the address like so
engine.draw(tmp_Surface, &tmp_Rect);
// change parameters and use it again.
engine.draw(tmp_Surface, &tmp_Rect);
This of course assumes that your engine is just using the values in each
call and not storing the address for some future use.
There are other places where you’re “newing” data, but there are no
deletes. When you’re allocating memory in a loop and you never delete
it, you’ll be out of memory soon.
CWC
Leonardo Guilherme wrote:
Well, at least you can have a good look at the SDL functions… I
think that the converting the C approach into C++ code ins’t that
hard… or it is?
You can find some good game concepts in the book, so its worth some
attention.
2008/4/7, Ankush Thakur <@Ankush_Thakur
mailto:Ankush_Thakur>:
Thanks a lot.
The book does look good, but follows C code :(
I would have been more happy with an object oriented approach,
which I believe is the basic for modern games.
Have you ever tried "Programming Linux Games", from Loki's games?
It covers well SDL and a simple 2D game is crerated through
the book.
If you search "Programming Linux Games" in google you'll
eventualy find a link to it. It's an e-book.
Good Luck!
2008/4/7, Ankush Thakur <@Ankush_Thakur
<mailto:@Ankush_Thakur>>:
OK, thanks for the idea. Implementing it will take some
time, so I'll tell you later.
By the way, I would *REALLY* appreciate a COMPLETE game
tutorial for SDL. It should be for a simple 2D game and
must discuss ALL the aspects involved right from start to
finish. I'm particularly interested in class design and
game flow.
As I'm new to game dev. + OOP, I am having lots of
troubles. :(
Please help me find some tutorials.
Delay is a bad way to do that. What you need is a
timer instead. Your
game loop should look more like this:
set timer for how long to display card
while game is playing
if display time not expired
redraw screen
check for mouse clicked
if click is detected
check for click coordinates in the
right place
decrement display time by amount of time passed
since last loop
Hope that helps you.
-J
> Hi,
>
> I am making a small game.
> The requirement is that an image will be displayed
for some time (say 1000
> ms), and the user has to click on it.
> After the click, we must check for click coordinates.
>
> the general structure I follows goes like this:
>
> draw();
> checkForInput();
> delay for 1000 ms();
>
> The problem is that mouse clicks are not getting
detected. I guess it is
> because the mouse clicks happen when the game is
waiting through
> SDL_Delay(1000), so we miss the input.
>
> The delay MUST be there because the image has to stay
for a certain amount
> of time.
>
> Please help me out.
>
> _______________________________________________
> SDL mailing list
> SDL at lists.libsdl.org <mailto:SDL at lists.libsdl.org>
> http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
>
>
_______________________________________________
SDL mailing list
SDL at lists.libsdl.org <mailto:SDL at lists.libsdl.org>
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
_______________________________________________
SDL mailing list
SDL at lists.libsdl.org <mailto:SDL at lists.libsdl.org>
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
_______________________________________________
SDL mailing list
SDL at lists.libsdl.org <mailto:SDL at lists.libsdl.org>
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
_______________________________________________
SDL mailing list
SDL at lists.libsdl.org <mailto:SDL at lists.libsdl.org>
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
All right, I’ll go through it after this game is finished. Thanks :)> On Mon, Apr 7, 2008 at 11:01 PM, Leonardo Guilherme <leonardo.guilherme at gmail.com <mailto:leonardo.guilherme at gmail.com>> wrote:
On Mon, Apr 7, 2008 at 10:14 PM, Justin Coleman <jmcoleman at gmail.com <mailto:jmcoleman at gmail.com>> wrote:
On Mon, Apr 7, 2008 at 12:39 PM, Ankush Thakur <@Ankush_Thakur <mailto:@Ankush_Thakur>> wrote: