Jump to content
  • Advertisement
Sign in to follow this  
soitsthateasy

SDL Key Presses (C++)

This topic is 2747 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I just started learning SDL from LazyFoo's tutorials and I'm trying to make a simple game of Tic-Tac-Toe. I made a console version a while ago so I want to make a graphical version now. I have a good idea of how to go about it, and I've worked out all the basic logic and functions now, Two things I need to work on:


1) How to find out where someone clicked on the screen.

2) How to write using fonts for the scoreboard (I believe that SDL can do that, could be wrong though...)

So any help would be appreciated, thanks in advance!

Share this post


Link to post
Share on other sites
Advertisement
Determining where someone clicked on a screen is relatively easy with SDL. I believe LazyFoo covers it in the 9th tutorial here. When you create an instance of the SDL_Event structure, you'll want to see if the SDL_Event's type variable is equal to SDL_MOUSEBUTTONDOWN. This indicates that one of the mouse buttons was pressed. Once you've determined that the input is indeed from a mouse, you can get the x and y coordinates of the mouse click. The Lazy Foo' page has the relevant code already there, so I'd advise that you take a look at it once you get to that point.

If you want to use fonts, SDL has an extension library called SDL_ttf which gives you support for True Type Fonts. You'll have to download SDL_ttf and set it to work with your IDE and compiler. Lazy Foo' has tutorials on handling additional libraries. You can change the color and size of the text you want to put on the screen. The text gets rendered as an SDL_Surface structure so that you can properly blit it to the screen. Lazy Foo' covers this subject in the 7th tutorial here.

Good luck with your project.

EDIT: Beaten by TerranceN!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!