Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use Nearby Service to make games online at close range

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly explains "how to use Nearby Service to make the game online in close range". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to use Nearby Service to make the game online in close range".

Development preparation

Before    integrates Nearby Service, you need to complete the following preparatory work

Configure AppGallery Connect

Open short-range communication service

Integrated SDK

Configuration obfuscation script

For more information about   , please refer to Development preparation.

How to use Nearby Service

  , let's first take a look at the interface comparison between Kryonet and Nearby Service:

| | Kryonet |

| |-|-|

| | start broadcasting | bind |

| | start scanning | discoverHost |

| | request connection | connect |

| | connection succeeded | connected |

| | disconnect | disconnected |

| | receive data | received |

| | send data | Send |

The interfaces of    Nearby Service and Kryonet are consistent. Replace the interface of Kryonet with that of Nearby Service, and do some parameter conversion according to the differences in parameter types.

Permission application

   because Nearby Service will use Bluetooth discovery, WIFI hotspot creation and other operations, so you need to show to the user to apply for some permissions. The code is as follows:

Compile, load, debug

After completing the above business code,    can compile, generate apk, install it on two or more Android 8 Android phones and run it. For detailed development steps, please refer to Codelab.

Achievement presentation

One side of the    clicks "Creat a Game" and the other clicks "Join a Game" to discover each other. After the discovery is successful, the host clicks "GO!" Button to start the game. Swipe the screen to control the green snake to turn to get more food, and the snake fails when its head hits an obstacle.

Thank you for your reading, the above is the content of "how to use Nearby Service to make the game close online". After the study of this article, I believe you have a deeper understanding of how to use Nearby Service to make the game close online, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report