Need help coding Megaman sprite sheet attack from the left (C++, SDL)

Started by
7 comments, last by LackOfGrace 17 years, 1 month ago
Wow I don’t like asking for help but I am having problems programming a Megaman Clone using the sprite sheet I got from the Internet. Ok I found the pixel coordinates for the sprite to make a walking animation, attacking animation and even jumping, but only facing to the right. The walking animations are just fine because they need no extra space[figures 1 and 2] But not the attacking animation. When the sprites are facing right and they need more space because of the sword extending[figure 3], I just add a dozen or two pixels to the source rectangle’s width. But when the player is facing the left, you must add to the source rectangle width[figure 4], AND subtract from the source rect’s x position. But that makes the player jump back. If you can understand me, please help.
Advertisement
I'd recommend establishing an 'anchor position' in each frame - one pixel that is a 'fixed point' as the character animates and moves around. Then you track where you want the fixed point to be, and render the rectangle such that it aligns correctly.

Richard "Superpig" Fine - saving pigs from untimely fates - Microsoft DirectX MVP 2006/2007/2008/2009
"Shaders are not meant to do everything. Of course you can try to use it for everything, but it's like playing football using cabbage." - MickeyMouse

I'm sorry but I don't understand. Could you give me a pic or something? What do you mean track it, I thought it was a fixed point?
Your data says, "I'm displaying a sprite using frame N at position (X,Y)."

Your renderer renders the sprite such that the "fixed point" in frame N is at position (X,Y).

That way, the data doesn't need to account for the width/height of the graphic.

Richard "Superpig" Fine - saving pigs from untimely fates - Microsoft DirectX MVP 2006/2007/2008/2009
"Shaders are not meant to do everything. Of course you can try to use it for everything, but it's like playing football using cabbage." - MickeyMouse


Quote: Your data says, "I'm displaying a sprite using frame N at position (X,Y)."

Your renderer renders the sprite such that the "fixed point" in frame N is at position (X,Y).

That way, the data doesn't need to account for the width/height of the graphic.


Yeah but you determine frame N by giving xy coordinates and the width and height.

edit: and thank you for helping me even if I am a little slow.
Quote:Original post by Evil Booger

Quote: Your data says, "I'm displaying a sprite using frame N at position (X,Y)."

Your renderer renders the sprite such that the "fixed point" in frame N is at position (X,Y).

That way, the data doesn't need to account for the width/height of the graphic.


Yeah but you determine frame N by giving xy coordinates and the width and height.

edit: and thank you for helping me even if I am a little slow.


What I think superpig means is that your pixel art is a bit off, so it looks like it's jumping back or forward. So what you need to do is to make sure that they're all centered. For instance, if your "megaman"'s feet doesn't move during the attack, make sure they're in the same spot throughout all the different sprites. Then when you render them, you don't have to worry about programming it so that it matches up (instead of doing "if spritenum == 1, move back 3 pixels, if spritenum == 2, move forward 2 pixels)

What I'd do is make all the sprites the SAME size, this way, I won't have to worry about right or left facing sprites. I'd just make them wide enough for both, then just render them normally. So if you have 48 pixels wide for a sprite facing right (and it takes 35 extra pixels to take in the sword) I'd recommend you make 118 pixels wide.
Or you could preprocess the frames by having (example) four pure red pixels around the character, then a pure blue pixel as anchor point. when you have that you just need to calculate the uv coordinates, and you wont waste tons of texture memory.

(in this case red pixels might not work, a pinkish color would work i think)


Quote:Original post by LackOfGrace
Or you could preprocess the frames by having (example) four pure red pixels around the character, then a pure blue pixel as anchor point. when you have that you just need to calculate the uv coordinates, and you wont waste tons of texture memory.

(in this case red pixels might not work, a pinkish color would work i think)

graphical and code example please [smile]

Beginner in Game Development?  Read here. And read here.

 

Well, im at work, so i dont have time to upload material or write you a snippet.
the psuedo code would look something like this though:

Image loading:
//Load Pixels
ColorValue Buffer[ ImageWidth * ImageHeight ]
LoadStuff( filepath , Buffer );

for( y as imageheight )
{
for( x as imagewidth )
{
Index = (y*imagewidth) + x
if( Buffer[Index].red == 1 )
{
Coord1 FindNextRedPixelHorizontal(x,y)
Coord2 FindNextRedPixelVertical(y,x)

if( Coord1 or Coord2 is Invalid ) break

Box.TopLeft = Coord( x,y )
Box.TopRight = Coord( Coord1.x , y )
Box.BottomLeft = Coord( x,Coord1.y )
Box.BottomRight = Coord( Coord1.x , Coord1.y )

Box.AnchorPosition = FindBluePixelInBox( Box );

BoxContainer.Push( Box )
}
}
}


when drawing:

Box = BoxContainer.getwantedbox( boxname )
//Create Image Corners
Position = PlayerPos - Box.AnchorPosition
RenderSprite( Sprite , Box , Position )



or something, i could be quite off in calculations since i dont have time to go check my code.
work work....


good luck with your sprites



This topic is closed to new replies.

Advertisement