{"id":40,"date":"2018-02-04T22:22:39","date_gmt":"2018-02-05T04:22:39","guid":{"rendered":"http:\/\/www.chroniclesoftright.com\/blog\/?p=40"},"modified":"2018-02-04T22:22:39","modified_gmt":"2018-02-05T04:22:39","slug":"basic-multiplayer","status":"publish","type":"post","link":"https:\/\/www.chroniclesoftright.com\/blog\/2018\/02\/04\/basic-multiplayer\/","title":{"rendered":"Basic multiplayer"},"content":{"rendered":"<p>Well that was a little faster than I thought.\u00a0 Here&#8217;s a screenshot of my very, very basic multiplayer support in action:<a href=\"http:\/\/www.chroniclesoftright.com\/blog\/wp-content\/uploads\/2018\/02\/multiplayer-2018.02.04.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-medium wp-image-41\" src=\"http:\/\/www.chroniclesoftright.com\/blog\/wp-content\/uploads\/2018\/02\/multiplayer-2018.02.04-300x103.png\" alt=\"\" width=\"300\" height=\"103\" srcset=\"https:\/\/www.chroniclesoftright.com\/blog\/wp-content\/uploads\/2018\/02\/multiplayer-2018.02.04-300x103.png 300w, https:\/\/www.chroniclesoftright.com\/blog\/wp-content\/uploads\/2018\/02\/multiplayer-2018.02.04-768x264.png 768w, https:\/\/www.chroniclesoftright.com\/blog\/wp-content\/uploads\/2018\/02\/multiplayer-2018.02.04-1024x353.png 1024w, https:\/\/www.chroniclesoftright.com\/blog\/wp-content\/uploads\/2018\/02\/multiplayer-2018.02.04.png 1862w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>That&#8217;s two browsers running the game side by side.\u00a0 For now, your player is represented by my nifty character model, and any other players are a gray sphere.\u00a0 So you can see in this screenshot that in the game on the left the sphere is where the player is in the game on the right, and vice versa.\u00a0 As each moves around it&#8217;s updated in real time on all other clients.\u00a0 My polling time is set at 1 second right now, so the server only sends out an update once per second and the movement is very jumpy, but there are ways to improve that, the simplest of which is to simply decrease the polling period.<\/p>\n<p>Using <a href=\"https:\/\/socket.io\/\" target=\"_blank\" rel=\"noopener\">socket.io<\/a> and <a href=\"http:\/\/nodejs.org\" target=\"_blank\" rel=\"noopener\">node<\/a> this was almost disturbingly easy.\u00a0 It took me a bit to get my head wrapped around the concepts, but overall this is a very simple thing to do with these tools.\u00a0 I also relied pretty heavily on a series of <a href=\"https:\/\/rainingchain.com\/tutorial\/nodejs\" target=\"_blank\" rel=\"noopener\">tutorials<\/a> made by the guy who made <a href=\"http:\/\/www.rainingchain.com\" target=\"_blank\" rel=\"noopener\">Raining Chain<\/a>.\u00a0 The tutorials were very helpful, and the game itself is also quite entertaining, so if you&#8217;ve never played it, go check it out.<\/p>\n<p>Still many things to do, but it&#8217;s exciting to get basic multiplayer support added so quickly and easily.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Well that was a little faster than I thought.\u00a0 Here&#8217;s a screenshot of my very, very basic multiplayer support in action: That&#8217;s two browsers running the game side by side.\u00a0 For now, your player is represented by my nifty character model, and any other players are a gray sphere.\u00a0 So you can see in this&hellip;<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-40","post","type-post","status-publish","format-standard","hentry","category-feature-development"],"_links":{"self":[{"href":"https:\/\/www.chroniclesoftright.com\/blog\/wp-json\/wp\/v2\/posts\/40","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.chroniclesoftright.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.chroniclesoftright.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.chroniclesoftright.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.chroniclesoftright.com\/blog\/wp-json\/wp\/v2\/comments?post=40"}],"version-history":[{"count":1,"href":"https:\/\/www.chroniclesoftright.com\/blog\/wp-json\/wp\/v2\/posts\/40\/revisions"}],"predecessor-version":[{"id":42,"href":"https:\/\/www.chroniclesoftright.com\/blog\/wp-json\/wp\/v2\/posts\/40\/revisions\/42"}],"wp:attachment":[{"href":"https:\/\/www.chroniclesoftright.com\/blog\/wp-json\/wp\/v2\/media?parent=40"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.chroniclesoftright.com\/blog\/wp-json\/wp\/v2\/categories?post=40"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.chroniclesoftright.com\/blog\/wp-json\/wp\/v2\/tags?post=40"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}