保存代码
This commit is contained in:
+16
-2
@@ -1322,7 +1322,19 @@ void FaceApp::drawFrame(long long frameTime)
|
||||
_curTexIndex++;
|
||||
if (_curTexIndex >= _curMotion_png_size)
|
||||
{
|
||||
_curTexIndex = 0;
|
||||
if(_animationFinishedCallback != nullptr)
|
||||
{
|
||||
_animationFinishedCallback();
|
||||
}
|
||||
|
||||
if (_animationLoop)
|
||||
{
|
||||
_curTexIndex = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
_curTexIndex = _curMotion_png_size - 1;
|
||||
}
|
||||
}
|
||||
game_time = game_time - actionTime;
|
||||
}
|
||||
@@ -1357,7 +1369,7 @@ string FaceApp::preReadyMotion(const std::string& json, Callback callback)
|
||||
return "failure";
|
||||
}
|
||||
|
||||
void FaceApp::changeMotion(const string motion_type)
|
||||
void FaceApp::changeMotion(const string motion_type, AnimationFinishedCallback callback, bool loop)
|
||||
{
|
||||
if (_curMotion_type == motion_type)
|
||||
{
|
||||
@@ -1387,6 +1399,8 @@ void FaceApp::changeMotion(const string motion_type)
|
||||
_curMotion_type = motion_type;
|
||||
_curMotion_png_size = _nextMotion.png_names.size();
|
||||
_motionState = ready;
|
||||
_animationFinishedCallback = callback;
|
||||
_animationLoop = loop;
|
||||
|
||||
|
||||
// for (int i = 0; i < _curMotion.png_names.size(); ++i)
|
||||
|
||||
+4
-1
@@ -35,6 +35,7 @@ struct PushConstants {
|
||||
};
|
||||
|
||||
using Callback = std::function<void(const std::string&)>;
|
||||
using AnimationFinishedCallback = std::function<void()>;
|
||||
|
||||
class FaceApp :public Application
|
||||
{
|
||||
@@ -139,8 +140,10 @@ private:
|
||||
|
||||
public:
|
||||
Callback _callback;
|
||||
AnimationFinishedCallback _animationFinishedCallback;
|
||||
bool _animationLoop = true;
|
||||
string preReadyMotion(const std::string& json, Callback callback);
|
||||
void changeMotion(const string motion_type);
|
||||
void changeMotion(const string motion_type, AnimationFinishedCallback callback, bool loop);
|
||||
//void changeMotion(Motion& motion);
|
||||
InitArg _initArg;
|
||||
//Motion _curMotion;
|
||||
|
||||
+8
-1
@@ -41,11 +41,18 @@ std::wstring ReadFileWithChinesePath(const std::wstring& filePath) {
|
||||
|
||||
FaceApp* g_app;
|
||||
|
||||
|
||||
void CppAnimationFinishedCallback()
|
||||
{
|
||||
std::cout << "call CppAnimationFinishedCallback\n";
|
||||
}
|
||||
|
||||
void CppCallback(const string& motion_type)
|
||||
{
|
||||
g_app->changeMotion(motion_type.c_str());
|
||||
g_app->changeMotion(motion_type.c_str(), CppAnimationFinishedCallback, true);
|
||||
}
|
||||
|
||||
|
||||
int main() {
|
||||
|
||||
//std::string path = "chinese.txt";
|
||||
|
||||
Reference in New Issue
Block a user