質問

I am making game for android using libgdx my requirement is that when character play game normaly then we work as

         if velocity == normal(==25) 
        cam.position.y = character.position.y;

But in case getting some power then need is that we smoothly increese y-position of character for that I assign as

             if when velocity >25(means get power)
           cam.position.y = character.position.y-screenHieght/3;  

it is working but character is not move smoothly move with jerk and no real effect is comming. Please anyone help me how I can solve this problem?

役に立ちましたか?

解決

After giving a second read to your question I think you are asking how to smoothly update your camera regardless of the speed the player is moving at.

Here's how i update my camera :

     protected void updateCamera() {
        float tX = cameraObjective.pos.x - cam.position.x;
        float tY = cameraObjective.pos.y - cam.position.y;
        float newX = cam.position.x + tX;
        float newY = cam.position.y + tY;
        if ( newX < camBounds.x || newX > camBounds.x + camBounds.width ){
            tX = 0;
        }
        if ( newY < camBounds.y  - camBounds.height || newY > camBounds.y  ){
            tY = 0;
        }
        cam.translate(tX, tY, 0);
    }

cambounds is a huge rectangle which defines the camera's movement limits, so you might omit that part if it's not helpful for your case

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top