本文介绍了如何管理摄像头移动到游戏角色顺利?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做游戏采用了android libgdx我的要求是,当角色玩游戏normaly那么我们作为

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;

但是,如果获得一些权力,然后需要的是我们顺利increese字符y位置为此,我指定为

But in case getting some power then need is that we smoothly increese y-position of characterfor 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是一个巨大的矩形,它定义了摄像机的运动极限,所以你可能会忽略的那部分,如果它不利于你的情况

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

这篇关于如何管理摄像头移动到游戏角色顺利?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-05 15:51