typewriter effect

SGDK only sub forum

Moderator: Stef

Post Reply
ronin68k
Interested
Posts: 29
Joined: Mon Nov 02, 2015 5:28 am
Location: Krasnodar, Russia

typewriter effect

Post by ronin68k » Mon Jun 03, 2019 4:11 am

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);
	}
}
Attachments
rom.rar
(22.93 KiB) Downloaded 254 times

Stef
Very interested
Posts: 3131
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Re: typewriter effect

Post by Stef » 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.

ronin68k
Interested
Posts: 29
Joined: Mon Nov 02, 2015 5:28 am
Location: Krasnodar, Russia

Re: typewriter effect

Post by ronin68k » Mon Jun 03, 2019 2:00 pm

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.

matasiete
Interested
Posts: 10
Joined: Thu Jan 25, 2018 6:21 pm
Location: Spain
Contact:

Re: typewriter effect

Post by matasiete » Mon Jun 03, 2019 5:10 pm

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

ronin68k
Interested
Posts: 29
Joined: Mon Nov 02, 2015 5:28 am
Location: Krasnodar, Russia

Re: typewriter effect

Post by ronin68k » Mon Jun 03, 2019 5:17 pm

Wow, that's really cool! Thank you :)
btw, nice game!

Boyfinn
Very interested
Posts: 57
Joined: Sat Aug 08, 2015 12:12 pm
Location: Lapland, Finland

Re: typewriter effect

Post by Boyfinn » 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?

ronin68k
Interested
Posts: 29
Joined: Mon Nov 02, 2015 5:28 am
Location: Krasnodar, Russia

Re: typewriter effect

Post by ronin68k » Fri Oct 25, 2019 8:50 pm

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)

Boyfinn
Very interested
Posts: 57
Joined: Sat Aug 08, 2015 12:12 pm
Location: Lapland, Finland

Re: typewriter effect

Post by Boyfinn » Tue Jan 14, 2020 2:17 am

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.

Post Reply