I am beginner for UE4 program, now I am trying to learning how to use C++ to implement a simple 2D action side-scrolling game. The first step for that is try to set up a main character. I used 2D sprite and flipbook, then try to code some base function such as idle, walk, jump, and so on. I had a simple concept:
I also wrote some code for that but it didn’t work well, for example:
in character class. I used some bool to control the animation status:
// Custom Params
IsLanding = true;
IsWalking = false;
IsRunning = false;
IsStartJump = false;
IsRising = false;
IsStartFalling = false;
IsInAir = false;
IsFalling = false;
in Tick() function, I checked these variables.
The I used my custom function “UpdateAnimation” to set Flipbook. just like follow code:
// Standing
if (IsLanding && !IsRising && !IsRunning && !IsWalking)
{
GetSprite()->SetFlipbook(IdleAnimation);
}
// Walking
if (IsLanding && IsWalking && !IsRising && !IsRunning)
{
GetSprite()->SetFlipbook(WalkingAnimation);
}
// Running
if (IsRunning && IsLanding)
{
GetSprite()->SetFlipbook(RunningAnimation);
}
// Jump start
if (IsStartJump && !IsRising && !IsStartFalling)
{
GetSprite()->SetFlipbook(JumpStartAnimation);
}
// Jump rising
if (IsRising && !IsStartFalling && !IsStartJump)
{
GetSprite()->SetFlipbook(JumpRisingAnimation);
}
// Jump in air and start falling
if(IsStartFalling && !IsFalling && !IsStartJump)
{
GetSprite()->SetFlipbook(JumpInAirAnimation);
}
// Falling
if(IsFalling)
{
GetSprite()->SetFlipbook(JumpFallingAnimation);
}
Did I have mistakes or logic problem? Can somebody give me some tips for coding. Thx first.
By the way, the resource I used were downloaded from website, these were extracted from other games, I just used it to learn and find some fun.