Sign in to follow this  
soitsthateasy

SDL Key Presses (C++)

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
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this