Database,Socket.io,MMORPG

553 views
Skip to first unread message

Szabó Dávid

unread,
Aug 31, 2012, 1:11:26 PM8/31/12
to craf...@googlegroups.com
Hi all!
I started developing an mmorpg.

Is craftyjs is good to use with socket.io (nodejs)?

And if yes what database module should i use?

When i move with a character.i should check the collisson in client or in server?

Thanks! 

Søren Bramer Schmidt

unread,
Aug 31, 2012, 1:32:32 PM8/31/12
to craf...@googlegroups.com
You should run all game logic on the server to avoid players cheating. In the beginning you could just send input from client to server, render game on server and send coordinates to the clients.
When that is working you can begin to simulate the game on the clients to make a smoother experience, but still correcting for authoritative state received from the server.

There is nothing build into Crafty to support this, but there shouldn't be anything getting in the way either.

John Wilkinson

unread,
Aug 31, 2012, 2:13:55 PM8/31/12
to craf...@googlegroups.com
Crafty works great with socket.io! I've been working on a very similar project myself in my free time when I have leftover programming energy after work (rarely).

https://github.com/jcwilk/genesis (or see it in action [currently only seems to work in firefox?] with stock randomly borrowed graphics http://jcwilk-genesis.herokuapp.com/ )

Dávid - I've so far had success with having an Avatar base component which is "inherited" by RemoteAvatar and LocalAvatar, the latter being the local character which is controlled directly with the keyboard, the former being applied to the characters which are synced from the server.

So far I'm just putting full trust in the data received from the client for simplicity... I plan to put a "checking" algorithm on the server eventually which will give the client a bit of wiggle room but if they start claiming to move in a manner that's impossible (ie, hacking and jumping around faster than you should be able to move) then it could truncate their movement. Ideally I'd want to avoid doing that unless they're clearly hacking though to make the client as smooth and unjumpy as possible.

I'm mainly focusing on the infrastructure of syncing data from arbitrary crafty entities to and from the server in an organized way right now... And I'm not even persisting data on the server, just keeping it all in memory in objects so it's zippy as hell but whenever the server restarts all the data is lost, which doesn't matter at all right now since there's a single room with no objects except for players.

Anyways, please feel free to fork my github project as a starting point, would love to be able to share bits of code with another project. Otherwise, looking forward to seeing what you come up with, and feel free to ask any questions about my project if you have interest.

Szabó Dávid

unread,
Aug 31, 2012, 2:30:05 PM8/31/12
to craf...@googlegroups.com
I think i sent you private messages,or umm.I don't really know,still new to this groups.google.com sorry =)
So thanks,this is a good start point for me =)

John Wilkinson

unread,
Aug 31, 2012, 2:36:51 PM8/31/12
to craf...@googlegroups.com
Great, feel free to file issues in my github repo about anything that's unclear or just ask. There's a "chat" branch with partial progress towards chat support, but the code in that branch is very messy right now and needs a lot of reorganization and enhancements to the data pipeline to be able to support it cleanly. I should be able to clean up the chat code and get it merged into the master branch and deployed to heroku sometime in the next couple days though, just need a block of focused time to noodle over the data flow.

As for the google group stuff, if you want to send an email to the crafty group send it to craf...@googlegroups.com or just email my email directly if you just want me to get it. If our conversation gets too far off topic of crafty as a framework then we should probably take it off the mailing list so we don't bother people, but they probably won't be bothered by a short thread about the goal of an MMORPG via crafty.

Szabó Dávid

unread,
Aug 31, 2012, 2:45:22 PM8/31/12
to craf...@googlegroups.com
Mostly i coded in PHP not in javascript.

So just a simple question.

var toData = function(){
return {
id: id,
data: data
}
};

This can't be simply: var toData = {id:id,data:data}; ?
Or i misunderstood something?

Matt Petrovic

unread,
Aug 31, 2012, 2:47:41 PM8/31/12
to craf...@googlegroups.com
it's now a function that will return the current values of id and data. It's not very useful like that, but if it can be accessed outside the scope of id and data, it becomes more useful.

John Wilkinson

unread,
Aug 31, 2012, 2:52:55 PM8/31/12
to craf...@googlegroups.com
It's not quite the same... But both are valid syntax. They serve different purposes:

id = 5
data = {some: 'data'}

var toData = function(){
  return {
    id: id,
    data: data
  }
};

