无法理解使用cocos2d游戏在设备之间传输数据

时间:2012-05-29 13:32:05

标签: android bluetooth cocos2d-android game-development

我已经在Android开发人员上完成了蓝牙CHAT示例,现在我正在设计游戏并需要在设备之间传输坐标。我正在使用cocos2d,现在如何通过蓝牙在其他设备上发送数据。我需要在这个游戏中应用蓝牙聊天应用程序,但是如何?我不明白如何实现它。任何建议都非常感谢...如果你没有得到我想要的东西,请问任何问题......

    public boolean ccTouchesEnded(MotionEvent event)
   {
    boolean get=false;
    //int y=0;
    // Choose one of the touches to work with
  CGPointlocation=CCDirector.sharedDirector().convertToGL(CGPoint.ccp(event.getX(),event.get;
    if(y==0)    
    {get=shootarrow(location);
    y=1;
    return get;}
    else if(y==1)
        {get=shootme(location);
        y=0;
        return get;
        }
    return get;
}

public boolean shootme(CGPoint loc){

    // Set up initial location of projectile
    CGSize winSize = CCDirector.sharedDirector().displaySize();
    CCSprite projectile = CCSprite.sprite("ah2.png");
    projectile.setPosition(CGPoint.ccp(650,180));

    CCSprite player2 = CCSprite.sprite("Ply2.png");
    player2.setPosition(CGPoint.ccp(winSize.width / 2.0f,320));

 // Determine offset of location to projectile
    int offX = (int)(loc.x - projectile.getPosition().x);
    int offY = (int)(loc.y - projectile.getPosition().y);
    if (offX >= 0)
        return true;
    if (offY <= -7)
        return true;
    addChild(projectile);
    addChild(player2);
    projectile.setTag(2);
    _projectiles.add(projectile);

    // Determine where we wish to shoot the projectile to
    int realX = (int)(-(winSize.width + (projectile.getContentSize().width / 2.0f)));
    float ratio = (float)offY / (float)offX;
    int realY = (int)((realX * ratio) + projectile.getPosition().y);
    CGPoint realDest = CGPoint.ccp(realX, realY);

 // Determine the length of how far we're shooting
    int offRealX = (int)(realX - projectile.getPosition().x);
    int offRealY = (int)(realY - projectile.getPosition().y);
    float length = (float)Math.sqrt((offRealX * offRealX) + (offRealY * offRealY));
    float velocity = 680.0f / 1.0f; // 480 pixels / 1 sec
    float realMoveDuration = length / velocity;

 // Move projectile to actual endpoint
    projectile.runAction(CCSequence.actions(
            CCMoveTo.action(realMoveDuration, realDest),
            CCCallFuncN.action(this, "spriteMoveFinished")));
    Context context = CCDirector.sharedDirector().getActivity();
    return true;

}

0 个答案:

没有答案