2018-06-19 20:05:09 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2018 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2018-08-08 15:36:17 +00:00
|
|
|
#include "Sample.h"
|
2018-10-30 19:08:53 +00:00
|
|
|
|
2019-03-20 16:55:08 +00:00
|
|
|
#include "AnimTimer.h"
|
2018-10-30 19:08:53 +00:00
|
|
|
#include "Resources.h"
|
|
|
|
#include "nima/NimaActor.h"
|
|
|
|
|
2018-06-21 15:24:13 +00:00
|
|
|
#include <nima/Animation/ActorAnimationInstance.hpp>
|
2018-06-19 20:05:09 +00:00
|
|
|
#include <cmath>
|
|
|
|
|
|
|
|
using namespace nima;
|
|
|
|
|
2018-08-08 15:36:17 +00:00
|
|
|
class NimaView : public Sample {
|
2018-06-19 20:05:09 +00:00
|
|
|
public:
|
|
|
|
NimaView()
|
2018-10-30 19:08:53 +00:00
|
|
|
: fActor(nullptr) {
|
2018-06-19 20:05:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2018-08-08 15:36:17 +00:00
|
|
|
virtual bool onQuery(Sample::Event* evt) override {
|
|
|
|
if (Sample::TitleQ(*evt)) {
|
|
|
|
Sample::TitleR(evt, "Nima");
|
2018-06-19 20:05:09 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return this->INHERITED::onQuery(evt);
|
|
|
|
}
|
|
|
|
|
|
|
|
void onOnceBeforeDraw() override {
|
|
|
|
// Create the actor.
|
2018-10-30 19:08:53 +00:00
|
|
|
std::string nimaPath(GetResourcePath("nima/Robot.nima").c_str());
|
|
|
|
std::string texturePath(GetResourcePath("nima/Robot.png").c_str());
|
|
|
|
|
|
|
|
fActor = std::make_unique<NimaActor>(nimaPath, texturePath);
|
2018-06-19 20:05:09 +00:00
|
|
|
|
2018-10-30 19:08:53 +00:00
|
|
|
// Also available: dance, jump, idle
|
|
|
|
fActor->setAnimation("attack");
|
2018-06-19 20:05:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void onDrawContent(SkCanvas* canvas) override {
|
|
|
|
canvas->save();
|
|
|
|
|
2018-10-30 19:08:53 +00:00
|
|
|
canvas->translate(500, 700);
|
2018-06-19 20:05:09 +00:00
|
|
|
canvas->scale(1, -1);
|
|
|
|
|
|
|
|
// Render the actor.
|
|
|
|
fActor->render(canvas);
|
|
|
|
|
|
|
|
canvas->restore();
|
|
|
|
}
|
|
|
|
|
2019-03-20 16:55:08 +00:00
|
|
|
bool onAnimate(const AnimTimer& timer) override {
|
2018-10-30 19:08:53 +00:00
|
|
|
if (fActor) {
|
|
|
|
float time = std::fmod(timer.secs(), fActor->duration());
|
|
|
|
fActor->seek(time);
|
2018-06-19 20:05:09 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2018-10-30 19:08:53 +00:00
|
|
|
std::unique_ptr<NimaActor> fActor;
|
2018-06-19 20:05:09 +00:00
|
|
|
|
2018-08-08 15:36:17 +00:00
|
|
|
typedef Sample INHERITED;
|
2018-06-19 20:05:09 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2018-08-08 15:36:17 +00:00
|
|
|
DEF_SAMPLE( return new NimaView(); )
|