Fading Text Display. Comments?

Community Forums/Showcase/Fading Text Display. Comments?

WERDNA(Posted 2009) [#1]
Hey everyone!

I recently created the story sequence for my game, Ping Pong Battle,
and after experimenting a bit with various font commands, was
able to make some really nifty text for the story that 'fades' in and out.
Starts out pure black, slowly turns brighter and brighter white,
and then fades to black again and is replaced by new text.

Just wanted to get some opinions on this and see what everyone
thinks, and if there is any way that I could improve upon it.


I've included the code along with the .exe as well, because I
know I could improve it, probably using types and a For loop, or
just using an array :)

I'll stuff the code in a codebox for you as well, just to make things
convenient!

http://www.mediafire.com/?yfbzrzmzqmm





Merry Christmas Everyone!


Sauer(Posted 2009) [#2]
Cool story, I'm really into table tennis myself. I hate to nit pick, but there is a grammar issue: "Once Atlantis sunk beneath the waves" shouldbe "Once Atlantis sank beneath the waves".


WERDNA(Posted 2009) [#3]
Yeah I wasn't sure about that, lol.
also beginning is misspelled :)


I find it interesting that you actually like the story.
Wasn't sure how well it would be received.

Its mainly inspired by Mortal Kombat.


How does the code look?
I've been really trying lately to clean up my code, and especially to
make functions self reliant(I think thats the right term), so they don't
have to rely on globals, or outside values.


Sauer(Posted 2009) [#4]
It would be better if you put your strings in a Blitz Array and used for loops to iterate over them when printing them out, that way you have less redundant code.

Also, indentation of code is nice.


Foppy(Posted 2009) [#5]
I agree about using an array. You can then do:

For i = 0 to numberOfStrings-1
  Text GraphicsWidth()/2-StringWidth(myStringArray(i))/2,FontHeight()*2,myStringArray(i)
Next


(Instead of dealing with every string on its own line of code.)

You could put the strings in lines of Data at the bottom of the program and read those into an array at the start.

P.S. I can't see the effect right now because I'm at work.

Edit: This example assumed use of a global array, using round brackets for array access.


Duckstab[o](Posted 2009) [#6]
yes very nice :)

Coding comments are true you could cut the code down by 60% then give some room for moving text code :)


WERDNA(Posted 2009) [#7]
Ok, I figured an array was the way to go.

Thanks for the example Foppy!

And yeah, I know I still forget to indent, lol. I'm working on it :)

60% then give some room for moving text code

Nifty!


Thanks everyone!


Yeshu777(Posted 2009) [#8]
Couldn't you read / parse the text from a seperate file?


Sauer(Posted 2009) [#9]
I second the Data block suggestion, I find it easier to parse than a plain text file.


WERDNA(Posted 2009) [#10]
I'll modify my code using the Data block suggestion, and repost it in
a day or two :)

Also I'm still really noob in BlitzMax, and will be posting a BlitzMax
copy of this, that I don't really understand whats wrong with it.

Thanks everyone!


therevills(Posted 2009) [#11]
LOL.... didnt I say to use an array last time Werdna.... ;)

But I do agree that it should be in a separte text file, therefore if you want to translate your game in the future, all you have to do is replace the text files (as long as your chosen font can handle foreign characters)....


WERDNA(Posted 2009) [#12]
Ok, I have 2 new versions.

Using Blitz3D, this version reads the text from a separate file into
an array, and prints depending on what values I set NumSeen, and
NumInScene too. I still have to modify this a bit, but this is the direction
I'm going in :)



Separate Text File that data is read from.



And the BlitzMax version which goes along the lines of the first version.
I'm still really noob with BlitzMax, and am obviously doing something
wrong with this. because it runs VERY slowly.
(Although doesn't seem to have any problems besides that :)



Tell me what you think,
(Particularly with the BlitzMax one)


BlitzSupport(Posted 2009) [#13]
That last BlitzMax example is running slowly because the last parameter of Graphics in BlitzMax isn't the same as in Blitz3D (where it controls the window mode) -- in BlitzMax it's the refresh rate, ie. you're limiting it to 2 frames per second here! Caught me out with that one.

There's quite a bit that could be optimised there:

Calculate GraphicsWidth()/2 just once and store it in a Global just after Graphics -- you're calculating this for every single DrawText call.

You're going through each and every case on every frame with all those If statements, ie. even if Scene = 1, you're still checking If Scene = 2... 6 after that. Use Select instead, which simply jumps to the right Scene and then exits, ignoring all the other cases:

Select Scene

    Case 1
        DrawText String1$, x, y
        DrawText String2$, x, y
        DrawText String3$, x, y

    Case 2
        DrawText String1$, x, y
        DrawText String2$, x, y
        DrawText String3$, x, y

    Case 3
        DrawText String4$, x, y
        DrawText String5$, x, y
        DrawText String6$, x, y

    Case 4
        DrawText String7$, x, y
        DrawText String8$, x, y
        DrawText String9$, x, y

    Case 5
        DrawText String10$, x, y
        DrawText String11$, x, y
        DrawText String12$, x, y

    Case 6
        DrawText String13$, x, y
        DrawText String14$, x, y
        DrawText String15$, x, y

End Select


Use arrays like others suggested, then you only have to do something like this:

Select Scene

    Case 1
        For storyline = 1 To 5
            linewidth = TextWidth (StoryString (storyline)) / 2
            DrawText StoryString (storyline), GW - linewidth, y
        Next

    Case 2
        For storyline = 6 To 10
            linewidth = TextWidth (StoryString (storyline)) / 2
            DrawText StoryString (storyline), GW - linewidth, y
        Next

End Select


... instead of typing each DrawText line out separately.

Here's a reworked version:



I found indenting much easier once I started typing the opening and closing parts of If/EndIf, Select/End Select, Function/End Function, While/Wend, etc, before typing any code inside them, eg.:

If
EndIf

' After typing EndIf and hitting Enter, press Up, Enter, Up, Tab:

If
	' Cursor now here, and hitting Enter after each line will keep the indentation...
EndIf

' Doing the same Up/Enter/Up/Tab sequence for such Start/End blocks while inside an indented block will indent further and keep you in the right place:

If

	While
		' Now here...
	Wend

EndIf




Yasha(Posted 2009) [#14]
For indentation, your best strategy is to get IDEal (it's free). Among the hundreds of other goodies on offer, it automatically correctly indents each line as you type it, and optionally can also fill out the end of a block (the Wend, EndIf, etc.) on the line beyond the cursor, meaning you do just that little bit less typing.


WERDNA(Posted 2009) [#15]
lol, I set the refresh rate to 2?

I knew I was doing something wrong :)


Thanks a bundle BlitzSupport!

I'll try reworking my code today more along the lines of your example.
(But so it can read from a text file too!)


And thanks Yasha. I'll definitely give that a try. I always forget to
indent or find it too bothersome, lol.

Although I should probably learn :(


Dabhand(Posted 2009) [#16]
Indenting is essential in my opinion.

Just thought I'd chuck that in! ;)

Dabz


MGE(Posted 2009) [#17]
Only programmers care how things were done, end users playing the game could care less. ;)


WERDNA(Posted 2009) [#18]
Just tried out your suggestion for Indenting BlitzSupport!

If
EndIf

' After typing EndIf and hitting Enter, press Up, Enter, Up, Tab:

If
' Cursor now here, and hitting Enter after each line will keep the indentation...
EndIf

' Doing the same Up/Enter/Up/Tab sequence for such Start/End blocks while inside an indented block will indent further and keep you in the right place:

If

While
' Now here...
Wend

EndIf



Very much appreciated. I will practice it until it becomes natural :)

Thanks!


BlitzSupport(Posted 2009) [#19]
Cool... I do type the first line in full first myself, eg.

If x = y
EndIf


It'd be too much hassle otherwise!