toData() // returns {id: 5, data: {some: 'data'}}

toData   // returns a function

id = 10

toData() // returns {id: 10, data: {some: 'data'}}


As compared to...

id = 5
data = {some: 'data'}
var toData = {
  id: id,
  data: data
}

toData // returns {id: 5, data: {some: 'data'}}

id = 10

toData // Still returns {id: 5, data: {some: 'data'}}


The point is that when it's in a function, it creates and returns a new object with fresh copies of the variables everytime you call the function rather than being a static object which will go "stale" once the data that it's derived from changes.

John Wilkinson

unread,
Aug 31, 2012, 2:56:58 PM8/31/12
to craf...@googlegroups.com
Note that all that toData fromData stuff is still experimental and hasn't quite gelled yet... I'm planning on moving the id inside of the data rather than next to it for consistency. If you check out the jasmine specs inside of the /spec/ folder that might help to better describe its behavior (although it takes a little bit to figure out how to read the jasmine specs, but once you do the descriptions of the tests are very informative)

Szabó Dávid

unread,
Aug 31, 2012, 3:01:21 PM8/31/12
to craf...@googlegroups.com
Thanks a lot!

Szabó Dávid

unread,
Aug 31, 2012, 4:41:43 PM8/31/12
to craf...@googlegroups.com
I want my MMORPG to work in tiles.

So i wrote two component for this.

What i wanted is that when the player press W,A,S,D then the character move 16 pixels.

Is this ok or there is a better way to do this?

Thanks!

Here is the link for it : http://pastebin.com/Lx8fCe9Z

Szabó Dávid

unread,
Aug 31, 2012, 4:47:18 PM8/31/12
to craf...@googlegroups.com
Ohh another question =)

What is the best way to make the player not going out of the canvas?

Should i make a solid wall outside of the canvas?

Or there is something in the CraftyJS for this?

Thanks everything !!!
Message has been deleted

John Wilkinson

unread,
Sep 1, 2012, 1:36:21 AM9/1/12
to craf...@googlegroups.com
I'm new around here too so I can't say for sure if there are existing tools, but a place to start is by downloading the Crafty source and skimming through the files under src/

There's some interesting isometric stuff in diamondiso.js and isometric.js, and lots of control-related code in controls.js, that's where I found "multiway" which i use in my game.

Take a look at the way the isometric stuff maps from position to x/y too, it might make your code a bit more maintainable if you avoided doing any relative adjustments in pixels... in other words, rather than doing:

- take the current x,y
- add 16 to it
- set to the new x,y

you could do

- take the current tile coordinate (ie, row 5, column 4)
- add 1 to it to get the next tile over
- store the new tile coordinate for future adjustments
- translate tile coordinate to x,y (eg, row * 16, column * 16)
- set position to x,y


As for keeping the player in the canvas, yeah setting tiles around the outside wall with "solid" on them and then setting "Collision" on the player is how that's done I believe. Check out the "rpg" example under "demos/" in the source to see it implemented: https://github.com/craftyjs/Crafty/blob/master/demos/rpg/game.js

I'm not bothering with it in my game until I get the tiles populated from server data though

On Fri, Aug 31, 2012 at 2:22 PM, Szabó Dávid <david....@gmail.com> wrote:
Some fix for tileMove and Controls.


Szabó Dávid

unread,
Sep 1, 2012, 12:42:18 PM9/1/12
to craf...@googlegroups.com
I've tried to do the viewport follow the local player.

