在我的游戏中,我有一个头文件,其中包含游戏中季节的属性和函数。这些属性都是静态的,包括一个表示当前季节的浮点数和另一个表示季节之间转换的当前点的浮点数,如果不转换则为零。
在我的游戏中,有几个功能依赖于过渡(此时有两个),其中一个运行良好。虽然,在另一种情况下,这根本不起作用。
在负责控制我的游戏背景的类中,每当引用“SeasonTransition”变量时,它就为零。但是在另一个类中,变量以完全相同的方式引用,它得到了真正的值。
这是游戏可以更新几帧后调用断点后的图片:
这些变量再次在 ac 头文件中声明:
#import "somestuff.h"
static float SeasonTransition
etc...
这不应该这样做吗?我该如何解决这个问题?
编辑:
Season.h 文件如下:
//GL.h contains different functions and global variables to be used anywhere in the project.
//This file, like Season.h is a singular header file with static declarations, and is setup
//the same way. I have been developing this from the start of the project and havent had any
//problems with it.
#import "GL.h"
static float currentSeason;
static float SeasonTransition;
static void UpdateSeason(){
currentSeason += 0.0002f;
float TransitionLength = 0.15f;
float SeasonDepth = Clamp(currentSeason - floorf(currentSeason), 0, TransitionLength);
float bigTL = TransitionLength / 4;
float endTL = TransitionLength;
float Speed2 = 0;
float Speed1 = 1;
float bRatio = SeasonDepth / bigTL;
float eRatio = SeasonDepth / endTL;
SeasonTransition = (SeasonDepth < TransitionLength) ?
((SeasonDepth < bigTL) ?
(Speed1 * bRatio) + (Speed2 * (1.0f - bRatio)) :
(Speed1 * (1.0f - eRatio)) + (Speed2 * eRatio))
:
Speed2;
}