我的精灵不会显示,我正在 as3 上做一个侧滚轮 [英] My sprite will not display, I am making a side scroller on as3

查看:34
本文介绍了我的精灵不会显示,我正在 as3 上做一个侧滚轮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一个游戏,我的火箭飞船必须避开小行星.但是,我的火箭飞船精灵不会显示.任何帮助表示赞赏.

I am making a game where my rocket ship has to avoid asteroids. However, my rocket ship sprite will not display. Any helps is appreciated.

          var myRocket:MovieClip;
          addChild(myRocket);
          myRocket.addEventListener(KeyboardEvent.KEY_DOWN, keyDown);
          myRocket.addEventListener(KeyboardEvent.KEY_UP, keyUp);
          myRocket.x=200;
          myRocket.y=150;

推荐答案

好的,这就是您从 Library 实例化事物的方式.

Ok, that's how you instantiate things from Library.

首先,Library 对象必须有一个 AS3 类.您可以在 Library 对象的属性中分配它.假设类名是 SpaceRocket.

First, the Library object must have an AS3 class. You assign it in the Library object's properties. Let's say the class name is SpaceRocket.

然后您执行以下操作:

// Instantiate the object by its class.
var rocket:SpaceRocket = new SpaceRocket;

// Assign coordinates.
rocket.x = 200;
rocket.y = 150;

// Add the instance to the display list.
addChild(rocket);

另外,我不建议为键盘事件监听火箭.这意味着火箭应该有键盘焦点,这很容易丢失.你应该在阶段听它,因为所有的键盘事件最终都会发生:

Also, I don't recommend listening the rocket for the keyboard events. It means the rocket should have the keyboard focus, which can be lost quite easily. You should rather listen it at the stage because all the keyboard events go there eventually:

stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDown);
stage.addEventListener(KeyboardEvent.KEY_UP, keyUp);

这篇关于我的精灵不会显示,我正在 as3 上做一个侧滚轮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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