diff options
| author | Loic Guegan <manzerbredes@mailbox.org> | 2022-12-29 11:52:24 +0100 |
|---|---|---|
| committer | Loic Guegan <manzerbredes@mailbox.org> | 2022-12-29 11:52:24 +0100 |
| commit | 756c888145f4c1046b25cad062af11c13596d50e (patch) | |
| tree | 86b2a3ff1f0a30e61314470cd1aacce5204b9e57 /src/game_tab | |
| parent | 3efabf1c331bef94d27e2818ab734a02dc401dfe (diff) | |
Improve animation consistency
Diffstat (limited to 'src/game_tab')
| -rw-r--r-- | src/game_tab/left_panel/board/BoardCanvas.cpp | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/src/game_tab/left_panel/board/BoardCanvas.cpp b/src/game_tab/left_panel/board/BoardCanvas.cpp index ad6ba65..58c3fd6 100644 --- a/src/game_tab/left_panel/board/BoardCanvas.cpp +++ b/src/game_tab/left_panel/board/BoardCanvas.cpp @@ -17,7 +17,7 @@ BoardCanvas::BoardCanvas(wxFrame *parent) SetBackgroundStyle(wxBG_STYLE_PAINT); duration=200; duration_fast=100; - fps=180; + fps=30; Bind(wxEVT_KEY_DOWN, &BoardCanvas::OnKeyEvent, this); Bind(wxEVT_KEY_UP, &BoardCanvas::OnKeyEvent, this); @@ -121,9 +121,9 @@ void BoardCanvas::Animate(std::string board, bool is_black_turn, std::map<char, // Now remove the piece that will be moved this->board[pfile + 8 * (7-prank)]=' '; - SetupBoard(this->board,this->is_black_turn,this->captures); - Update(); // Since refresh in SetupBoard is not synchronous, this call wait the end of Refresh() - + wxMemoryDC memDC(*buffer); + DrawBoard(memDC); + // Now compute piece start position and translation vector (Copy paste from DrawBoard()) std::uint32_t piece_width = t->GetPiecesSizes(); std::uint32_t centrer_offset = (square_width - piece_width) / 2; @@ -153,10 +153,16 @@ void BoardCanvas::Animate(std::string board, bool is_black_turn, std::map<char, duration=faster ? duration_fast : duration; frame=0; int frames=duration/(1000/fps); // total number of frames + int time_per_frame=duration/frames; + wxStopWatch sw; for(int i=frames;i>0;i--){ Refresh(); Update(); - wxMilliSleep((1000/(fps*2))); + int delay=sw.Time()-time_per_frame; + if(delay>10){ + wxMilliSleep(delay); + } + sw.Start(0); } duration=faster ? duration_backup : duration_backup; reuseBuffer=false; |
