Character Movement and Animation

Smooth walking between tiles.

  • (2 Pages)
  • +
  • 1
  • 2

15 Replies - 7345 Views - Last Post: 21 January 2010 - 08:53 AM Rate Topic: -----

#1 SamAllmon  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 30
  • Joined: 27-August 09

Character Movement and Animation

Posted 27 August 2009 - 03:38 PM

Okay.
So.
I've finished my introductory class for C++, and did quite well.
Now, I'm delving into the simple 2D game department.
My Particular approach is using DarkGDK.
I've made a shooter, A sakoban, and now am trying to do a 2D puzzle-platformer, Like Oddworld, Abe's Oddysee.

I have made the map (I'm working on getting the first level playable, before making an editor, though, that doesn't seem hard.)

So I know how to make the character move Via Pixels, with smooth animation.

And I know how to make him move from tile-to-tile, where he just "teleports" to the next square.

I'm greedy, so I want Grid Movement with smooth animation.

I need it to stay grid based, like Oddworld was, cuz I can cheat things like throwing and jumping, when the math is the same.

So what I'm looking for is, some pseudocode, or something, with an idea on how to even get this process started.

What I tried, and Horribly failed at was

void playerMoveLeft( void ) //this is called when you press left
{
	while (iMoveStep < 7)			  //I attempted to make
	{										   // it where you move a little, show a
			if (iMoveStep == 1)//sprite, move some more, next sprite
			{						  // Yaddayadda.
				iPlayerX = (iPlayerGridX * 32) - 5;
				dbSetSpriteFrame ( 1 , 12 );

				iMoveStep = 2;
			}
			else if (iMoveStep == 2) 
			{
				iPlayerX = (iPlayerGridX * 32) - 10;
				dbSetSpriteFrame ( 1 , 11 );
				iMoveStep = 3;
			}
			else if (iMoveStep == 3)
			{
				iPlayerX = (iPlayerGridX * 32) - 16;
				dbSetSpriteFrame ( 1 , 10 );
				iMoveStep = 4;
			}
			else if (iMoveStep == 4)
			{
				iPlayerX = (iPlayerGridX * 32) - 22;
			dbSetSpriteFrame ( 1 , 9 );
				iMoveStep = 5;
			}
			else if (iMoveStep == 5)
			{
				iPlayerX = (iPlayerGridX * 32) - 27;
			dbSetSpriteFrame ( 1 , 8 );
				iMoveStep = 6;
			}
			else if (iMoveStep == 6)
			{
				iPlayerX = (iPlayerGridX * 32) - 32;
			dbSetSpriteFrame ( 1 , 7 );
				iMoveStep = 7;
			}
			
			dbSprite ( 1 , iPlayerX , iPlayerY , 1 );
			dbWait(60);
			
	}
	iPlayerGridX--;
	if (iPlayerGridX < 0)
		iPlayerGridX = 0;
	iMoveStep = 1;


}




That just made him teleport, and was only quasi linked to the array.

Is it my C++ logic messed up, or My GDK stuff messed up?

I remember seeing something in a preview of Gaddis' book on DarkGDK, and he using dbSpriteAnimate(), but Alas, it was only a preview(the top 10 lines) and I couldn't see what was going on.

Even if you aren't Familiar with C++ or GDK, tell me how you would do it in your specific code, or give me pseudocode explaining it.
I can't seem to get it.

Any Help is appreciated.

Is This A Good Question/Topic? 0
  • +

Replies To: Character Movement and Animation

#2 Kanvus  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 42
  • View blog
  • Posts: 452
  • Joined: 19-February 09

Re: Character Movement and Animation

Posted 27 August 2009 - 11:45 PM

hard to tell without seeing the character sprite. usually the answer is in making the walk cycle look good then move its position at a reasonable speed in float values to get it over to the next cell or block. screenshots would explain more what the problem is.
Was This Post Helpful? 0
  • +
  • -

#3 SamAllmon  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 30
  • Joined: 27-August 09

