Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
Tags

RenJS

HTML5 Visual Novel creation made easy and free · By lunafromthemoon

Phaser Editor 2D (IDE), mini games and RenJS

A topic by Lapinay created Apr 13, 2019 Views: 771 Replies: 15
Viewing posts 1 to 13
(2 edits)

Hi lunafromthemoon.

I don't know if  you have ever used Phaser Editor 2D in one of your phaser projects, but i'm considering using it to make a game where RenJS is the main core system to tell a story, and sometimes i may with a command, a choice or a button  send the player to a mini game on a dedicated phaser scene. 

First i have no idea how to do that and i can't find any documentation on this (i'm not a developer, just learning things from dealing with multiple projects)... 

Secondly, is there a way to use Phaser Editor 2D with such a project ?

Thank you for reading me ^___^;

Developer(+1)

Hello Alix, I haven't used the Phaser Editor, so I can't be of much help with this. I can point you to the GUI file for RenJS, called SimpleGUI.js. This file is where the GUI is created and contains also all the interactions with it.

Another question about mini game, i was looking for answers on the following matter on Phaser documentation, examples and forums with no success, whether i can't find a thing or am I searching with the wrong words.  Let's say I have a mini game (one JS file) coded for Phaser, suppose i want to call this game over or inside the RenJS game canvas,  the mini game is playable and the story stops, i would have to show a button to close the mini game i think to continue the story and add something to continue the story when game is complete or over,  and finally I could use scores from this mini game as variables in the story for branching purpose.  Could you guide me please :) ?

Developer

To continue with the story, you need to call the function RenJS.resolve(), this is called after completing every action, and tells the story interpreter that this action is finished and to read the next one. In your minigame, make sure that you finish it completely before calling RenJS.resolve(), for example, you'll need to hide all of the assets, finish all animations and tweens, stop music, etc.

On you're second question, as long as you store your variables into RenJS.logicManager.vars during the minigame, then you can use them in the story as well.

What i don't understand is where do I put the code of the mini-game. In CustomContent.js or in separate JS file. If in CustomContent I don't know how to wrap the code of the mini game in a function to call in the story, and if outside CustomContent I don't know how to proceed... Sorry i'm such a newbie :)

hello, i met the question same as you . Sorry, i am not good at english.

For example, your write your game code in function "   gamefucntion(){}" . 

You can write

game.state.add('yourgame', gamefucntion);
game.state.start('yourgame');

in CustomContent.js.

But, i don't know how i can exit my game completely.

I want to combine renjs with my phaser game, which is really drives me crazy.

I'm lost such as you are :)

Someone on the Phaser's Discord channel suggested the following : 

two options 
1) you can call a normal JS function that creates and starts the game -- this would basically just be something like
function startMiniGame() { return new Phaser.Game(...) } 
and when it's over you would just destroy the game / make sure you drop all references and let it get garbage collected 

2) the other option would be to start the game in a hidden div and when it's time to start it your function would just call update a boolean that your game tracks and start playing; it'd look something like 

function startMiniGame() { document.getElementById('phaser-game').style.display = 'absolute'; window.gameRef.miniGameEnabled = true; }
 the actual details will vary wildly and I don't remember CE well at all so none of that sample code can be used as is but those are probably your two best approaches

In the two options I don't understand where and how  to put the mini-game code. What about a mini game with multiple files ?

I think using Phaser STATES would be the right solution, but i 've tried to make a function in CustomContent that calls a state but with no success. Then i also don't know how to come back to current RenJS story.

Developer

Hello guys, the Phaser STATES can not be used for a mini game because RenJS uses them internally to run. Basically, if you change your state to a minigame, it will be very difficult to return back to the story as it was before calling the minigame.

I think the solution of calling a new Phaser Game entirely (in a different div) from a CustomContent function is the right way. You just have to add your minigame files to the index.html, along with RenJS, and when you want to call the minigame you do it from a CustomContent function, remembering to call RenJS.resolve() once your minigame is over (and hiding your minigame div).

I'll try to build a simple example for you to play with.

Developer(+1)

Here's the example: https://gitlab.com/lunafromthemoon/renjs-minigame-example

Your minigame is in a folder called minigame, it's the breakout example from Phaser (https://phaser.io/examples/v2/games/breakout). The only change is that the creation of the game is inside a function called createMinigame(callback), the callback is a function that the minigame has to call when it's over. In this case, the minigame is over when you lose three lives. By calling the callback function, the control returns to RenJS. Also, the  score of the minigame is sent as a parameter to the callback function, so that I can have this information in the story.

To start the minigame, I use an action "call", to the CustomContent function minigame. This function hides the RenJS canvas, calls the createMinigame() function and creates the callback, that will store the score from the minigame into RenJS.logicManager.vars, show again the RenJS canvas, and then continue with the story. 

The file for the minigame has to be called from the index too.

The example is very simple and the transition between the story and the minigame is very rough, you should code a nicer one.

Thank you ! This is exactly what i need :)

Deleted 5 years ago
(3 edits)

it is amazing! Thank you  lunafromthemoon. I love your code.

I'm sorry I didn't see it earlier, though I couldn't have done it. hahaha.

The method I used before is: when the plot is over, I start a phaser game, like this

   game.state.start("startGame",true);

Then re-initialize the story system when the game is over.

This made my project module clear, but I also spent days researching the source code for RenJS.

Now the RenJS in my project has been messed up by me. hahaha

Developer(+1)

Thanks! I tried to keep the code clean so anyone could make they own modifications. If your method works then it's good, I thought about this other way because changing the states could bring unexpected bugs.

(5 edits)

Hi. 

I have another issue i can't solve. Currently, with your help i can call a mini-game that is coded in a single JS file working with Phaser 2.

Then, i discussed with someone who knows Phaser 2 and Phaser 3, he told me that i can also call from RenJS, if i want, a mini game working with Phaser 3 (and others JS scripts), using 

window.open("/myPhaser3MiniGame-index.html", "_blank");
His words :

You're launching a separate html page with it own scripts (Phaser3 in this case). You will need preserve any information (perhaps in local storage?) when you return to RenJS.

First, when I've tried this in CustomeContent.JS, it opens the minigame on another tab, and Renjs tab remain blank.

Second, if this is possible, i have no idea how to "preserve information" user score etc "perhaps in local storage.

Any help is very much appreciated !  ^__^ ;

Hi @lunafromthemoon What would be your thoughts about this last point of mine ?