Просмотр исходного кода

world: do not wrap frame index

Daniele Bartolini 6 лет назад
Родитель
Сommit
e38d362f47
2 измененных файлов с 4 добавлено и 2 удалено
  1. 1 0
      CHANGELOG.md
  2. 3 2
      src/world/animation_state_machine.cpp

+ 1 - 0
CHANGELOG.md

@@ -12,6 +12,7 @@ Changelog
 * runtime: fixed an issue that prevented kinematic actors to be controlled via the SceneGraph
 * runtime: fixed an issue that prevented PhysicsWorld.actor_center_of_mass() to be called for static actors
 * runtime: fixed an issue that prevented PhysicsWorld.actor_world_{position,rotation,pose}() to be called for static actors
+* runtime: fixed an issue that reset the sprite animation to the beginning even when loop was set to false
 * runtime: fixed an issue where a regular Matrix4x4 was returned if Matrix4x4Box is called without arguments
 * runtime: removed "io" and "os" libraries from Lua API
 * runtime: small fixes and performance improvements

+ 3 - 2
src/world/animation_state_machine.cpp

@@ -187,8 +187,9 @@ void AnimationStateMachine::update(float dt)
 		if (!anim_i.resource)
 			continue;
 
-		const f32 frame_time  = f32(anim_i.num_frames) * (anim_i.time/anim_i.time_total);
-		const u32 frame_index = u32(frame_time) % anim_i.num_frames;
+		const f32 frame_ratio     = anim_i.time / anim_i.time_total;
+		const u32 frame_unclamped = frame_ratio * f32(anim_i.num_frames);
+		const u32 frame_index     = min(frame_unclamped, anim_i.num_frames-1);
 
 		anim_i.time += dt*speed;