Jump to content

How-to create a demo stage with autoplay / demo-mode autorunning?


ZED
 Share

Recommended Posts

Hello,

 

I am using Phaser because working to a arcade-style "remake" of a game, made some time ago jQuery/JS, and that I'm re-creating with better features using Phaser, of course.

 

All seems great 'til now (very fast), but I would like to know if is there a way to show to the gameplay to users, i.e our game running alone, all dinamycs pre-recorded (just to get idea, like it were a video), and a button Press Start to start playing live.

 

Can a Phaser stage added in the top of the list be guided by JS code, i.e random or something like that? I suppose yes, but just searching the best way for acting... what do you think? Hope I was clear, thanks in advance for help!

 

Salvatore

 

 

Link to comment
Share on other sites

In arcade games this is often called 'attract mode'. I guess one way you could do this is to first ensure any random events use the game.rnd instance methods properly seeded (see this example - needs the developer console open to see the output: http://examples.phaser.io/_site/view_full.html?d=misc&f=repeatable+random+numbers.js&t=repeatable%20random%20numbers) and then play a game, storing your inputs every frame into an array in some format. Then have a state where the game is initialised into a specific and reliable state and those inputs are fed back into the game, with the real inputs disabled except for the 'press start' button.

Link to comment
Share on other sites

Thank you lewster32, your help is great.

 

Think your idea about "attract mode" sound interesting, I will investigate in these days and post here some results /further ideas - got some doubts about saving format for single array elements, images shoud be too heavy so need to try some things before proceeding.

 

And I suppose, for now, that Phaser would be coolest if should automate this, i.e with some ad hoc functions :)

Link to comment
Share on other sites

Unity goes about this in a pretty good way; all objects can be 'serialized' - their important properties returned as an easily parsable object - and then saved. If you extend all of the Phaser objects you wish to use (Sprite etc) then you could add your own serialize method, which returns a standard JavaScript object containing its properties - something like this:

sprite.serialize();> { id: "dde408b0-5189-44b5-a85d-d7edf6b3edd2", type: "sprite", key: "player", frame: 0, position: { x: 100, y: 200}, scale: { x: 1, y: 1}, anchor: {x: 0.5, y: 0.5}, rotation: 0, z: 12 }

You could add properties from the body too, to save the velocity, facing etc etc, basically you decide which properties are important. Then you should be able to write another function which is run during state.create which checks through the saved list of serialized objects and recreates them with the same properties in the new state.

 

The only thing you'd probably want to add is a unique ID to every object you create so it can be tracked, and handily Phaser has a function for this built in.

Link to comment
Share on other sites

  • 2 weeks later...

Ok, this sounds like using JSON strings as serializable object and that's good, but how to save "persistent" objects? I suppose that javascript is not the most adapt language for doing that... or am I missing something?

Link to comment
Share on other sites

How persistent do you need it to be? If you want persistence between browser sessions, you can use local storage. If you want persistence between multiple players (or just more reliable persistence) then you could create a RESTful server in NodeJS or similar, then send the objects to the server to be stored in a database or other data storage medium. When you start doing server-side stuff though, be aware it's a can of worms you're opening - suddenly you have to figure out how to identify a particular user, which usually leads to needing a login process of some kind.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...