Simplifying data sharing with BroadcastValues and SyncValues This allows each feature to be lifted independently to another Lens Studio project. As Packets.js takes care of the messaging between players, each feature doesn’t need to know about the other features needs. In this example, you can see Packets.js being used for features like avatars, block placing, state sharing. This allows you to create a decoupled realtime feature or send and catch one of unique messages (like sending a projectile). ![]() For example, you could have messages like. Then in the onMessage callback you can use the code function to make it a JavaScript object. Using JSON to send messagesĪn even better way to do this would be to use the JavaScript function JSON.stringify to turn a JavaScript object into a string for sending (as sendMessage sends strings). In this situation, you could start the message with the word ‘chat’ or ‘block’. But what if you wanted more realtime features than just chat messages? For example, if you wanted to send chat messages and place block messages? Now you would need to put something in each message to identify it as being a chat message or a place block message. Players would send and receive their chat messages using the sendMessage function and onMessageReceived callback. (In reality, we wouldn’t do this as Connected Lens automatically allows players to chat with voice or text using the Snapchat Connect Lens interface). Let’s imagine we are building a Lens with text chat capability. This module gives the Lens access to a MultiplayerSession for sending and receiving messages (using the connectedLensModule’s sendMessage function and the connectedLensSessionOption’s onMessageReceived callback) Passing different types of messages between players Message passing between playersĪs the Lens creator, you will want to consider how you pass messages between players to realize your share AR experience. This Lens can then invite other Snapchat users to open the Lens and join the MultiplayerSession that it has created. A MultiplayerSession gets created by a Lens when a player opens the Lens from the Lens carousel. It is this multiplayer session that the Lens uses to send messages to the other connected users/Lenses. Therefore, the key to a Connect Lens experience is the ability to send messages to a group of players who are connected at the same time.Ī group of players come together in realtime by having their Lenses connected to a single multiplayer session. The magic of inhabiting a shared augmented reality version of the world with other happens by having each player share their actions with every other connected player.įor example, when one player places a block in their Lens, the Lens needs to tell the other Lens to place the block too. Notes on sharing data between players Creating a shared AR experience using multiplayer sessions
0 Comments
Leave a Reply. |