0
我在我的代码中发现错误时遇到问题。我正在为一个学校项目制作我自己的太空入侵者版本。 P5没有显示任何错误,但是当我对代码进行测试运行时,我得到的只是一个白色屏幕。我需要一套额外的眼睛。任何帮助表示赞赏。谢谢!!P5.js中的未知错误
//initializes bullets
var bullets = {
x: new Array(),
y: new Array(),
shot: new Array()
}
//initializes the ship
var ship = {
x: 625,
y: 475,
photo: loadImage("download.png")
}
function setup() {
createCanvas(1350,650);
//bullet1
append(bullets.x, ship.x);
append(bullets.y, ship.y);
append(bullets.shot, false);
//bullet2
append(bullets.x, ship.x);
append(bullets.y, ship.y);
append(bullets.shot, false);
//bullet3
append(bullets.x, ship.x);
append(bullets.y, ship.y);
append(bullets.shot, false);
}
//Controls
function updateShip()
{
//Right movement
if (keyIsDown(RIGHT_ARROW)) {
ship.x = ship.x+ 10;
if (ship.x >= 1350) {
ship.x = ship.x - 11;
}
}
//Left movement
if (keyIsDown(LEFT_ARROW)) {
ship.x = ship.x - 10;
if (ship.x <= 0) {
ship.x = ship.x + 11;
}
}
//Up movement
if (keyIsDown(UP_ARROW)) {
ship.y = ship.y - 10;
if (ship.y <= 350) {
ship.y = ship.y + 11;
}
}
//Down movement
if (keyIsDown(DOWN_ARROW)) {
ship.y = ship.y + 10;
if (ship.y >= 580) {
ship.y = ship.y - 11;
}
}
}
function drawShip()
{
ship.photo.resize(75,75);
image(ship.photo,ship.x-ship.photo.width/2,ship.y+ship.photo.height/2);
}
//Drawing the bullets
function drawBullets() {
fill(255);
rect(bullets.x[0],bullets.y[0], 5, 10);
rect(bullets.x[1],bullets.y[1], 5, 10);
rect(bullets.x[2],bullets.y[2], 5, 10);
}
//Controls the bullet movement
function updateBullets() {
bullets.y[0] = bullets.y[0] + 10;
}
//Checks if bullet is shot
function checkShoot() {
if (keyIsPressed && keyCode === 32) {
bullets.y[0] = ship.y;
}
}
function draw() {
background(0);
updateShip();
drawShip();
checkShoot();
updateBullets();
drawBullets();
}
告诉我们你的HTML – Goose
? I.无法看到这个应用程序从 –
开始,我没有编码任何HTML。它在P5中,几乎是JS的Processing版本。 –