为平台游戏as3

时间:2015-12-27 18:42:13

标签: actionscript-3 game-engine side-scroller scrollrect

编写一个横向滚动平台并认为scrollRect最适合内存,因为它只渲染矩形而不是整个舞台。我让它以我的英雄为中心并与他滚动。我的问题是为矩形创建外边界。 if(view.x< 0)很容易。我有x和y起源被锁定,这是我遇到问题的其他边缘。它在ENTER_FRAME上运行,顺便说一句。这是我的代码:

    public function ScrollWithHero()
    {
        var stageW2:Number = stage.stageWidth/2;
        var stageH2:Number = stage.stageHeight/2;
        var view:Rectangle = new Rectangle(0,0,stage.stageWidth,stage.stageHeight);

        if(hero.x - stageW2 > 0){ view.x = hero.x - stageW2; }

        if(hero.x + stageW2 > levelWidth){ // stop scrolling the rect }

        if(hero.y - stageH2 > 0){ view.y = hero.y - stageH2; }

        if(hero.y + stageH2 < levelHeight){ // stop scrolling the rect }

        scrollRect = view;
    }

1 个答案:

答案 0 :(得分:0)

public GameObject[] models;
       GameObject currentPoint;
       int index;
 public AudioSource correct;
 public AudioSource notcorrect;

 void Start()
 {
     models = GameObject.FindGameObjectsWithTag("numbers");
     index = Random.Range (0, models.Length);
     currentPoint = models[index];
     print (currentPoint.name);
     models [index].GetComponent<AudioSource> ().PlayDelayed(2);
     }