Re: Character Movement and Animation

Posted 28 August 2009 - 10:35 AM

Posted Image
That is the Sprite.
But I can't take video of what the program is doing.
I don't have the program or whatever.

OH, and I didn't make the sprites, I just arranged them in the sheet.
They are a hold-over while I work on gameplay.

This post has been edited by SamAllmon: 28 August 2009 - 10:36 AM

Was This Post Helpful? 0
  • +
  • -

#4 SamAllmon  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 30
  • Joined: 27-August 09

Re: Character Movement and Animation

Posted 28 August 2009 - 11:32 AM

When I tried doing it with the dbPlaySprite(), he just teleported over, and then made the walking motion in the next cell.

Back in the day, when I attempted game-making in SWiSH, i would just make the animation, then tell it to move over one grid, and do it slowly.

I'm sure theres someway to do that, i mean, there's code running that makes SWiSH do it, I just don't know how.
Was This Post Helpful? 0
  • +
  • -

#5 stayscrisp  Icon User is offline

  • フカユ
  • member icon

Reputation: 998
  • View blog
  • Posts: 4,173
  • Joined: 14-February 08

Re: Character Movement and Animation

Posted 28 August 2009 - 12:40 PM

Hi

Well if your tiles are on a grid then they will all be the same size so you just need to create something that animates from the start point to the end point.

So lets say you have your sprite on one tile of 10x10 in the center of your grid if you moved up then you would just increase the y by a set amount and while that happens animate the sprite. so instead of just setting where the sprite is next, your going to have to make it move by a set amount and then use something like a while loop to say while the player has not reached the next tile play the sprite animation.

Hope that helps

This post has been edited by stayscrisp: 28 August 2009 - 12:41 PM

Was This Post Helpful? 0
  • +
  • -

#6 SamAllmon  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 30
  • Joined: 27-August 09

Re: Character Movement and Animation

Posted 28 August 2009 - 04:53 PM

So something like
while (LinksXPosition is NOT LinksOldPosition + 32)
	  dbPlaySprite(walking right);
	  LinksXPosition++;


?
Was This Post Helpful? 0
  • +
  • -

#7 SixOfEleven  Icon User is offline

  • using Caffeine;
  • member icon

Reputation: 945
  • View blog
  • Posts: 6,342
  • Joined: 18-October 08

Re: Character Movement and Animation

Posted 28 August 2009 - 05:16 PM

I don't use DarkGDK but that looks somewhat right. Your method call, dbPlaySprite. Does it do animation? Like, you have your sprite sheet(s) above does dbPlaySprite advance from the starting frame to the end frame?
Was This Post Helpful? 0
  • +
  • -

#8 SamAllmon  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 30
  • Joined: 27-August 09

Re: Character Movement and Animation

Posted 28 August 2009 - 05:26 PM

dbPlaySprite() takes these arguments
dbPlaySprite(
Sprite ID number, 
Start Frame (Numbered from 1(top left) to the end(this case, 36, bottom right)), 
end Frame, 
Delay between frames in milliseconds
);



So if I tell it to dbPlaySprite(1, 1, 6, 60);
It would Animate Link walking right, at about 17 frames a second.

This post has been edited by SamAllmon: 28 August 2009 - 05:27 PM

Was This Post Helpful? 0
  • +
  • -

#9 stayscrisp  Icon User is offline

  • フカユ
  • member icon

Reputation: 998
  • View blog
  • Posts: 4,173
  • Joined: 14-February 08

Re: Character Movement and Animation

Posted 29 August 2009 - 02:46 AM

View PostSamAllmon, on 28 Aug, 2009 - 03:53 PM, said:

So something like
while (LinksXPosition is NOT LinksOldPosition + 32)
	  dbPlaySprite(walking right);
	  LinksXPosition++;



Yeah that looks quite good, have you tested it?
Was This Post Helpful? 0
  • +
  • -

#10 SamAllmon  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 30
  • Joined: 27-August 09

