亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何在P5中為球添加彈跳壓縮動畫?

如何在P5中為球添加彈跳壓縮動畫?

呼啦一陣風 2021-05-04 21:29:22
我用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;      }    }  }  this.show = function() {    ellipse(this.xpos, this.ypos, this.diameter);    fill(255);  }}var ball;function setup() {  createCanvas(600, 600);  ball = new Ball();}function draw() {  background(0);  ball.update();  ball.show();}<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.8.0/p5.js"></script>
查看完整描述

1 回答

  • 1 回答
  • 0 關注
  • 130 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號