c++ - Use and over use of static variables -
is recommended use static variables ever comfortable with?
because tend use more now. there thing using static variables bad practice or fill memory quickly?
currently doing small games c++. maintain states jump position , animation time have use static variables in function , function called multiple times in loop. static variables job. there oo patterns on problem?
void jumpit(){ static int jump ; if( !jump && pressed) jump=1; if (jump) obj.y++; }
and in loop call job done..do have better idea same??
your "obj" keep track of own state.
a free standing jumpit function implemented as:
void jumpit(object& obj, bool pressed) { if( !obj.jump && pressed) obj.jump = true; if (obj.jump) obj.y++; }
or might better implement jumpit part of "object"
it never idea keep state in function.
Comments
Post a Comment