小编R G*_*eet的帖子

如何完全停止/重置/重新初始化 Matter.js canvas/world/engine/instance

我在屏幕上有一个 Matter.js 实例,例如游戏,并且希望在用户/玩家单击“新游戏”按钮时从头开始:

const { Engine, Render, Runner, World, Bodies, Mouse, MouseConstraint, Body, Events } = Matter;

    //movement setup
    const engine = Engine.create();
    const { world } = engine;

    let render;
    let runner;

const startGame = document.querySelector('#start');
startGame.addEventListener('click', event => {

    event.preventDefault();

    //hide 'choose difficulty' 
    const chooseDifficulty = document.querySelector('.options');
    chooseDifficulty.classList.add('hidden');

    //get selected difficulty
    const difficulty = document.querySelector('input[name=difficulty]:checked').value;

    //set number of horizontal/vertical cells based on difficulty selected
    switch(difficulty) {
        case 'easy':
            cellsHorizontal = 6;
            cellsVertical = 4;
            break;
        case 'medium':
            cellsHorizontal …
Run Code Online (Sandbox Code Playgroud)

javascript matter.js

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

Mongoose Post Hook 用于 create() 而不是 update()

也许我误解了,但我能找到的在猫鼬模型上使用后挂钩的所有内容都create()提出了该update()方法。和create()update()一样的吗?

我想要做的是在User创建文档时发送欢迎电子邮件,而不必在创建用户的每个路由/控制器上手动调用方法。

我对前挂钩和后挂钩有一些了解,并且我有一个预删除挂钩:

userSchema.pre('remove', async function() {
    for (let response of this.responses) {
        Response.findByIdAndRemove(response);
    };
});
Run Code Online (Sandbox Code Playgroud)

但我在 mongoose 文档中找不到任何关于create().

如果create()update()相同,那么当用户信息发生更改时,什么会阻止发送此欢迎电子邮件?我只想在最开始的时候发送一次。

让我知道我是否清澈如泥

javascript mongoose mongodb node.js

0
推荐指数
1
解决办法
3320
查看次数

标签 统计

javascript ×2

matter.js ×1

mongodb ×1

mongoose ×1

node.js ×1