But it laggs like hell =(
What can be the problem?
Or what is happenning while the camera follows the player?

John Wilkinson

unread,
Sep 1, 2012, 1:53:01 PM9/1/12
to craf...@googlegroups.com

I haven't yet tried this, but there are some threads that talk about scrolling and such if you search for them. If you could write a jsfiddle with a minimum implementation of your scrolling code then you could probably get some input from the more experienced crafty folk

jplur

unread,
Sep 2, 2012, 10:50:08 AM9/2/12
to craf...@googlegroups.com
I was messing with scrolling viewports a year ago and came to the conclusion that it's too slow to use for large amounts of entities. Perhaps some of the Crafty rewrites planned for layers and multiple viewports would help this, but personally I've been thinking about webGL for any game idea that involves following the player around on a large map.

Søren Bramer Schmidt

unread,
Sep 2, 2012, 11:05:48 AM9/2/12
to craf...@googlegroups.com
With hw accelerated css 3d transforms it is basically free to move entities, so i see no reason we shouldn't be able to implement this in a performant way at some point.

Matt Petrovic

unread,
Sep 2, 2012, 11:56:48 AM9/2/12
to craf...@googlegroups.com
I don't understand this. Were you using DOM or canvas? The vast majority of the work involved with moving a DOM camera is done by the browser. It should be very fast.

jplur

unread,
Sep 2, 2012, 12:33:08 PM9/2/12
to craf...@googlegroups.com, mpet...@guneva.net
Take a look:  http://jsfiddle.net/GFTyz/ 
Perhaps I'm doing something wrong with moving the viewport, but it's pretty poor as either DOM or Canvas

G

unread,
Sep 2, 2012, 12:45:46 PM9/2/12
to craf...@googlegroups.com

In the game I'm working on, the viewport is following the player on a 2048x2048 map with 10-20 entities on screen at once, using DOM with Crafty.canvas.init not being called.  I've been playing it for a few months now, and I rarely see viewport lag - unless there is some other section of code that is slowing everything down.  So, I'd guess it's not the viewport causing the lag in your game, but it may be how many entities there are on screen.  How many entities are on screen?
Or do you have a jsfiddle of viewport lag?

TheGrak

unread,
Sep 2, 2012, 12:55:43 PM9/2/12
to craf...@googlegroups.com
Looking at your fiddle, I can tell you its because of how many crafty entities there are on screen.
You are creating a background of 100*100 crafty entities.
I have found that it is much faster to create 1 crafty entity, then load an image of the background into that.
Here is a fiddle illustrating this approach: http://jsfiddle.net/FpNaF/
Check out the community cookbook, it has a lot of helpful examples.

Matt Petrovic

unread,
Sep 2, 2012, 12:57:25 PM9/2/12
to craf...@googlegroups.com
even that shouldn't matter. The entities themselves aren't changing. Just the viewport. It should still be extremely fast to move the viewport laterally.

TheGrak

unread,
Sep 2, 2012, 1:04:29 PM9/2/12
to craf...@googlegroups.com, mpet...@guneva.net
I thought that maybe the Crafty.e.camera approach was slowing it down, nope: http://jsfiddle.net/caJ3r/
Pretty sure it's the # of entities, but I'd love to have the viewport more optimized/faster.  :)

Matt Petrovic

unread,
Sep 2, 2012, 1:10:36 PM9/2/12
to craf...@googlegroups.com
The fiddle performs well in Chrome, but poorly in Firefox. I'll be looking at this today.

For future reference, when making fiddles about issues with the engine, use the full version of the source. It's impossible to debug minified code.

TheGrak

unread,
Sep 2, 2012, 1:12:37 PM9/2/12
to craf...@googlegroups.com, mpet...@guneva.net
With 10*10 array of entities, there is no lag: http://jsfiddle.net/WJDPw/
I'd love to be able to have 10,000 (100*100) crafty entities in the browser without lag.
Anyone know how to do that?

jplur

unread,
Sep 2, 2012, 1:14:39 PM9/2/12
to craf...@googlegroups.com, mpet...@guneva.net
Will do, and looking forward to hearing what you find out.

On a hunch I'm guessing viewport changes trigger draw updates without getting a map hash query to limit.

Matt Petrovic

unread,
Sep 2, 2012, 1:23:57 PM9/2/12
to craf...@googlegroups.com
Running crafty.canvas.init will slow it down, even if there's no canvas entities. Taking this out brings the entire enterframe down to 2 ms in Chrome, which is well within the 20ms limit for 50 fps.

I'm having trouble testing firefox, since it keeps crashing when I load the jsfiddle.

Matt Petrovic

unread,
Sep 2, 2012, 1:34:34 PM9/2/12
to craf...@googlegroups.com
I managed to get Firefox working for a bit. The entirety of your camera.set function takes 0.05ms to run. It's not the viewport. The browser itself is having trouble chugging through all those DOM objects. 

jplur

unread,
Sep 2, 2012, 2:22:59 PM9/2/12
to craf...@googlegroups.com, mpet...@guneva.net
Ok I see.

For comparison you can move that many dom elements around if you move the parent element

That runs very fast with 100^2 divs, perhaps something to think about for the viewport.
Reply all
Reply to author
Forward
0 new messages