当我拍摄子午线时,它们会被丢弃,这正是我想要的,但是,我希望更多的子类产卵,而不是仅仅删除forever.Im,不知道在这段代码中添加什么来让更多的子代进入游戏。
任何帮助都是非常感谢的。
我认为,将asteriods的数量设为常量将确保5个asteriod在任何时候都在屏幕上,但是这似乎不起作用。
// the asteroids
const NUM_ASTERIODS = 3;
for (let i = 0; i < NUM_ASTERIODS; i++) {
var spawnPoint = asteroidSpawnPoint();
var a = add([
sprite("asteroid"),
pos(spawnPoint),
rotate(rand(1,90)),
origin("center"),
area(),
scale(0.2),
solid(),
"asteroid",
"mobile",
"wraps",
{
speed: rand(5, 10),
initializing: true
}
]);
while (a.isColliding("mobile")) {
spawnPoint = asteroidSpawnPoint();
a.pos = spawnPoint;
a.pushOutAll();
}
a.initializing = false;
a.pushOutAll();
}
function asteroidSpawnPoint() {
// spawn randomly at the edge of the scene
return choose([rand(vec2(0), vec2(width(), 0)),
rand(vec2(0), vec2(0, height())),
rand(vec2(0, height()), vec2(width(), height())),
rand(vec2(width(), 0), vec2(width(), height()))]);
}发布于 2022-11-29 10:03:06
Kaboom网站有一个使用loop()生成游戏对象的演示,这有帮助吗?
https://stackoverflow.com/questions/74511264
复制相似问题