Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


LazyFoo's Per-Pixel Collision Tutorial (SDL)


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 Motoky   Members   -  Reputation: 182

Like
0Likes
Like

Posted 14 June 2013 - 05:52 AM

I have been working through these tutorials for a while now. I have been stuck a few times, but managed to overcome it on my own or through some very helpful posters on here.

 

I have the program all and running. The program displays to circles of the same size and you are meant to move one circle towards the other and they will collide together. Once they meet, the circle stops.

 

The problem I am having is with keyboard input. I've got it working in previous tutorials, but I have been slowly changing my code to spread across multiple header files and source files to make it easier to read.

 

I can't upload the project because it's too big as a whole. I also have trouble getting code to appear properly without it looking like a mess and readable on here.

 

I guess I will upload an image of each section that I am having trouble with.

 

 

Okay, from the image. The first section is where I poll for events. I then try to retrieve input for my dot object. I send that same Event structure to the function which is shown in the second section. It checks for the key down event and checks the type of key that was pressed and increases or decreases the velocity of the circle depending on the key that was pressed. It also checks to see if that key was released and then sets the velocity to 0 making the circle stop moving. Again, if nothing was pressed, it goes back to the first section and checks to see if the type of event was a quit event, control is returned to the main function in the third section.

 

In the third section, if the function returned false, quit becomes true and the program exits. This event works, it quits when I press on the 'X'. If I didn't press 'X', the program should return control to main and move the circle as shown in the function moveSprites(), clears the screen to white, displays the circles, flips the back buffer and caps the frame rate to 20 FPS.

 

 

It seems like a lot to follow, but for some reason, the circle just isn't moving. I've been through my code a hell of a lot and I can't see what the problem is. I've compared it to a previous SDL project and I've only changed a few things, and all I have done is handled all of my input inside the SDLManager class. I've even tried changing this project to closely match my previous project and it's still not working.

Attached Thumbnails

  • SDL Problems.png


Sponsor:

#2 amrazek111   Members   -  Reputation: 693

Like
0Likes
Like

Posted 16 June 2013 - 01:25 PM

Nothing stands out to me at first glance.  Have you tried going through it line-by-line with a debugger?



#3 Godmil   Members   -  Reputation: 744

Like
0Likes
Like

Posted 16 June 2013 - 02:35 PM

The only thing that's catching my eye is that LazyFoo's dot->handleEvents() doesn't take an argument, while yours passes the event. It doesn't look wrong though :( is there any way you could zip the code files and email them to me at my username at gmail.com and I'll see if I can do some more in depth debugging. I feel there could be something useful to learn by finding out why this doesn't work.

#4 Motoky   Members   -  Reputation: 182

Like
0Likes
Like

Posted 17 June 2013 - 08:48 AM

Yeh I can email it to you. Just make sure you have SDL all set up though.

 

PM me your Gmail.

 

Cheers.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS