平台游戏:屏幕上移动方法不工作方法、工作、屏幕上、平台

2023-09-08 15:02:31 作者:thorns(荆棘)

下面是我没有VCAM或任何其他屏幕上移动方法Flash游戏: http://www.swfcabin.com/open/1389129611 我用hitTestPoint方法来处理我的碰撞。然而,当我尝试添加一个VCAM这是结果: http://www.swfcabin.com/open/1389130109 是不是怪还是什么?在code口用于VCAM是:

Here is my flash game without a vcam or any other screen movement methods: http://www.swfcabin.com/open/1389129611 I used the hitTestPoint method to handle my collisions. However, when I tried adding a vcam this was the result: http://www.swfcabin.com/open/1389130109 Is that strange or what? The code I used for the vcam was:

stage.addEventListener(Event.ENTER_FRAME,update_vcam);
function update_vcam(e:Event){
    vcam.x=char.x;
    vcam.y=char.y;
}

的VCAM的demensions是完全一样的阶段(并且也完全对准的阶段)。我用Jazza的虚拟摄像头。我也试过很多其他vcams,但每一个被证明是因为搞砸了。我用vcams所有的时间早在AS2天,他们一直工作。这不是我试过的唯一方法。我还试图移动的字符的地面来代替。这里的结果: http://www.swfcabin.com/open/1389130683 我完全不知道发生了什么事。任何想法?

The vcam's demensions are exactly the same as the stage(and are also perfectly aligned to the stage). I used "Jazza's" virtual camera. I've also tried many other vcams, but each one proves to be as messed up. I used to use vcams all the time back in the as2 days, and they always worked. This is not the only method I've tried. I also tried moving the ground instead of the character. Here's the result: http://www.swfcabin.com/open/1389130683 I have absolutely no idea what's going on. Any ideas?

德雷克Swartzy

Drake Swartzy

推荐答案

我不知道是什么VCAM是的,但建立一个摄像头其实是非常简单的。所有你需要做的是把所有的游戏对象的容器中,并抵消基础上,照相机的立场,即容器。

I'm not sure what vcam is, but setting up a camera is actually really simple. All you need to do is have all of your game objects in a container, and offset that container based on the 'camera' position.

例如,你把所有的游戏中的对象雪碧全球。在这精灵,你有另一个名为对象字符。你需要从这里做的是设置 X 全球来的负位置的字符

For example, you have all of your game objects in a Sprite named world. Within that sprite you have another object called char. What you need to do from here is set the x and y of the world to the negative position of the char, plus half of the screen size to center the char:

// A 'Camera' is really just a Point within the world we want to center on
// the screen.
var camera:Point = new Point();

// Set the camera coordinates to the char coordinates.
camera.x = char.x;
camera.y = char.y;

// Adjust the world position on the screen based on the camera position.
world.x = -camera.x + (stage.stageWidth / 2);
world.y = -camera.y + (stage.stageHeight / 2);

这可以被制作成一个简单的摄像头类型类像这样:

This could be made into a simple camera type class like so:

public class Camera2D
{

    private var _position:Point;
    private var _world:Sprite;
    private var _stage:Stage;


    public function Camera2D(world:Sprite, stage:Stage)
    {
        _position = new Point();
        _world = world;
        _stage = stage;
    }


    public function set x(value:Number):void
    {
        _position.x = value;
        _world.x = -_position.x + (_stage.stageWidth / 2);
    }


    public function set y(value:Number):void
    {
        _position.y = value;
        _world.y = -_position.y + (_stage.stageHeight / 2);
    }


    public function get x():Number{ return _position.x; }
    public function get y():Number{ return _position.y; }

}

和等来实现:

var camera:Camera2D = new Camera2D(world, stage);
camera.x = char.x;
camera.y = char.y;