【问题标题】:Action Script 3. How to make shadow bottom of the character?动作脚本 3. 如何在角色的底部制作阴影?
【发布时间】:2014-02-18 19:01:18
【问题描述】:

我正在创建 Flash 游戏,我需要在角色和敌人的底部制作阴影。这里有大约 35 个动画,每个动画大约 100 帧。所以编辑每一帧并绘制阴影是不可能的。

我的角色的名字是英雄和对手的敌人。我需要制作这样的东西,总是会显示英雄和敌人阴影的底部(阴影可以是圆形等)。只是在跳跃时它应该重新调整大小(当角色/敌人在空中时,阴影应该更暗更小)。

有没有可能做这样的事情?

这就是我宣布敌人的方式:

public var Enemy:Priesas = new Priesas; //Priesas is instance name of Enemy

英雄的模板是通过点击按钮来选择的:

public function selectHero(what:int):void {
    // this is called with correct "what", design yourself. I use array index
    var whatHero:Class = heroes[what]; // get selected hero symbol
    if (Hero && Hero.parent) Hero.parent.removeChild(Hero);
    // clean up previous hero. Drop listeners here, if any
    Hero = new whatHero(); // get new hero
    // process as usual, don't forget to "addChild(Hero)" somewhere
    create_hero();
}

    function choosePlayer(event:MouseEvent):void {
        selectHero(0); // here is set first template for my Hero
        start(event);
        }

     function create_hero()
     {
        addChild(Hero);
     }

所以声明的变量是:HeroEnemy

这是如何为角色英雄设置动画的最简单代码:

if (attack1)
{
            enterFrameHandler();
    Hero.gotoAndStop("attack1");

}

我不知道你是否有足够的信息,请你帮帮我吗?

【问题讨论】:

    标签: actionscript-3 flash animation actionscript shadow


    【解决方案1】:

    创建一个电影剪辑“阴影”,它是您想要的任何形状的阴影。 创建另一个包含英雄和影子的影片剪辑“HeroWithShadow”。

    public function selectHero(what:int):void {
        // this is called with correct "what", design yourself. I use array index
        var whatHero:Class = heroes[what]; // get selected hero symbol
        if (Hero && Hero.parent) Hero.parent.removeChild(Hero);
        // clean up previous hero. Drop listeners here, if any
        Hero = new whatHero(); // get new hero
        // process as usual, don't forget to "addChild(Hero)" somewhere
        create_hero();
    }
    
    function choosePlayer(event:MouseEvent):void {
        selectHero(0); // here is set first template for my Hero
        start(event);
    }
    
    function create_hero(){
        //create shadow
        var shadow:Shadow = new Shadow();
        //create container that will hold both hero and shadow
        var heroWithShadow:HeroWithShadow = new HeroWithShadow();
        //add both hero and shadow on heroWithShadow
        heroWithShadow.addChild(Hero);
        heroWithShadow.addChild(shadow);
        //bring shadow to the bottom of hero
        shadow.y = Hero.height;
        addChild(heroWithShadow);
    }
    

    请注意,现在如果你想水平移动英雄(步行)然后更新“heroWithShadow.x”,如果你想垂直移动英雄(跳跃)然后更新“Hero.y” 让我知道这是否有效。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-03-22
      • 1970-01-01
      • 1970-01-01
      • 2022-01-14
      • 1970-01-01
      • 1970-01-01
      • 2020-10-23
      • 2018-03-01
      相关资源
      最近更新 更多