Page 1 of 2

how create profiles

Posted: Fri Sep 11, 2009 7:57 pm
by reza10203045
how do i create profiles for game and save profile.

Re: how create profiles

Posted: Fri Sep 11, 2009 8:02 pm
by Robin
reza10203045 wrote:how do i create profiles for game and save profile.
I'm afraid your question is not very clear.

Are you asking how to save data? For that, you need the love.filesystem functions.

Could you please elaborate? It's hard to help you otherwise. :P

Re: how create profiles

Posted: Fri Sep 11, 2009 8:35 pm
by Jasoco
You'll need to code it yourself.

The input box for entering your name, the method for saving a file with the current game's data. I haven't implemented any of that yet as you would see if you tried my game. But I hope to try soon.

The name input part would be especially difficult as you'd have to run through a kind of loop waiting for key presses, figure out what key was pressed, add it to a string of characters pressed, if a backspace is pressed remove the last character. It's quite a mess. But when I get mine working, you'll be able to see it when I upload another demo.

Re: how create profiles

Posted: Fri Sep 11, 2009 9:10 pm
by Robin
Jasoco wrote:The name input part would be especially difficult
Well, it wouldn't be so difficult if you use a GUI library. ;)

Anyway, you can't use loops, it'll block the game completely. If you want your hands to get dirty, use game states.

Re: how create profiles

Posted: Fri Sep 11, 2009 9:56 pm
by Jasoco
Robin wrote:
Jasoco wrote:The name input part would be especially difficult
Well, it wouldn't be so difficult if you use a GUI library. ;)

Anyway, you can't use loops, it'll block the game completely. If you want your hands to get dirty, use game states.
That's what I meant. Loops would freeze the game. I'm going to try implementing one by putting in a state called "inSetup" which will handle key presses and display the appropriate stuff.

Re: how create profiles

Posted: Fri Sep 11, 2009 10:27 pm
by Jasoco
Here's a question though. How do I convert the code I get from love.key_press into the actual character?

Each key has a code that is recieved when a key is pressed. For instance, A is 97. B is 98. But there doesn't seem to be a way to differentiate between a capital and lowercase letter. I guess we can poll for Shift as well (Which is 104 and 103 for the Left and Right shift's) and deal with it accordingly.

Do I have to make my own chart to get the right letters? *sigh*

Re: how create profiles

Posted: Fri Sep 11, 2009 10:59 pm
by Jasoco
I have a very rudimentary setup right now:

This function will return a letter or number. Only letters and numbers right now. All lowercase.

Code: Select all

--RETURN LETTER FROM NUMBER
function returnChar(c)
	local str = ""
	if c > 96 and c < 123 then
		local chr = "abcdefghijklmnopqrstuvwxyz"
		local n = c - 96
		str = string.sub(chr, n, n)
	if c > 47 and c < 58 then
		local n = c - 48
		str = n
	else
		str = ""
	end
	if kShift then str = string.upper(str) end
	return str
end
In your KeyPress function:

Code: Select all

tmpName = tmpName .. returnChar(k)
Then in your Draw function you use something like this:

Code: Select all

love.graphics.drawf(tmpName, 100, 100, 640, love.align_center
Make sure you have a global variable first. I used tmpName to hold the name.

I haven't implemented backspace yet either. So don't go by me. This is just a starting prototype.

Edit: Making good progress. Will post all my code when I get it perfected.

Re: how create profiles

Posted: Sat Sep 12, 2009 8:33 am
by bartbes
keycodes are available in 0.6.0

Re: how create profiles

Posted: Sun Sep 13, 2009 4:53 am
by Jasoco
Does 0.6.0 have ways to find out how wide a string of characters will be drawn at so we can figure out where to draw a cursor? If you create your own fonts, they could be any size, and any combination of characters could be any width. It's impossible to find out how wide the text is going to be so we can place a blinking cursor in the right place. We need some ways of finding out the dimensions of strings based on the font they're going to use. Like where the top left corner pixel will be at the end of a string of text. And it should have support for wrapped text too.

Basically it'd be something like:

Code: Select all

love.graphics.setFont(fontName)
local varTxtXY = love.graphics.print(stringOfText, 320)
love.graphics.print(stringOfText, screenW / 2 - 50, screenH / 2, 320, love.align_left)
love.graphics.line(varTxtXY[0], varTxtXY[1], 0, 20)
Where 320 is the optional wrap value (in case the stringOfTxt is long enough it wraps a few lines) and the varTxtXY would be a local array that is returned containing the rightmost x and y points based on the string's length.

Would be verrrrry useful for making it look seamless.

Re: how create profiles

Posted: Sun Sep 13, 2009 8:10 am
by Robin
Actually, this is possible in 0.5.0.
See http://love2d.org/docs/Font.html