#29199 - identitycrisisuk - Sat Nov 13, 2004 4:42 pm
I've read a few things before about using & (n-1) instead of % n but this is the first time I've had to use it. AFAIK these two code segments should be equivalent:
However, only the first example results in a decrease in speed of the animation that I'm trying to do. The second just makes the character move in Benny Hill vision with the frame of animation appearing to change every frame. There's excessive brackets as I was trying to make sure I knew exactly what I was doing. At least the first way works but I'd like to know why the second isn't as it's nicer and I will probably need it in future.
Code: |
if(Moving()) { if(++m_animCount > 8) { ++m_walkFrame; m_animCount = 0; } if(m_walkFrame > 2) m_walkFrame = 0; m_nextLower = WALK0+m_walkFrame; } if(Moving()) { if((++m_animCount) & (8-1)) { ++m_walkFrame; } if(m_walkFrame > 2) m_walkFrame = 0; m_nextLower = WALK0+m_walkFrame; } |
However, only the first example results in a decrease in speed of the animation that I'm trying to do. The second just makes the character move in Benny Hill vision with the frame of animation appearing to change every frame. There's excessive brackets as I was trying to make sure I knew exactly what I was doing. At least the first way works but I'd like to know why the second isn't as it's nicer and I will probably need it in future.