Android多人蓝牙 [英] Android multiplayer bluetooth

查看:108
本文介绍了Android多人蓝牙的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用带有Eclipse的蓝牙开发简单的多人游戏.
该游戏已经可以在单人模式下运行(使用AndEngine),但是现在我需要发送信息 设备之间.
有关在设备之间建立连接并将其链接的部分
已经在工作,可以在设备之间发送消息,但是现在我需要
在其他"设备上开始游戏,所以我认为解决方案正在发送Intent
使用蓝牙,但是我不确定这是否可行.
那么,如何同时在两个设备上启动游戏? (我不希望实时游戏,我只想比较每个玩家获得的硬币数量.)

I'm trying to develop a simple multiplayer game using bluetooth with Eclipse
The game is already working in single player mode (using AndEngine), but now I need to send information between devices.
The part that concerns establishing connection between devices,and link them
is already working, and I can send messages between devices, but now I need to
start the game on "the other" device, so I think that the solution is sending an Intent
using Bluetooth, but I'm not sure if this is possible or not.
So, how can I start the game in both devices at the same time? (I don't want the game in real time, I just want to compare the number of coins that each player gets).

非常感谢!

推荐答案

如果您看到"Uno"游戏,就会有所了解.在那里,他们没有使用蓝牙,而是使用WiFi. 从中学到的知识以及您等待Connection成功的其他一些蓝牙游戏.

If you see the "Uno" game, you'll get some idea. There, they aren't using Bluetooth, but WiFi. From that I learned, and some other bluetooth games that you wait for Connection successful.

如果您使用BluetoothChat应用程序作为参考,请使用Handler作为事件生成器来启动游戏.

If you're using BluetoothChat application as the reference, then use your Handler as your event generator to start your game.

    // The Handler that gets information back from the BluetoothChatService
private final Handler mHandler = new Handler() {
    @Override
    public void handleMessage(Message msg) {
        switch (msg.what) {
        case MESSAGE_STATE_CHANGE:
            if(D) Log.i(TAG, "MESSAGE_STATE_CHANGE: " + msg.arg1);
            switch (msg.arg1) {
            case BluetoothChatService.STATE_CONNECTED:
                setStatus(getString(R.string.title_connected_to, mConnectedDeviceName));
                mConversationArrayAdapter.clear();

                // DO YOUR ACTIVITY HERE .. .. 
                // May Be like ...  Intent intent = new Intent( ... )


                break;

这篇关于Android多人蓝牙的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