简体   繁体   English

VueJS组件可运行MelonJS游戏

[英]VueJS component to run a MelonJS game

I am making an application with VueJS, that launches a game with MelonJS, and then passes the score along to the mongoDB database. 我正在使用VueJS开发一个应用程序,该应用程序使用MelonJS启动游戏,然后将分数传递给mongoDB数据库。

At the moment, I have a .vue component that I want to inject the game into. 目前,我有一个.vue组件想要将游戏注入其中。

This is where the game should launch 这是游戏应该启动的地方

</template>

<style>
#game-screen {
  background-color: blue;
}
</style>

<script>


</script>

The div screen is where the game is to run. div screen是运行游戏的地方。 The original game minifies the files, and on the index.html file it is injected into that div. 原始游戏会缩小文件大小,并在index.html文件上将其注入该div中。

This is the game that I want to use 这是我要使用的游戏

I am confused when it comes to require or importing the script files. 当需要或导入脚本文件时,我感到困惑。 Does Vue support using such large blocks of code in a component? Vue是否支持在组件中使用如此大的代码块? If I link the files in the new project html file, once the component loads will it have access to the js and css files? 如果我将文件链接到新的项目html文件中,则一旦组件加载,它是否可以访问js和css文件?

I have the idea in my mind that I can require them into the component, and the it will act just like the html file. 我的想法是,我可以要求它们进入组件,并且它的行为就像html文件一样。

Adding a proper answer in so you have something to accept if it works, as well as some more sourcing. 添加一个适当的答案,以便您在可行的情况下有所收获,以及更多的采购。

Each Vue has an el -- Which is the element you are binding to -- as well as events like ready 每个Vue都有一个el (您要绑定的元素)以及诸如ready之类的事件

In melon you supply an el (This is the optional div they call a wrapper) to render your element into, so you should be able to created a Vue, which requires all the game files, with an el of "#screen", and when the ready event fires trigger the game.onload() which will render onto the supplied selector (screen in this case) 在瓜中,您提供了一个el (这是他们称为包装器的可选div)来渲染您的元素,因此您应该能够创建一个Vue,它需要所有游戏文件,并且el为“ #screen”,并且当就绪事件触发时,将触发game.onload(),该game.onload()会呈现在提供的选择器上(在这种情况下为屏幕)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM