my animation is not working?

Started by
8 comments, last by 3pic_F4il_FTW 8 years, 12 months ago

hello.
iam trying to animate a small sprite sheet but when i run it all i get is the first image on the sheet as a still image.
here is the code for my update function:
http://pastebin.com/U5G42Ctm

and here is some of the code that i use it in:

http://pastebin.com/tfxDeBpH

is there anything iam doing wrong?

heres the project if needed closer look.
https://drive.google.com/file/d/0By7ww7H1L1aeYzhlbnZRdzFmeTQ/view?usp=sharing

Advertisement

Hi,

1) just as a sidenote: your member variable m_FramesPerSecond has the unit [time/frames] and should hence be named m_SecondsPerFrame.

2) Where do you update the Timer class? Maybe I overlooked it but I couldnt find a call to its Update function in your code resulting in GetDeltaTime() always returning 0.0f

Hi,

1) just as a sidenote: your member variable m_FramesPerSecond has the unit [time/frames] and should hence be named m_SecondsPerFrame.

2) Where do you update the Timer class? Maybe I overlooked it but I couldnt find a call to its Update function in your code resulting in GetDeltaTime() always returning 0.0f

ok i looked at this function:


float Timer::GetDeltaTime()
{
	float dt = m_deltaTime;
	if (dt < 0.0f || dt > 1.0f)
	{
		dt = 0.025;
	}

	return dt;
}

and i changed the less than and greater than symbols to:(swaped them around)


float Timer::GetDeltaTime()
{
	float dt = m_deltaTime;
	if (dt > 0.0f || dt < 1.0f)
	{
		dt = 0.025;
	}

	return dt;
}

and all i got was the frames animating but i could see all of the frames at once just flickering extremely fast.

I think you got that one wrong.. I didnt mean that you should switch the operators , they were not the problem (although I dont really think that the boundchecking should go into the Timer class)

What I meant was that you have to update the m_DeltaTime variable which is 0.0f by default. In order to do so you have to call Timer::Update() every gametick.

Currently your Engine class is not doing so resulting in m_DeltaTime staying 0.0f and Timer::GetDeltaTime() always returning 0.0f.

Your change in the GetDeltaTime() function causes it to always return 0.025f and thus stepping the counter way too fast, thus the flickering, which obviously isnt the desired behaviour.

ok so i made a pointer to the Timer in engine.h
and i called m_timer->update();


void Engine::Update()
{
	m_sprite->Update();
	m_timer->Update();
}
 

and now iam getting the flickering effect this way.

Well first off you actually dont need a pointer to a Timer instance as you made every member variable and method static. While this probably is not the best way to layout a timer class just calling Timer::Update() will suffice.

2things that could still cause the flicker:
1) you did not undo your changes in GetDeltaTime (the changes you made cause it to return 25ms of elapsed time every tick because every number is greater than 0 or smaller than 1)
2) your animation is running too fast. I cant check it right now but i think the animation youre using has only 3 frames so you should have a look at your FramesPerSecond variable. If you are using 6 fps for example the animation will run twice per second

Btw where did you find this timer code?

alright so i call Timer::Update(); as you said.i lowered the FPS to 6.0f, and now its animating it on each frame.but i have a problem. it doesnt update the image in the same position.for eg it draws the first frame and a few pixels to the right it draws the second and few to the right again it draws the third. how do i make it so that it draws it all in one position.
and for some other sprite sheets i tried now kind of turn messed up(dont know if you know what i mean).
but with the sprite sheet does it need to be evenly spread out?

and i made that timer class similar to one this guy made on youtube.

Yes, if i remember correctly, with your current code each frame has to be the same size and layed out accordingly (cant check on my phone atm)

Edit: And about the messed up sprites: can you post a visual example? Maybe tgeyre just stretched?

yo
i changed the sprite sheet to one that i found online and it animates pretty well. but the alpha blending doesnt work on it for some reason. at least i got it to work thanks to you smile.png

the sheet i was using before is messed up iam pretty sure.

Hi
Im glad that I could help you. If you need further help just send me a message
We will probably be able to fix your sprites as well ;)

This topic is closed to new replies.

Advertisement