English 中文(简体)
平方运动不平稳
原标题:Pong movement not smooth

我想在处理过程中玩个乒乓球游戏。 但是球的动作并不很顺利。 我尝试了改变框架率并降低球速, 但动作速度似乎并不稳定。 这会不会是一个性能问题? 我做错了什么, 或者处理得不对, 即使是简单的游戏? (我的目标是尝试处理.js 并做一个没有插件的游戏) 。 这是我的代码 :

// Colorset
color scrBG;
color bastards;

// Border for the Paddle
int border;

// The Paddle
int padWid;
int padHei;
float padX;
float padY;

// The Ball
float ballX;
float ballY;
int ballRad;

int speed;
float velX;
float velY;

boolean playing = false;



void setup()
{
  border = 5;

  scrBG = #EEEEEE;
  bastards = #FFF0EB;

  padWid = 80;
  padHei = 10;
  ballRad = 15;
  speed = 5;
  velX = velY = speed;

  size(800, 600);
  background(scrBG);
  noStroke();
  noCursor();
  //frameRate(100);
  smooth();
}

void draw()
{

  background(bastards);drawPaddle();
  drawBall();
}

void drawBall()
{

  if(!playing)
  {
    ballX = padX+padWid/2;
    ballY = height-border-padHei-ballRad/2-2;
  }
  else
  {
if(ballY > height)
{
  ballOut();
}

if(ballY > padY && ballX < padX + padWid && ballX > padX)
{
  velY = -velY;
  ballY = padY-ballRad-1;
}
if(ballX < ballRad)
{
  velX = -velX;
  ballX = ballRad+1;
}
if(ballX > width-ballRad)
{
  velX = -velX;
  ballX = width-ballRad-1;
}
if(ballY < ballRad)
{
  velY = -velY;
  ballY = ballRad+1;
}


ballY += velY;
ballX += velX;   
  }

  fill(0);
  ellipse(ballX, ballY, ballRad*2, ballRad*2);

}

void drawPaddle()
{
  padX = constrain(mouseX, border, width-padWid-border);
  padY = height-padHei-border;

  fill(0);
  rect(padX, padY, padWid, padHei);
}

void startLevel()
{
  playing = true;
}

void resetLevel()
{
  playing = false;
}

void ballOut()
{
  playing = false;
}

void mouseClicked()
{
  if(playing)
  {
    resetLevel();
  }
  else
  {
    startLevel();
  }
}
最佳回答

您的 FramerRate 似乎退出高空。 30 个框架通常在像 Planching 和 Flash 那样的事物中是滑动动动画的好速度 。 我也会将我所有的内涵都换成浮点, 因为浮点对平滑动画来说更好 。

我接下来要看到的是 添加一些放松, 这样可以平滑它。请看关于处理的这个信息。 org :

"http://procession.org/learning/basics/easing.html" rel=“nofollow'>www.process.org/learning/basics/easing.html

并游戏一局。

问题回答

暂无回答




相关问题
Best dynamic languages for OpenGL/general graphics

Which are the most mature and well supported solutions for writing graphical programs? I have been using C++ with OpenGL/GLUT, but would like to try a more flexible and expressive approach. Ruby and ...

How to change a GLSL shader parameter in Processing

I m playing with shaders in openGL using Processing. I m pretty noob at this and a bit lost. I found this thread that has an example on how to use GLSL shaders in Processing. I m just trying to the ...

How to tell when an @font-face rule is applied

Is there any way to tell when an @font-face rule is applied? I m creating @font-face rules that use data: URIs from a font file requested with an synchronous XMLHttpRequest in JavaScript and then ...

how to extrude a path in 3d?

I m trying to extrude a path in 3d. Nothing fancy yet, just following some points and using a regular polygon for tubing . I m using Processing for now to quickly prototype, but will later turn the ...

Java - Zoom / 3D Data Visualization Libraries

What are the best libraries/frameworks for doing 3D and/or Zoom interfaces in Java? I d like to be able to do some prototyping of creating new types of interfaces for navigating within data and ...

热门标签