当人物移动的动作脚本3.更改动画 [英] Action Script 3. Change animations when character moving

查看:165
本文介绍了当人物移动的动作脚本3.更改动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要创建简单的Flash游戏。我需要改变动画时的性格感动。例如,当走,跑,跳,攻击等我有不同的动画。只是我不知道如何正确地添加它们?

在图书馆中,我创建了我的性格,它命名为英雄作为太联动英雄。我需要双击它,在英雄的时间表创建新的图层名称跑步,走路,攻击,等等......然后把这里的动画?或者我需要在图书馆创建点名和联动HeroRun,heroAttack等...?

据我知道我需要使用后像 Hero.gotoAndPlay(运行); 但是,这并不为我工作。对不起,这些新手的问题,但我真的需要你的帮助,谢谢你。

例如,这是我的code部分为左转:

 如果(左){
                Hero.x_speed = -walkspeed;
                setDirection(1);
                Hero.gotoAndPlay(运行); //我不知道如何正确使用它
}
 

更新

如何现在看来: 创建影片剪辑人物英雄

创建图层命中和去

和现在我需要使用 Hero.gotoAndStop(点击); 如果想看打动画

更新2 好吧,我这样做,但现在我已经问题存在后,我不使用动画只改变图像 Hero.gotoAndStop(攻击); ,但在这里必须动画。这里是照片如何攻击的MovieClip是这样的:

这里是我的英雄screenshot.It有2个关键帧进攻中去。

和这里的英雄>将时间线的截屏:

更新:

下面是我的code空间键(跳跃的字符),当它显示动画在地上我有我认为这是因为碰撞检测,并当上了空中动画播放无延迟。

大滞后

 如果(Hero.y_speed> 0安培;&安培; myCollisionList.checkCollisions()长度GT; 0){
        Hero.y_speed = 0;
        Hero.x_speed = 0;

        如果(空间){


            如果(ground.hitTestPoint(Hero.x + 28,Hero.y + 20,TRUE)){

            Hero.gotoAndStop(攻击);
            停止();
            Hero.y_speed = -20;
 

这里是冲突列表:

  VAR myCollisionList:CollisionList =新CollisionList(英雄);
        myCollisionList.addItem(地);
        myCollisionList.addItem(ground3);
        myCollisionList.addItem(ground5);
        myCollisionList.addItem(ground4);
 

解决方案

的<一个href="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/MovieClip.html#gotoAndPlay%28%29"相对=nofollow> 的gotoAndPlay() 功能,它可以是一个帧索引( INT )或帧标签(字符串)的参数,另一个影片剪辑的不是名字。

您正在试图做的可以通过多种方式来实现什么 - 在我看来,最简单的就是建立一个影片剪辑包含你的角色的所有动画作为个别关键帧。然后,您可以标记每个关键帧的唯一标签,然后使用<一个href="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/MovieClip.html#gotoAndPlay%28%29"相对=nofollow> gotoAndStop() 功能的动画之间切换。

首先,创建每个角色动画作为一个单独的影片剪辑 - 你不需要导出这些(除非你需要以编程方式访问它们)。一旦做到这一点,创建一个新的影片剪辑并添加关键帧为每个您所做的动画。所以,如果你的角色有4个动画(例如 IDLE1 IDLE2 运行)你会在这个片段创建4个关键帧。

将每个动画中的关键帧中的一个(小心地将它们,这样当您切换字符不会跳),然后标记每个关键帧与相应的动画名。导出从库中此影片剪辑。您可以通过单击时间轴中的关键帧,然后在属性窗口添加标签名称标记一个关键帧。一旦帧标签是否到位,该框架将有一个小红旗。以下是在Flash CS 5标签的截图(图像编辑,只显示相关部分):

一旦做到这一点,你现在可以创建你的角色的实例,并通过调用设置正确的动画状态:

  ...
Hero.gotoAndStop(走);
...
 

您也可以只使用 Hero.gotoAndStop(1); 如果行走动画关键帧1,但如果你改变了动画的顺序,你不得不如果你使用的帧索引更新所有code。使用帧标签是一个很大的灵活性。

您需要使用 gotoAndStop()让闪存停留在指定的关键帧,并继续显示在该帧的动画。如果你使用的gotoAndPlay()你只看到过关键帧的所有状态的动画为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?

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...?

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

How It looks now: Created MovieClip character Hero

Created layers hit and going

And for now I need to use Hero.gotoAndStop("hit"); if want to see "hit" animation?

UPDATE 2 All 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.

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;

And here is collision list:

        var myCollisionList:CollisionList = new CollisionList(Hero);
        myCollisionList.addItem(ground);
        myCollisionList.addItem(ground3);
        myCollisionList.addItem(ground5);
        myCollisionList.addItem(ground4);

解决方案

The gotoAndPlay() function takes either a frame index (int) or a frame label (String) parameter, not the name of another movie clip.

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.

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.

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");
...

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.

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.更改动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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