canvas小球乱撞动画效果代码

代码语言:html

所属分类:动画

代码描述:canvas小球乱撞动画效果代码

代码标签: canvas 小球 乱撞 动画

下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开

<!DOCTYPE html>
<html lang="en" >

<head>
  <meta charset="UTF-8">
  

  
  
<style>
canvas{
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%); 
}
</style>

  
  
  
</head>

<body>


<canvas id="gameCanvas" width="350" height="180"></canvas>


  
      <script >



//js for the bouncy ball
var canvas;
var canvasContext;
var rectX = 170; //coordinates of the white squre
var rectY = 90; //coordinates of the white squre
var squareSpeedX = 10; //speed of the white square
var squareSpeedY = 10; //speed of the white square

var blockageX = 100;
var blockageY = 10;
var blockageHeight = 130;
var blockageWidth = 5;

canvas = document.getElementById("gameCanvas");
canvasContext = canvas.getContext("2d");

var framePerSecond = 60;
setInterval(function () {
  draw();
  move();
}, 1000 / framePerSecond);

//this is a function to draw. I put here all the things needs to be.........完整代码请登录后点击上方下载按钮下载查看

网友评论0