• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
ankhd

Having Trouble Detecting The End Of A Animation

3 posts in this topic

Hi All.
I would like to have my update Animation function return true when the animation is at the end.
I have in my animation update function where it detects the last frame time, It was working on a larger animation
but I am trying it on a animation that has 30 frames and its max time is 4800(last frame time).

I steped through the code and my frame delta time value passed into this function is like 3200000 thats a big number

if I loop the animation it runs fine. even with this larg time value, Another thing if I break the code before the update animation function
the frame delta is 103.1 so some where in passing and entering the function funky stuff is happening. I thought it came from passing a float to a windows FLOAT
So I changed the FLOATS to float but the same thing.????

Maybe its because my animation time is a DWORD and my timer class is a double casted to a float for time deleta. What should I do here????

Ok heres some code the first is the UpDateAnimation function and the next is the timer class I'm using.


void AnimationCollection::Update(char *AnimationSetName,     
                                  DWORD Time, BOOL Loop, BOOL *atend)
{
  cAnimationSet *AnimSet = m_AnimationSets;

  //set atend to false;
  if(atend)//if its being used
*atend = false;

  // Look for matching animation set name if used
  if(AnimationSetName) 
 {

   // Find matching animation set name
   while(AnimSet != NULL) 
   {

    // Break when match found
    if(!_stricmp(AnimSet->m_Name.c_str(), AnimationSetName))
       break;

   // Go to next animation set object
   AnimSet = AnimSet->m_Next;
  }
}

  // Return no set found
  if(AnimSet == NULL)
    return;

  // Bounds time to animation length
  if(Time >= AnimSet->m_Length)
  {
//if atend is not null we can see if we are looping if we are then we dont get to the end
//but if loop = false we set it to true
 if(atend)
 {
   if(Loop)
     *atend = FALSE;
   else
     *atend = TRUE;
}
Time = (Loop==TRUE)?Time%(AnimSet->m_Length+1):AnimSet->m_Length;
  }

timer class

class GameTimer
{
public:
	GameTimer(void);

	float getGameTime(void)const;  // in seconds
	float getDeltaTime(void)const; // in seconds

	void reset(void); // Call before message loop.
	void start(void); // Call when unpaused.
	void stop(void);  // Call when paused.
	void tick(void);  // Call every frame.

private:
	double mSecondsPerCount;
	double mDeltaTime;

	__int64 mBaseTime;
	__int64 mPausedTime;
	__int64 mStopTime;
	__int64 mPrevTime;
	__int64 mCurrTime;

	bool mStopped;
};



float GameTimer::getDeltaTime(void)const
{
	return (float)mDeltaTime;
}




void GameTimer::tick(void)
{
	if( mStopped )
	{
		mDeltaTime = 0.0;
		return;
	}

	__int64 currTime;
	QueryPerformanceCounter((LARGE_INTEGER*)&currTime);
	mCurrTime = currTime;

	// Time difference between this frame and the previous.
	mDeltaTime = (mCurrTime - mPrevTime)*mSecondsPerCount;

	// Prepare for next frame.
	mPrevTime = mCurrTime;

	// Force nonnegative.  The DXSDK's CDXUTTimer mentions that if the 
	// processor goes into a power save mode or we get shuffled to another
	// processor, then mDeltaTime can be negative.
	if(mDeltaTime < 0.0)
	{
		mDeltaTime = 0.0;
	}
}
0

Share this post


Link to post
Share on other sites

First: unless you intentionally want very large delta-times after you pause/un-pause the app, always update the current and previous times. Just set mDeltaTime = 0 when your app is paused after you've calculated mDeltaTime. Your code as posted will result in large deltas after a pause.

 

Second: when you're debugging (i.e., setting breakpoints), the clock will continue to run while you're staring at your code. While you're debugging, set mDeltaTime to a fixed value (something like 0.01667 - 60th of second). Then, when you want to run "live" (with the First suggestion above implemented), try things out with a "live" delta time.

 

EDIT: That is, your comment

// Time difference between this frame and the previous.

should read:

// Time difference since the last time the app was not in a stopped condition. May be 100s of seconds.
Edited by Buckeye
1

Share this post


Link to post
Share on other sites

Hey thanks.

 

What I have worked out is the elapsed time is ok for a looping animation as the time gets lapped to start frame.

But for a animation that you want to run once I need to keep the start time and use this time to calculate the frame like this.

I'm also now using timeGetTime() it should be more then enough for animation hey.??? as my Animation class uses DWORD for time anyway.

 

after 8 years this is the firts time i've wanted or needed a animation to play once lol hehehe.

I noraly just not animate them and only animate them when needed.

 

static DWORD StartTime = timeGetTime();//this was my test. StartTime is now part of the object

DWORD elapsed = (timeGetTime() - StartTime) *10;//the 10 speeds it up some

 

then when I want to play the animation again I set StartTime = timeGetTime(); and a flag that triggers the render to render the animation or its not called.

 

What I'm using it for is my SpearOfObjectPlacement it allows the user to place objects from the menu to the terrain with a left click.

this is where I play the the animation on the leftclick, then the spear raises a bit and slams into the terrain with some effects(next part) when the last frame is played.

 

Thanks Again All.

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0