乒乓游戏示例

问题描述:

我做了一个非常基本的乒乓游戏(在工作),我的问题是,球移动“模糊”..我增加帧率,但它似乎还没有确定..任何想法?乒乓游戏示例

package src { 
    import flash.display.*; 
    import flash.display.MovieClip; 
    import flash.display.Stage; 
    import flash.display.Sprite; 
    import flash.display.BitmapData; 
    import flash.events.*; 
    import flash.events.MouseEvent; 
    import flash.net.*; 
    import flash.filters.*; 
    import flash.text.*;  
    import flash.xml.*; 
    import flash.geom.*; 

    public dynamic class pong00 extends Sprite{ 

     public var playerA:pongPlayer = new pongPlayer(); 
     public var playerB:pongPlayer = new pongPlayer(); 
     public var ball01:Ball00 = new Ball00(); 
     public var ballDegree:Number = 45; 
     public var ballAngelRadian:Number = 0; 
     public var ballColisionStage:Boolean = false; 
     public var ballAngelRadianVector:Number = 1; 
     public var ballSpeed = 16; 

     public function pong00():void{ 
      addChild(playerA); 
      addChild(playerB); 
      addChild(ball01); 
      ballAngelRadian = (ballDegree * Math.PI/180);         stageOrginizer(); 
     } 
     private function stageOrginizer():void{ // put on the stage 
      tita_txt.text = " Ready "; // .. a text box on stage .. 
      playerA.x = 20; playerB.x = stage.stageWidth - 20; 
      playerA.y = playerB.y = stage.stageHeight/2; 
      ball01.x = stage.stageWidth/2; 
      ball01.y = stage.stageHeight/2; 
      stage.addEventListener(MouseEvent.MOUSE_MOVE, io); 
      stage.addEventListener(Event.ENTER_FRAME, FL); 
     } 
     public function io(evt:MouseEvent):void{ //// mouse 
      if (ball01.x < (stage.stageWidth/2)){ 
       playerA.y = mouseY; 
      }else{ 
       playerB.y = mouseY; 
      } 
     } 
     public function FL(evt:Event):void{  /// stage enter frame 
      if (!(ballColisionStage)){ 
      ball01.x -= ballAngelRadianVector * (Math.cos(ballAngelRadian) * ballSpeed); 
      ball01.y -= ballAngelRadianVector * (Math.sin(ballAngelRadian) * ballSpeed); 
      } 
      if ((ball01.x < 0) || (ball01.x > stage.stageWidth)){ 
       tita_txt.text = " ooops !!! "; // .. a text box on stage .. 
       impact(0); 
      } 
      if ((ball01.y < 0) || (ball01.y > stage.stageHeight)){ 
       impact(180); 
      } 
      if((ball01.hitTestObject(playerB)) || (ball01.hitTestObject(playerA))){ 
       tita_txt.text = "";// .. atext box on stage .. 
       impact(0); 
      } 
     } 
     public function impact(fee:int):void{ 
      ballAngelRadianVector = -ballAngelRadianVector; 
      ballDegree = fee - ballDegree ; 
      ballAngelRadian = (ballDegree * Math.PI/180); 
     } 
    } 
} 
+0

不能真正编译这个 - 你可以上传的SWF或东西,并提供一个链接,所以我可以看到你的意思? http://www.filedropper.com/ – Marty 2011-06-10 05:14:42

+0

http://www.filedropper.com/pong00 – 2011-06-10 05:20:47

+0

你对我的回答不满意吗? – Marty 2011-06-10 06:18:11

从我所看到的一切都是完美的。模糊效果是在较暗的背景上由白球引起的错觉。

如果将帧率降低为10,则会看到没有模糊效果。

PS。在游戏中做得很好 - 如果你需要这个空间的帮助,请告诉我!

+0

检查此.. http://www.kataxco.com/num/num04.html和http://www.kataxco.com/zd/zd04.html ..两个相同的引擎(使用箭头键左右旋转).. :)), – 2011-06-10 05:34:49

+0

非常好。保持。 – Marty 2011-06-10 05:38:57

+0

太好了,谢谢.. – 2017-07-01 08:57:32

我建议你使用tweenlite引擎进行动画制作。我从来没有对这个库有任何问题,这对动画非常棒。你可以下载它在http://www.greensock.com/TweenLite

+0

TweenLite对此会很糟糕。它用于从A点移动到B点一次,而不是像在游戏中一样不断更新位置。 – grapefrukt 2011-06-10 08:39:08

+0

这就是你错了我的朋友:)我已经制作了一个网络摄像头运动检测库,并且我使用TweenLite进行光标的不断动画。如果你将TweenLite的时间设置为0.1,你可以做很好的动画而不会给你的系统带来压力(我已经完成了这方面的研究)。 – 2011-06-10 08:43:07

+0

如果你需要位置插值,也许,但对于更新每一帧的游戏,你没有让我信服。但是,每一个都是他自己的! – grapefrukt 2011-06-10 08:45:06