actionscript 3:在hitTestObject之后改变对象大小

时间:2015-09-13 11:10:28

标签: actionscript-3 object resize size hittest

我想让我的球员分别吃掉一个好的(球2)或坏球(theBadBall)时直径变大或变小。香港专业教育学院创建了一个hitTestObject函数,我试图让球越来越大,但它不起作用。

          var player1;
          var player2;
          var player3;
          var theBall2;
          var theBadBall;
          player1 = new player(50,384, 1);
          player2 = new player(944,384,2);
          player3 = new player(488,84,3);
          stage.addChild(player1);
          stage.addChild(player2);
          stage.addChild(player3);
          var player.width: player.width * 2; // 1086 syntax error: expecting semicolon before dot.
          var player.height:player.height * 2;// 1086 syntax error: expecting semicolon before dot.

        //this function checks to see if theBall2 has collided with a player
        if(theBall2.hitTestObject(player1) || theBall2.hitTestObject(player2) || theBall2.hitTestObject(player3))
        {
            //removes the ball from the stage
            trace("a player has eaten a ball");
            stage.removeChild(theBall2);
            //adds new ball
            theBall2 = new ball2();
            theBall2.x = stage.stageWidth/2;
            theBall2.y = stage.stageHeight/2;
            stage.addChild( theBall2 );
            //makes player larger
            player.width =  player.width * 4; // do I have to define player1, player2, player3, instead of their class player?
            player.height =  player.height * 4;
        }

        //this function checks to see if theBadBall has collided with a player
        if(theBadBall.hitTestObject(player1) || theBadBall.hitTestObject(player2) || theBadBall.hitTestObject(player3))
        {
            //removes thebadball from the stage
            trace("a player has eaten bad ball");
            stage.removeChild(theBadBall);
            //adds new ball
            theBadBall = new badball();
            theBadBall.x = stage.stageWidth/2;
            theBadBall.y = stage.stageHeight/2;
            stage.addChild(theBadBall);
            //makes player smaller
            player.width =  player.width / 2;
            player.height =  player.height / 2;
        }

如何让它发挥作用?

1 个答案:

答案 0 :(得分:0)

在任何地方都没有player,因此您无法更改其高度或宽度。 这些行完全错误:var player.width: player.width * 2;

您有player1player2player3,您需要更改其尺寸。那些是MovieClips?

如果是这样,你可以举例如:

var player:MovieClip;
var goodBallHit:Boolean;
if(theBall2.hitTestObject(player1)){
    player = player1;
    goodBallHit = true;
}else if(theBall2.hitTestObject(player2)){
    player = player2;
    goodBallHit = true;
}else if(theBall2.hitTestObject(player3)){
    player = player3;
    goodBallHit = true;
}

if(goodBallHit){
    stage.removeChild(theBall2);
    theBall2 = new ball2();
    theBall2.x = stage.stageWidth/2;
    theBall2.y = stage.stageHeight/2;
    stage.addChild(theBall2);
    player.width = player.width * 4;
    player.height = player.height * 4;
}

所以你真的需要在这种情况下引用实际的对象,player1,..2或..3。

这只是一种方式,还有很多其他方式。我根本不建议使用hitTestObject,尤其是使用ball,但这可能是一个很好的方法。

你的整个项目需要更多的计划,但我知道如果你不太熟悉这门语言会很困难。只需要一些耐心,搜索本网站的信息&谷歌,你肯定会快速完成这项工作。 (+你真的需要继续谷歌搜索,必须有数十个类似的游戏资源和教程)