Dra*_*ber 0 flash actionscript-3
这是我的flash游戏没有vcam或任何其他屏幕移动方法:http: //www.swfcabin.com/open/1389129611我使用hitTestPoint方法来处理我的碰撞.但是,当我尝试添加一个vcam时,结果是:http://www.swfcabin.com/open/1389130109这有 什么奇怪的吗?我用于vcam的代码是:
stage.addEventListener(Event.ENTER_FRAME,update_vcam);
function update_vcam(e:Event){
vcam.x=char.x;
vcam.y=char.y;
}
Run Code Online (Sandbox Code Playgroud)
vcam的尺寸与舞台完全相同(并且与舞台完全对齐).我使用了"Jazza"的虚拟相机.我也尝试了许多其他的vcams,但每个人都被证明是混乱的.我曾经在as2天里一直使用vcams,他们总是工作.这不是我尝试过的唯一方法.我也试过移动地面而不是角色.结果如下:http: //www.swfcabin.com/open/1389130683 我完全不知道发生了什么.有任何想法吗?
Drake Swartzy
我不确定vcam是什么,但设置相机实际上非常简单.您需要做的就是将所有游戏对象放在容器中,并根据"摄像机"位置偏移该容器.
例如,您将所有游戏对象都Sprite命名为world.在那个精灵中你有另一个叫做的对象char.什么,你需要从这里做的是设置x和y的world来的负向位置char的屏幕尺寸居中,加上一半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);
Run Code Online (Sandbox Code Playgroud)
这可以做成一个简单的相机类型类,如下所示:
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; }
}
Run Code Online (Sandbox Code Playgroud)
并实施如下:
var camera:Camera2D = new Camera2D(world, stage);
camera.x = char.x;
camera.y = char.y;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
979 次 |
| 最近记录: |