how create profiles

General discussion about LÖVE, Lua, game development, puns, and unicorns.
reza10203045
Prole
Posts: 4
Joined: Thu Sep 03, 2009 12:25 pm

how create profiles

Post by reza10203045 »

how do i create profiles for game and save profile.
Attachments
profile.jpg
profile.jpg (17.24 KiB) Viewed 6020 times
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: how create profiles

Post 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
Help us help you: attach a .love.
User avatar
Jasoco
Inner party member
Posts: 3727
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: how create profiles

Post 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.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: how create profiles

Post 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.
Help us help you: attach a .love.
User avatar
Jasoco
Inner party member
Posts: 3727
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: how create profiles

Post 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.
User avatar
Jasoco
Inner party member
Posts: 3727
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: how create profiles

Post 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*
User avatar
Jasoco
Inner party member
Posts: 3727
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: how create profiles

Post 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.
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: how create profiles

Post by bartbes »

keycodes are available in 0.6.0
User avatar
Jasoco
Inner party member
Posts: 3727
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: how create profiles

Post 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.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: how create profiles

Post by Robin »

Actually, this is possible in 0.5.0.
See http://love2d.org/docs/Font.html
Help us help you: attach a .love.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot] and 9 guests