Page 1 of 1

typewriter effect

Posted: Mon Jun 03, 2019 4:11 am
by ronin68k
Hi, guys! I'm trying to add a typewriter effect to my project. I've duplicated VDP_drawTextBG function and modifying it :lol:
The main goal was achieved - i got it typing by one letter after another, but when it came to the next line (or even next string), it duplicated what I've written before and overwriting it with typewriter effect. Seems like it memorizes the string and pastes it as an array of tiles.
There is another problem - each call takes amount of time before next string appears on the screen.

Here's the rom and the source code, If someone could help me with it, i would be very happy :3

Code: Select all

#include <genesis.h>

#define _countof(a) (sizeof(a)/sizeof(*(a)))
#define xcentr(i) (VDP_getScreenWidth()/8)/2-(strlen(i)/2)

void typewrite(const char *str, u16 y);

const char * letter[]=
{
	"Dear santa,",
	"I've been good all year.",
	"Okay, most of the time.",
	"Well, most in a while.",
	"Oh... never mind,",
	"I'll buy my own stuff!"
};

int main()
{
	for(u16 i = 0; i < _countof(letter); i++)
	typewrite(letter[i], i+10);

	while(1)
		VDP_waitVSync();

	return 0;
}

static u16 text_basetile;
void typewrite(const char *str, u16 y)
{
	u32 len;
	u16 data[128];
	const u8 *s;
	u16 *d;
	u16 i;
	VDPPlan plan = PLAN_A;
	u16 x = xcentr(str);

	// get the horizontal plan size (in cell)
	i = (plan.value == CONST_PLAN_WINDOW)?windowWidth:planWidth;
	len = strlen(str);

	// if string don't fit in plan, we cut it
	if (len > (i - x))
		len = i - x;

	s = (const u8*) str;
	d = data;

	while(i--)
	{
		*d++ = TILE_FONTINDEX + (*s++ - 32);
		VDP_setTileMapDataRectEx(plan, data, text_basetile, x, y, len, 1, len);
		waitMs(50);
	}
}

Re: typewriter effect

Posted: Mon Jun 03, 2019 7:47 am
by Stef
Shouldn't you fill the data first then do the TypeWriter code afterward ? Also I don't understand why you're rewriting the full text each time, you can only add one letter by one letter.

Re: typewriter effect

Posted: Mon Jun 03, 2019 2:00 pm
by ronin68k
Stef wrote:
Mon Jun 03, 2019 7:47 am
Shouldn't you fill the data first then do the TypeWriter code afterward ? Also I don't understand why you're rewriting the full text each time, you can only add one letter by one letter.
That's where I'm stuck at :oops:
I've googled a lot, even tried stackoverflow advices, something like

Code: Select all

char* text[]= "Hello, world!";
...
VDP_drawText(text[i], 0, 0);
but no luck.

Re: typewriter effect

Posted: Mon Jun 03, 2019 5:10 pm
by matasiete
I do a similar effect in my jetpac port for printing the game info. Really basic stuff.

Here the code.
https://github.com/diegomtassis/md-jetp ... /printer.c

You can see the effect right after running the rom.
https://github.com/diegomtassis/md-jetp ... ut/rom.bin

Re: typewriter effect

Posted: Mon Jun 03, 2019 5:17 pm
by ronin68k
Wow, that's really cool! Thank you :)
btw, nice game!

Re: typewriter effect

Posted: Fri Jul 12, 2019 10:42 am
by Boyfinn
I rencently made this:
https://www.dropbox.com/s/7o2s4kcwr3ssj5f/rom.bin?dl=1
You mean something like this?

Re: typewriter effect

Posted: Fri Oct 25, 2019 8:50 pm
by ronin68k
Boyfinn wrote:
Fri Jul 12, 2019 10:42 am
I rencently made this:
https://www.dropbox.com/s/7o2s4kcwr3ssj5f/rom.bin?dl=1
You mean something like this?
Yes, this is cool! 8)

Re: typewriter effect

Posted: Tue Jan 14, 2020 2:17 am
by Boyfinn
My example uses sprites though, because i needed larger letters and both my background layers are a bit busy in the project i applied this to.