Writing integers

SGDK only sub forum

Moderator: Stef

Post Reply
User avatar
Staffan
Very interested
Posts: 57
Joined: Wed Jun 14, 2017 2:33 pm

Writing integers

Post by Staffan » Mon Aug 07, 2017 6:07 am

Hello,
Its certainly not hard to write text to the screen in SGDK. I wonder though if there is some way to write a number (a variable), to see how many coins left on a level etc etc.

Moon-Watcher
Very interested
Posts: 115
Joined: Sun Jan 02, 2011 9:14 pm

Re: Writing integers

Post by Moon-Watcher » Mon Aug 07, 2017 7:34 am

Use intToStr() and uintToStr() functions this way

Code: Select all

void drawInt( u32 nb, u8 x, u8 y, u8 zeros )
{
	s8 str [ zeros+1 ];
	intToStr ( nb, str, zeros );

	SYS_disableInts();
	VDP_drawText ( str, x, y );
	SYS_enableInts();
}

void drawUInt( u32 nb, u8 x, u8 y, u8 zeros )
{
	s8 str [ zeros+1 ];
	uintToStr ( nb, str, zeros );

	SYS_disableInts();
	VDP_drawText ( str, x, y );
	SYS_enableInts();
}

User avatar
Staffan
Very interested
Posts: 57
Joined: Wed Jun 14, 2017 2:33 pm

Re: Writing integers

Post by Staffan » Tue Aug 08, 2017 1:10 pm

Worked flawlessly thank you :)

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests