Flipping sprites issue.

SGDK only sub forum

Moderator: Stef

Post Reply
orlanrod
Very interested
Posts: 95
Joined: Fri Sep 25, 2015 7:46 pm

Flipping sprites issue.

Post by orlanrod » Sun Aug 06, 2017 1:57 am

While trying a new way to handle animation, the flipping function seems to stop working after triggering once.
Setting the frame keeps on working though. I'm new to using arrays in c, but i don't think that's the issue. Here is the code bellow.

Code: Select all

void updatePAnim()
{
	int townbodyanims[12][8] = {

			{0,0,0,0,0,0,0,0} , //core idle down
			{0,1,2,1,0,1,2,1} , //core walk down
			{0,1,2,3,4,4,4,1} , //core idle side
			{0,1,2,3,4,4,4,1} , //core walk side
			{0,1,2,3,4,4,4,1} , //core idle up
			{0,1,2,3,4,4,4,1} , //core walk up
			{0,1,2,3,4,4,4,1} , //wild idle down
			{0,1,2,3,4,4,4,1} , //wild walk down
			{0,1,2,3,4,4,4,1} , //wild idle side
			{0,1,2,3,4,4,4,1} , //wild walk side
			{0,1,2,3,4,4,4,1} , //wild idle up
			{0,1,2,3,4,4,4,1} , //wild walk up

	};

	char *townbodyflipState[12][8] = {

			{"FALSE","FALSE","FALSE","FALSE","FALSE","FALSE","FALSE","FALSE"} , //core idle down
			{"TRUE","TRUE","TRUE","TRUE","FALSE","FALSE","FALSE","FALSE"} , //core walk down
			{"FALSE","FALSE","FALSE","FALSE","FALSE","FALSE","FALSE","FALSE"} , //core idle side
			{"FALSE","FALSE","FALSE","FALSE","FALSE","FALSE","FALSE","FALSE"} , //core walk side
			{"FALSE","FALSE","FALSE","FALSE","FALSE","FALSE","FALSE","FALSE"} , //core idle up
			{"FALSE","FALSE","FALSE","FALSE","FALSE","FALSE","FALSE","FALSE"} , //core walk up
			{"FALSE","FALSE","FALSE","FALSE","FALSE","FALSE","FALSE","FALSE"} , //wild idle down
			{"FALSE","FALSE","FALSE","FALSE","FALSE","FALSE","FALSE","FALSE"} , //wild walk down
			{"FALSE","FALSE","FALSE","FALSE","FALSE","FALSE","FALSE","FALSE"} , //wild idle side
			{"FALSE","FALSE","FALSE","FALSE","FALSE","FALSE","FALSE","FALSE"} , //wild walk side
			{"FALSE","FALSE","FALSE","FALSE","FALSE","FALSE","FALSE","FALSE"} , //wild idle up
			{"FALSE","FALSE","FALSE","FALSE","FALSE","FALSE","FALSE","FALSE"} , //wild walk up
	};



	if (paction == 5) { //walk down animation

		if (VDP_VBLANK_FLAG) {

							if (panimtimer < 15) {

								panimtimer += 1;


							}else{

								if (animloop < 8){


									SPR_setFrame(sprites[1], townbodyanims[1][animloop]);
									SPR_setVFlip(sprites[1], *townbodyflipState[1][animloop]);
									VDP_drawText(townbodyflipState[1][animloop], 10, 15);

									animloop++;
								}else{
									animloop = 0;
								}

								panimtimer = 0;
							}
		}



	}
}

cero
Very interested
Posts: 206
Joined: Mon Nov 30, 2015 1:55 pm

Re: Flipping sprites issue.

Post by cero » Sun Aug 06, 2017 8:43 am

That function does not take a string, it takes a TRUE/FALSE integer. Also, your arrays are non-const, so they're wasting RAM.

Your compiler probably warned you about that.

orlanrod
Very interested
Posts: 95
Joined: Fri Sep 25, 2015 7:46 pm

Re: Flipping sprites issue.

Post by orlanrod » Mon Aug 07, 2017 1:12 am

cero wrote:
Sun Aug 06, 2017 8:43 am
That function does not take a string, it takes a TRUE/FALSE integer. Also, your arrays are non-const, so they're wasting RAM.

Your compiler probably warned you about that.
Ah okay. Yeah, i switched to int and made them constant. It worked. Thanks.

Miquel
Very interested
Posts: 216
Joined: Sat Jul 30, 2016 12:33 am

Re: Flipping sprites issue.

Post by Miquel » Mon Aug 07, 2017 3:20 am

Not enought, it's building those arrays into the stack every time you call the function.
Make it static or make it global to solve this nuisance.
Like:

Code: Select all

void updatePAnim()
{
	static int const townbodyanims[12][8] = {
...
or

Code: Select all

int const townbodyanims[12][8] = {
...
void updatePAnim()
{
...
Congratulations!, you have hit the lottery, president of little faith.
We were designed to be social, not only with humans but with other civilizations around the Solar System and beyond. They feel the same.
Enjoy your success, and PREPARE NEXT MOVE.

orlanrod
Very interested
Posts: 95
Joined: Fri Sep 25, 2015 7:46 pm

Re: Flipping sprites issue.

Post by orlanrod » Mon Aug 07, 2017 5:42 pm

Miquel wrote:
Mon Aug 07, 2017 3:20 am
Not enought, it's building those arrays into the stack every time you call the function.
Make it static or make it global to solve this nuisance.
Like:

Code: Select all

void updatePAnim()
{
	static int const townbodyanims[12][8] = {
...
or

Code: Select all

int const townbodyanims[12][8] = {
...
void updatePAnim()
{
...
Oh okay. Now it's updated. Thanks.

Post Reply

Who is online

Users browsing this forum: No registered users and 5 guests