Archived

This topic is now archived and is closed to further replies.

help, newbie problems attack

This topic is 5117 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

ive been tyring animation in Win32(a sequence of bitmaps) but every time i try more then one at a time(lets say two) but then i only get one bitmap displayed and its not even animated. here is the function i used: void Animate(int x, int y, int wid, int hgt, int state, HBITMAP bmp, SDBuffer buff, HDC img, int wait, int count, UINT color) { if(wait < count) { wait += 1; } if(wait >= count) { SelectObject(img,bmp); TransparentBlt(buff.back_dc,x,y,wid,hgt,img,0,0,wid,hgt,color); state += 1; wait = 0; } if(state > 5) { state = 1; } | // states are put in by 1 being first state, 2 second state, and so on to five. basically all it does is go up and down (or did) See anything wrong??? is my code bad??? any suggestions as to how you might do simultaenious animations??? Thanks in Advance

Share this post


Link to post
Share on other sites
I am assuming that the state variable controls what frame of animation is being shown, and you are changing the values of x and y somewhere else. If you pass state into your function by value and then increment it there, when Animate() returns the state variable will be unchanged. If you pass it by reference you can change it outside the scope of the Animate() function. Same thing goes for the wait variable.

Share this post


Link to post
Share on other sites
<< If you pass it by reference you can change it outside the scope of the Animate() function. Same thing goes for the wait variable. >>

That's probably it. Another solution is to use global variables for state, wait, count (anything you pass to the function), meaning you declare them at the top of your program before any functions. Makes things a lot easier with globals since you don't have to pass to functions anything declared global. So any global variables changed inside Animate function will remain changed.

You have to be careful with globals though and give them very unique names to make sure they don't get changed except when you want them to...Andre Lamothe suggests using globals to improve speed as well.

Phil P

[edited by - PhilVaz on December 13, 2003 7:11:51 PM]

Share this post


Link to post
Share on other sites