小编Sad*_*ena的帖子

如何在P5中为球添加弹跳压缩动画?

我用P5.js创建的简单游戏包括一个球,该球在重力作用下掉落并在地面反弹。我想在球触地时为其添加“压缩”动画,以使其看起来更逼真。

我该如何做而又不会显得怪异?

代码是这样的:

function Ball() {
  this.diameter = 50;
  this.v_speed = 0;
  this.gravity = 0.2;
  this.starty = height / 2 - 100;
  this.endy = height - this.diameter / 2;
  this.ypos = this.starty;
  this.xpos = width / 2;

  this.update = function() {

    this.v_speed = this.v_speed + this.gravity;
    this.ypos = this.ypos + this.v_speed;

    if (this.ypos >= this.endy) {
      this.ypos = this.endy;
      this.v_speed *= -1.0; // change direction
      this.v_speed = this.v_speed * 0.9;
      if (Math.abs(this.v_speed) < 0.5) {
        this.ypos = this.starty;
      }
    } …
Run Code Online (Sandbox Code Playgroud)

javascript processing canvas p5.js

7
推荐指数
1
解决办法
128
查看次数

如何将矩形平滑变为圆形?

我正在尝试使用p5.js库在javascript中制作动画.我想做一个方形改变它的形状变成一个圆圈.

我尝试在广场后面画一个圆圈并改变形状的大小,但那不是我想要的效果.

我需要做到这样的事情,旋转并不重要. 一只忙碌的猫

在此先感谢您的帮助!

javascript html5-canvas p5.js

3
推荐指数
1
解决办法
381
查看次数

标签 统计

javascript ×2

p5.js ×2

canvas ×1

html5-canvas ×1

processing ×1