Re: Character Movement and Animation

Posted 29 August 2009 - 05:42 AM

View Poststayscrisp, on 29 Aug, 2009 - 01:46 AM, said:

Yeah that looks quite good, have you tested it?


No, Not yet.

I'm planning the whole thing out, first.
I'm thinking I'll need it to be more like


dbSprite(1, playerX, playerY, 1); //make a sprite at this location
dbPlaySprite(1, frameStart, frameEnd, 60); //animate the portion of the
															   //sprite we want to
if (dbLeftKey())
{
	newPlayerX = playerX -32;
	frameStart = 7;//frames for left
	frameEnd = 12;
	
	while (playerX != newPlayerX)//while the player is not in the next square,
	{
		playerX--; //move him left a little
	}
	playerGridX--;//store him in the array next
	playerDirection = LEFT; //store the direction he's going, 
									  //so my rest animation can match it.
}

Etc.



I have the day off, so I'll work on it today.
Was This Post Helpful? 0
  • +
  • -

#11 SamAllmon  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 30
  • Joined: 27-August 09

Re: Character Movement and Animation

Posted 29 August 2009 - 06:56 AM

It doesn't move at all, now.
Dx


void playerUpdate ( void )
{
	// see if the player needs to try and go left
	if ( checkLeft() )
	{
		playerNewX=iPlayerX - 32;
		frameStart = 7;
		frameEnd = 12;
		while (iPlayerX != playerNewX)
		{
			iPlayerX--;
		}
		iPlayerDirection = LEFT;
	}
	// see if the player needs to try and go right
	else if ( checkRight() )
	{
		playerNewX=iPlayerX + 32;
		frameStart = 1;
		frameEnd = 6;
		while (iPlayerX != playerNewX)
		{
			iPlayerX++;
		}
		iPlayerDirection = RIGHT;
	}
	// not left or right, so lets face straight
	else
		switch (iPlayerDirection)
		{
		case LEFT:
		{
			frameStart = 19;
			frameEnd = 22;
		}
		case RIGHT:
		{
			frameStart = 13;
			frameEnd = 16;
		}
	}
}

Was This Post Helpful? 0
  • +
  • -

#12 stayscrisp  Icon User is offline

  • フカユ
  • member icon

Reputation: 998
  • View blog
  • Posts: 4,173
  • Joined: 14-February 08

Re: Character Movement and Animation

Posted 29 August 2009 - 10:32 AM

Instead of your checkleft and right functions use a bool such as

bool moveLeft;



then when the left key is pressed set it to true and when its released set it to false.

Where do you call those checkLeft() and checkRight() functions?
Was This Post Helpful? 0
  • +
  • -

#13 SamAllmon  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 30
  • Joined: 27-August 09

Re: Character Movement and Animation

Posted 29 August 2009 - 12:24 PM

View Poststayscrisp, on 29 Aug, 2009 - 09:32 AM, said:

Where do you call those checkLeft() and checkRight() functions?


In "Input.cpp"
They are Bools.
They just check if I'm pressing left (or a) or right ( or d)
I tried it with dbLeftKey() and dbRightKey(), still nothin.
Was This Post Helpful? 0
  • +
  • -

#14 SamAllmon  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 30
  • Joined: 27-August 09

Re: Character Movement and Animation

Posted 29 August 2009 - 12:35 PM

I got the animations to respond, but still no movement.
I wanna think it's how I'm using iPlayerX and playerNewX.
Was This Post Helpful? 0
  • +
  • -

#15 SamAllmon  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 30
  • Joined: 27-August 09

Re: Character Movement and Animation

Posted 29 August 2009 - 01:02 PM

I got it to move, but it's just teleporting over, and then playing animation, Like I had before.

If and Dark GDK users are here, what would dbMoveSprite() entail.
I know you have to rotate sprite, But would I have to do to my sheet with the characters sideways?

Cuz dbMoveSprite() moves Vertical, don't it?
I think dbMoveSprite takes Floats so it's constant.
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2