Skip to content

Commit

Permalink
Using custom property and fixing issue with blend mode.
Browse files Browse the repository at this point in the history
  • Loading branch information
luigi-rosso committed Feb 23, 2017
1 parent 41dd9ad commit b3bf7b3
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 3 deletions.
Binary file modified Assets/Archer.nima
Binary file not shown.
18 changes: 17 additions & 1 deletion Source/ArcherController.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "ArcherController.hpp"
#include <nima/ActorEvent.hpp>
#include <nima/CustomProperty.hpp>
#include <cmath>

ArcherController::ArcherController() :
Expand All @@ -8,6 +9,7 @@ ArcherController::ArcherController() :
m_Walk(nullptr),
m_Run(nullptr),
m_WalkToIdle(nullptr),
m_GroundSpeedProperty(nullptr),
m_AimAnimationTime(0.0f),
m_IdleTime(0.0f),
m_WalkToIdleTime(0.0f),
Expand Down Expand Up @@ -40,9 +42,17 @@ void ArcherController::onAdded(nima::GameActorInstance* actorInstance)
m_Run = actorInstance->animation("Run");
m_WalkToIdle = actorInstance->animation("WalkToIdle");

nima::ActorNode* characterNode = actorInstance->component<nima::ActorNode*>("Character");
if(characterNode != nullptr)
{
m_GroundSpeedProperty = characterNode->getCustomFloatProperty("GroundSpeed");
}

if(m_Aim != nullptr)
{
nima::ActorNode* muzzle = actorInstance->component<nima::ActorNode*>("Muzzle");

//
if(muzzle != nullptr)
{
for(int i = 0; i < AimSliceCount; i++)
Expand Down Expand Up @@ -170,7 +180,13 @@ void ArcherController::advance(nima::GameActorInstance* actorInstance, float ela
}

float moveSpeed = m_IsRunning ? 1100.0f : 600.0f;
root->x(root->x() + m_HorizontalSpeed * elapsedSeconds * moveSpeed);
float speedModifier = 1.0f;
if(m_GroundSpeedProperty != nullptr)
{
speedModifier = (m_IsRunning ? 1.0f - m_GroundSpeedProperty->value() : m_GroundSpeedProperty->value())*0.5f+0.5f;
}

root->x(root->x() + m_HorizontalSpeed * elapsedSeconds * moveSpeed * speedModifier);
if(m_Walk != nullptr && m_Run != nullptr)
{
if(m_HorizontalSpeed == 0.0f && m_WalkMix == 0.0f && m_RunMix == 0.0f)
Expand Down
1 change: 1 addition & 0 deletions Source/ArcherController.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class ArcherController : public nima::GameActorController
nima::ActorAnimationInstance* m_Walk;
nima::ActorAnimation* m_Run;
nima::ActorAnimation* m_WalkToIdle;
nima::CustomFloatProperty* m_GroundSpeedProperty;
float m_AimAnimationTime;
float m_IdleTime;
float m_WalkToIdleTime;
Expand Down
5 changes: 4 additions & 1 deletion Source/Graphics/OpenGL/GLRenderer2D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,11 @@ BlendMode GLRenderer2D::blendMode() const

void GLRenderer2D::setBlendMode(BlendMode mode)
{
if(m_BlendMode == mode)
{
return;
}
m_BlendMode = mode;
m_BlendMode = BlendMode::Normal;
switch (m_BlendMode)
{
case BlendMode::Off:
Expand Down

0 comments on commit b3bf7b3

Please sign in to comment.