AS3. How to set-up players for real-time game?

橙三吉。 提交于 2019-12-13 06:49:09

问题


I'm creating flash fighting game 1vs1.

Here is Hero (local-player) and Enemy (remote-player). How I need to setup them correctly that after connection to arena they will be spawned successfully?

I mean if player 1 connects to arena he should be declared as Hero (local-player) and for him player 2 should look like Enemy (remote-player).

The same for player 2. He should be declared as Hero (local-player) and for him player 1 should look like Enemy (remote-player).

Here are 2 character's templates to choose and here is code:

public function selectHero(what:int):void {
    // this is called with correct "what", design yourself. I use array index
    var whatHero:Class = heroes[what]; // get selected hero symbol
    if (Hero && Hero.parent) Hero.parent.removeChild(Hero);
    // clean up previous hero. Drop listeners here, if any
    Hero = new whatHero(); // get new hero
    // process as usual, don't forget to "addChild(Hero)" somewhere
    create_hero();
}

    function choosePlayer(event:MouseEvent):void {
        selectHero(0); // here choose first template
        start(event);
        }

     function create_hero()
     {
        addChild(Hero);
     }

So Hero added to stage (It is local-player).

This is how I declare Enemy:

public var Enemy:Priesas = new Priesas; //Priesas is instance name of Enemy

So as I understand I don't need to use addChild(Enemy); because will be added just template, how to add remote-player Hero (from other computer) that will be declared as Enemy? Or something like that.

This game is creating for Facebook. For that is needed AppWarp? Thank you for answers.


回答1:


Yes, you would need AppWarp to connect the two players and to exchange messages between them. This seems similar to one of the samples of AppWarp (smiley space shooter). Have you already explored the samples and documentation?

http://appwarp.shephertz.com/game-development-center/actionscript3-game-developers-home/



来源:https://stackoverflow.com/questions/21391044/as3-how-to-set-up-players-for-real-time-game

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!