AS3:没有尽头的视口
我正在制作一款太空导航游戏。所以它从宇宙飞船上的用户开始,然后当他按下向上键时,飞船就会前进,“地图”总是不同的,我有 5 种不同的恒星和 2 种不同的行星,所以它们基本上是随机“生成”的,而用户进行导航。我可以进行按键检测,影片剪辑生成器代码,但我不知道如何制作导航代码,我的意思是当用户按下按键时如何使视口移动,...我已经看到我不太理解的代码,这家伙基本上创建了一个巨大的影片剪辑,根据按下的键移动。这在我的情况下不起作用,因为我希望它随机生成所有内容,当用户按下向下箭头时,我希望它返回,并使用与之前相同的“地图”。请帮助我,我对所有这些视口的事情感到完全困惑。而且,我希望游戏运行得更快,我对动作脚本有点陌生,我不知道如果渲染未显示的对象,它是否会变得很重,如果是这样,一个简单的“obj”会变得很重吗? .visible = false'有效吗?提前致谢。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我在这里所做的是:
创建一个带有属性
camera
的Map
类,它是另一个自定义类MapCamera
。MapCamera
有五个属性:_x
_y
map
- 对Map
实例的引用code> 拥有此MapCamera
offsetX
offsetY
_x
和_y
属性是私有
,并且具有 getter 和 setter。getter 非常基本:
setter 是视口将被更改的地方,如下所示:
从这里,您将您的子项添加到
Map
容器中,然后可以简单地执行:这将导致玩家始终位于屏幕中央。
What I do here is:
Create a
Map
class with a propertycamera
which is another custom classMapCamera
.The
MapCamera
has five properties:_x
_y
map
- a reference to the instance ofMap
owning thisMapCamera
offsetX
offsetY
_x
and_y
properties areprivate
, and have getters and setters.The getters are pretty basic:
The setters are where the viewport will be altered, like so:
From here, you add your children into the
Map
container and then can simply go:Which will cause the player to always be in the centre of the screen.