For my latest game, I decided to use the new CGapiApplication class since it took care of many of the event handling routines (e.g., StylusDown, etc).
The problem is, I get screen flickers when I try to animate a graphic outside of the ProcessNextFrame() loop. I know I'm not supposed to loop outside of this routine, however, there are times where this is very useful.. for example, imagine a grid based game.. if you want to animate the movement of one play piece from one grid spot to another (with no user control in between) I would loop within a single ProcessNextFrame() call and Flip() the display myself during this loop. I did with my previous game and it worked fine.. however, when using CGapiApplication, I cannot figure out how to stop ProcessNextFrame() from trying to flip the display itself during my loop.
Anyone (Johan?) know how I can flip the display in a loop without ProcessNextFrame() thread executing its own flips? Is the Pause() method for this ?? I tried it breifly, but it still flickered on me.
Any ideas?
-Jeff
Disregard my previous message.. I solved the problem by modifying the CGapiApplication source code that was provided. I inserted a check inside the ThreadFunc() method at the conditition where the surface Flip occurs. I check to see if a global flag is true or false.. this flag regulates when I want control of the flipping and prevents CGapiApplication from calling flip when I want a controlled animation outside of the ProcessNextFrame() method.
I find this very useful when doing short, controlled animations (flipping). I know it breaks the paradigm set up by the class, but in the end, its easier than coding the more difficult tracking of short animations.
Actually, it would be useful to have this 'bypass' capability in future versions of GapiDraw perhaps. I would imagine others would find it very useful.
-Jeff
I came across the same issue with ProcessNextFrame() that you did. My solution was to rethink how I was doing my animation loop and set it up so it all worked within the CGapiApplication framework. The result was a much cleaner design and a constant framerate. Each of my object classes has a draw method which is processed hierarchically from within the ProcessNextFrame() method. This makes the code much easier to maintain and a hell of alot easier to debug. Just my 2 pennies worth. :)
-- GR
I used a similar technique for most of my game structure. That is, used base classes that had virtual draw(), update(), etc and were implemented in the derived classes. It sill made it tricky to deal with because I had many cases where I wanted a very scripted set of processing that did not easily fit within the overall 'update, plot' paradigm. Anyhow, good to know someone else gave thought to this :)
I am doing the exact same thing that you are trying to do in my grid based game. My solution was to have the ProcessNextFrame method call the Animate() routine which updates the data members depending of the state of the object. For example, suppose my Man is to move from one grid to another and the move requires 5 steps. I would call a Move() on my Man object that sets up the appropriates flags and counters so that the next time Animate() is called on it, it will animate/move the image one position and update the counter. Animate() will end the move cycle when the end of the counter (5 iterations) is reached. So when the ProcessNextFrame is called, it will call Animate() on the Man, which in turn will update the position and image of the man as necessary. Now ProcessNextFrame can call the Draw() on the Man to display the correct image at the correct position. The effect is that while the Man is in the Move mode, it will move from one grid cell to another in 5 steps, independent of user interaction. Note that a redraw is done only once per call to ProcessNextFrame, eliminating the flickering. You can also have Animate called by timer if you want the fully seperate the display and logic methods. I'm sure there are many ways of doing this but this is what works for me. Hope that helps.
The proper way of creating a game with many animations is to separate the data layer from the display layer. You modify the data with your code and the ProcessNextFrame should read the current state of your data and display it. For instance, suppose you have 3 enemies that have animations of 3, 8 and 11 frames. In your main program loop, you would just have each enemy advance to the next frame. For my game, I have a Game loop that is independant of the drawing loop.