Reputation: 621
I am making game in libgdx. I want to show tutorials on game start and disappear after few seconds.My code is given below
public class HeroCar{
static final int TUTE_STATE_SHOW = 0;
static final int TUTE_STATE_HIDE = 1;
int tuteState;
float tuteStateTime = 0;
public HeroCar()
{
tuteState = TUTE_STATE_SHOW;
}
public void update(float deltaTime){
if(tuteStateTime >= 0.56f){
tuteStateTime = 0;
tuteState = TUTE_STATE_HIDE;
}
else{
tuteState = TUTE_STATE_SHOW;
}
tuteStateTime += deltaTime;
}
and in game play screen class render method my code is
if(world.heroCar.tuteState == HeroCar.TUTE_STATE_SHOW){
spriteBatch.draw(Assets.speedingup_region, 480 / 2 - 172 / 2, 400, 172, 30);
}
}
Upvotes: 0
Views: 137
Reputation: 1149
If you are saying about alpha of texture then may be this could help. make
Sprite sprite = new Sprite(Assets.speeding_upregion);
in constuctor. and in render cyle
float step = 0;
float speed = 5;
float alpha = 0;
step = alpha > .9f ? -speed : alpha < .1f ? speed : step; alpha += step * deltaTime;
sprite.draw(spritebatch, alpha);
add your condition before draw if you want to draw or not.
Upvotes: 0
Reputation: 2305
Or can can just use Car distance
if(herocar.position.x<50&&canShowTute)
{
fon.draw(batcher,string,posx,posy);
}
else if(herocar.position.x>50&&canShowTute)
{
canShowTute=false;
}
This way u dont have to manage a variable for statetime
Also if car crosses a ceratain distance than manage that no further need to show tute next time.
Upvotes: 1
Reputation: 1149
if(tuteStateTime >= 0.56f){
tuteStateTime = 0; //--------------wrong
tuteState = TUTE_STATE_HIDE;
}
donot set
tuteStateTime = 0
because if you set it 0 then in the next cycle it will check time > 0.56f , then it goes to else block and set state = show...... Hence your tutorial will never dissappear. it will always remain in show state.
Upvotes: 0