Multiplayer
From GiderosMobile
Multiplayer
There are three ways to implement multiplayer games:
- Server Mode: Dedicated server with public IP
- Host Mode: One player is the host, all other players connect to them
- Shared Mode: Cloud Room has StateAuthority
Server Mode and Shared Mode can be daunting and won't be covered here. Some multiplayer platforms SDK you can check:
- https://noobhub.co.za/
- https://github.com/Overtorment/NoobHub
- https://www.smartfoxserver.com/
- https://github.com/EsotericSoftware/kryonet
And to get you started using Noobhub:
Host Mode
Host Mode is the easiest way to get started with multiplayer. In order to implement it in Gideros, we will use the Gideros Unite Framework written by Arturs Sosins (@ar2rsawseen).
The Gideros Unite framework allows a host (server) and clients to connect over a Local Area Network.
Gideros Unite Framework
Some demo code:
-- we can get all devices that are connected to our network
local devices = {}
serverlink:addEventListener("device", function(e)
print(e.data.id, e.data.ip, e.data.host)
devices[e.data.id] = {}
devices[e.data.id].ip = e.data.ip
devices[e.data.id].name = e.data.host
end)
serverlink:getDevices()
-- add some methods, that could be called by other clients or server through network
-- draw something
serverlink:addMethod("draw", self.drawLine, self)
-- end drawing
serverlink:addMethod("end", self.stopDrawing, self)
-- clear drawing
serverlink:addMethod("clear", self.reset, self)
-- then you can call this methods when needed
serverlink:callMethod("clear")
serverlink:callMethod("draw", someX, someY)
-- or call method of specific device using its id
serverlink:callMethodOf("clear", 112233)
serverlink:callMethodOf("draw", someX, someY, 112233)
-- and when game is finished
serverlink:close()