问题描述
我正在创建简单的flash游戏。我需要改变动画时字符移动。例如,当去,跑,跳,攻击等我有不同的动画。只是我不知道如何正确添加它们?
I'm creating simple flash game. I need to change animations when character moving. For example when going, running, jumping, attacking etc. I have different animations. Just I don't know how to add them correctly?
在图书馆中我创建了我的角色,它命名为英雄As Linkage太英雄。我需要双击它,在英雄的时间轴创建新的层与名称运行,步行,攻击等...然后放在这里动画?或者我需要在库创建名称和As LinkageHeroRun,heroAttack等...?
In Library I have created my character, It named "Hero" As Linkage too "Hero". I need double click It and in Hero's timeline create new Layers with names run, walk, attack, etc... and then put here animations? Or I need in Library create name and As Linkage "HeroRun", "heroAttack" etc...?
我知道我需要使用 Hero.gotoAndPlay(run);
但这不适用于我。对不起,这些新手的问题,但我真的需要你的帮助,谢谢你。
As I know I need to use later something like Hero.gotoAndPlay(run);
but this doesn't work for me. Sorry for these newbie questions, but I really need your help, thank you.
例如这是我的代码左转的一部分:
For example this is my part of code for turn left:
if(left){
Hero.x_speed = -walkspeed;
setDirection(1);
Hero.gotoAndPlay(run);// I don't know how to use It correctly
}
UPDATE
现在的样子:
创建的MovieClip字符英雄
How It looks now:Created MovieClip character Hero
创建的图层已开始创建
现在我需要使用 Hero.gotoAndStop(hit);
如果想看hit动画?
And for now I need to use Hero.gotoAndStop("hit");
if want to see "hit" animation?
UPDATE 2
好吧,我做到了,但现在我有问题,没有动画只有在我使用后更改图像 Hero.gotoAndStop(attack);
,但这里必须是动画。这里是照片如何攻击MovieClip看起来像:
UPDATE 2All right, I did that, but now I have problem there is no animations only change image after I use Hero.gotoAndStop("attack");
, but here must be animation. Here is photo how attack MovieClip looks like:
这里是我的英雄截图。它有两个关键帧攻击和进攻。
Here' my Hero screenshot.It have 2 keyframes Attack and Going.
这里是hero> going timeline的截图:
And here is hero > going timeline's screenshot:
UPDATE:
这是我的代码空格按钮(跳跃字符)当它显示在地面上的动画我有大滞后我认为,因为检查碰撞,
Here is my code for space button (jumping character) when It show animation on the ground I have big lags I think that because checking for collisions and when on the air animation playing without lag.
if(Hero.y_speed>0 && myCollisionList.checkCollisions().length > 0 ){
Hero.y_speed=0;
Hero.x_speed=0;
if(space){
if (ground.hitTestPoint(Hero.x + 28, Hero.y+20, true)){
Hero.gotoAndStop("attack");
stop();
Hero.y_speed = -20;
这里是碰撞列表:
var myCollisionList:CollisionList = new CollisionList(Hero);
myCollisionList.addItem(ground);
myCollisionList.addItem(ground3);
myCollisionList.addItem(ground5);
myCollisionList.addItem(ground4);
推荐答案
函数采用框架索引( int
)或框架标签( String
)参数,而不是另一个影片剪辑的名称。
The gotoAndPlay()
function takes either a frame index (int
) or a frame label (String
) parameter, not the name of another movie clip.
您想要做的事情可以通过几种方式完成 - 在我看来最简单的是设置一个 MovieClip
,其中包含您的角色作为单独关键帧的所有动画。然后,您可以使用唯一标签为每个关键帧添加标签,然后使用功能在动画之间切换。
What you're trying to do can be accomplished in several ways - in my opinion the simplest is to set up one MovieClip
that contains all the animations of your character as individual keyframes. You can then label each keyframe with a unique label and then use the gotoAndStop()
function to switch between animations.
首先,将每个字符动画创建为单独的 MovieClip
- 您不需要导出这些(除非您需要以编程方式访问它们)。完成后,创建一个新的 MovieClip
,并为您制作的每个动画添加关键帧。所以如果你的角色有4个动画(例如 walking
, idle1
, idle2 $
First, create each character animation as a separate MovieClip
- you don't need to export these (unless you need to programmatically access them). Once this is done, create a new MovieClip
and add a keyframe for each of the animations you made. So if your character has 4 animations (for example walking
, idle1
, idle2
, running
) you'd create 4 keyframes in this clip.
将每个动画在一个关键帧(仔细对齐它们,以便当你切换字符不会跳跃),然后标记每个关键帧与适当的动画名称。从库中导出此影片剪辑。您可以通过单击时间轴中的关键帧,然后在属性
窗口中添加标签名称来标记关键帧。一旦框架标签就位,框架将具有小的红色标记。以下是Flash CS 5中标签的屏幕截图(图片编辑后仅显示相关部分):
Put each of the animations in one of the keyframes (carefully align them so that when you switch the character won't jump) and then label each keyframe with the appropriate animation name. Export this movie clip from the library. You can label a keyframe by clicking the keyframe in the timeline and then adding a label name in the Properties
window. Once the frame label is in place, the frame will have a small red flag. Here's a screenshot with the labels in Flash CS 5 (the image is edited to show only relevant parts):
完成此操作后,您现在可以创建一个您的角色并通过调用以下方式设置正确的动画状态:
Once this is done, you can now create an instance of your character and set the correct animation state by calling:
...
Hero.gotoAndStop("walking");
...
您还可以使用 Hero.gotoAndStop (1);
如果步行动画是在关键帧1,但如果你改变动画的顺序,你必须更新所有的代码,如果你使用帧索引。使用框架标签是非常灵活的。
You could also use just Hero.gotoAndStop ( 1 );
if the walking animation is on keyframe 1 but if you change the order of your animations you'd have to update all the code if you use frame indexes. Using frame labels is a lot more flexible.
您需要使用 gotoAndStop()
指定的关键帧并保持在该帧中显示动画。如果你使用 gotoAndPlay()
,你只会看到所有状态动画的第一帧作为Flash循环通过关键帧。
You need to use gotoAndStop()
to let Flash stay on the specified keyframe and keep showing the animation in that frame. If you used gotoAndPlay()
you'd only see the first frame of all state animations as Flash cycles through the key frames.
这篇关于动作脚本3.当角色移动时更改动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!