0
\$\begingroup\$

I'm writing a browser-based RPG in JavaScript, HTML5 with Canvas, EaselJS, etc... I'd like to develop the back end data saving/user profile aspect now.

This is a single player RPG where the player will interact with NPCs to solve quests. It is not online.

I've developed a website in PHP before where I saved my own data in a database, and loaded the images to the page via MySQL and PHP.

For a RPG, how would this process be? In my mind... I will try:

  • At the RPG menu, have a user login screen. Handle this with a traditional PHP session.
  • Once the user logs in, load their stats from the database.

What I'm confused about is:

  • Loading text data is okay I suppose... but how can I load objects that were on the screen in the correct locations at the time of the save? Can this be handled through the database?

  • I have generated the Players, Objects, and NPCs as Javascript objects using EaselJS. To save the state of these objects, do I have to load the character as a PHP object?

Kind of like:

/**
 * Load a character and all related items and skills.
 * Do this when the user logs in. You can save the data in a session or
 * reload it every time the user makes a new request
 */
$Character = Character::model()->with('items, skills')->find(
    'username:=username', 
    array('username' => 'demo')
); 

Any tips for loading appropriate data per user profile?

Thanks!

\$\endgroup\$
1
  • \$\begingroup\$ When it's not really online but more like an offline game playing in the web browser, why save on the server at all? You could reduce the complexity a lot by using Javascript to save the game-state to localstorage. That way you don't even need a database. You don't even need PHP, unless you need it for some other reason. \$\endgroup\$
    – Philipp
    Dec 30, 2013 at 22:18

1 Answer 1

1
\$\begingroup\$

You could save the objects data structure serialized into a JSON structure and then save that blob of data as a database entry. Then on level load, deserialize the JSON and populate your game objects with the data pulled from the JSON.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .