显示动态变量对下一关键帧AS3 [英] Display dynamic variable on next key frame AS3

查看:155
本文介绍了显示动态变量对下一关键帧AS3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用AS3创建一个游戏。我需要显示的最终得分为下一个关键帧的播放器时,游戏结束。当玩家与敌人的球员得分增加1相撞

这是在code我有更新比分。

  VAR playerScore:= 0;

功能updateTextFields():无效
{
    playerScoreText.text =(分数:+ playerScore);
}

功能抓到(敌人:影片剪辑):无效
{
    enemy.removeEventListener(Event.ENTER_FRAME,dropEnemy);
    removeChild之(敌人);
    playerScore ++;
    updateTextFields();
}
 

我要展示的最后得分在比赛结束画面的球员,但因为playerScore的价值是动态的,加一我不能只显示

  playerScoreText.text =(分数:+ playerScore);
 

作为变量默认为0。

我都试过,但我无法弄清楚如何使它发挥作用。

  VAR playerScore = playerScore;
 

解决方案

如果你想使用VAR在每一帧你必须把它变成一个类(main函数之前)。你也应该使用公共或私人preFIX。如果添加私人你CA只有在这个类中使用这个变量,以及公共将使您能够使用它在每一个涉及到file.Also它的使用,而不是INT UINT好主意类。

例如它应该看起来像:

 包
{
       //进口...
       公共类主要扩展//(你应该写雪碧,影片剪辑...有)
       {
            公共变种playerScore:UINT = 0;
            公共函数main()
            {
                //构造
            }
       }
}
 

I am creating a game using AS3. I need to display the final score for the player on the next key frame when the game is over. When the player collides with an enemy the players score increments by 1.

This is the code I have which updates the score.

var playerScore:int = 0;

function updateTextFields():void
{
    playerScoreText.text = ("Score: " + playerScore);
}

function caught(enemy:MovieClip):void 
{
    enemy.removeEventListener(Event.ENTER_FRAME,dropEnemy);
    removeChild(enemy);
    playerScore++;
    updateTextFields(); 
}

I need to show the final score for the player on the game over screen but because the value for playerScore is dynamic and increments by one I can't just display

playerScoreText.text = ("Score: " + playerScore); 

as the variable default is 0.

I have tried but I can't figure out how to make it work.

var playerScore = playerScore;   

解决方案

If you want to use var in every frame you have to put it into a class (before the Main function). Also you should use public or private prefix. If you add private you ca use this variable only in this class, and public will enable you to use it in every class that is related to that file.Also it's good idea to use uint instead of int.

For example it should look like that:

package
{
       //import...
       public class Main extends //(you should write Sprite, MovieClip... there)
       {
            public var playerScore:uint = 0;
            public function Main()
            {
                //constructor
            }
       }
}

这篇关于显示动态变量对下一关键帧AS3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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