AS3:视口没有结束 [英] AS3: Viewports without an end

查看:193
本文介绍了AS3:视口没有结束的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在做一个太空航行的游戏。因此,它开始对飞船的用户,然后当他preSS向上键船前进,在地图始终是不同的,我已经分5变化和行星2的变化,所以他们基本上'重生随机而用户导航。我可以做的关键检测,影片剪辑发电机code,但我不知道我怎么做导航code,我的意思是如何让我的视口移动,当用户preSS的关键的,......我看到了一个code,我不明白非常清楚,这家伙基本上建立了一个巨大的影片剪辑,根据这是pressed的关键动作。这不会在我的情况下工作,因为我希望它随机生成的一切,当用户preSS的向下箭头,我希望它回去,用相同的地图,他是前。请帮我出人,我完全糊涂了这一切视事情。还有,我希望游戏跑得快,我有点新的动作脚本,我不知道,如果它变得沉重,如果你在渲染正在显示的不是对象,如果是的话会简单的OBJ 。可见=假'工作?提前致谢。

I'm making a space navigation game. So it starts with the user on the spaceship and then when he press the up key the ship goes forward, the 'map' is always different, I have 5 variations of stars and 2 variations of planets, so they basically 'spawn' randomly while the user navigates. I can make the key detection, the movie clips generator code, but I don't know how do I make the navigation code, I mean how do I make the viewport move when the user press the key, ... I've saw a code that I didn't understand too well that the guy basically created a giant movie clip that moves according to the key that was pressed. That won't work in my case because I want it to generate everything randomly and when the user press the down arrow, I want it to go back, with the same 'map' that he was before. Please help me out guys I'm totally confused with all this viewport thing. And also, I want the game to run fast, I'm kind of new to the Action Script, and I don't know if it gets heavy if you are rendering objects that are not being displayed, if so will a simple 'obj.visible = false' works? Thanks in advance.

推荐答案

我在这里做的是:

与属性相机这是另一个自定义类创建一个地图 MapCamera

Create a Map class with a property camera which is another custom class MapCamera.

MapCamera 有五个属性:

  1. _x
  2. _y
  3. 地图 - 引用地图拥有的实例,这个 MapCamera
  4. offsetX
  5. offsetY

  1. _x
  2. _y
  3. map - a reference to the instance of Map owning this MapCamera
  4. offsetX
  5. offsetY

  • 偏移值重新present x和y间隔从屏幕的左侧和顶部边缘,其应被设置为一半的阶段宽度和高度,使得摄像机将正确居中在舞台上。
  • _x _y 属性私人,并有getter和setter方法​​。
  • The offset values represent the x and y spacing from the left and top edges of the screen, which should be set to half of the stage width and height so that the camera will centre on the stage correctly.
  • The _x and _y properties are private, and have getters and setters.

的干将是pretty的基础:

The getters are pretty basic:

public function get x():Number{ return _x; }
public function get y():Number{ return _y; }

的制定者是在哪里视将被改变,像这样:

The setters are where the viewport will be altered, like so:

public function set x(n:Number):void
{
    _x = n;
    map.x = -(_x + offsetX);
}

public function set y(n:Number):void
{
    _y = n;
    map.y = -(_y + offsetY);
}

在这里,您可以添加你的孩子到地图容器中,然后可以简单地去:

From here, you add your children into the Map container and then can simply go:

map.camera.x = player.x;
map.camera.y = player.y;

这将导致播放器总是在屏幕的中心。

Which will cause the player to always be in the centre of the screen.

这篇关于AS3:视口没有结束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