Création d'un jeu de type pacman à l'aide de Flash (AS3). Il y a 3 joueurs en compétition pour manger le plus de points. À l'heure actuelle, lorsqu'un joueur mange un point, sur l'écran de ce joueur, le point disparaît (mais seulement pour une seconde) et apparaît à nouveau sur l'écran. L'autre joueur qui joue ne voit pas que le point a disparu et a réapparu. En utilisant hitTestObject, lorsqu'un joueur touche un point, le point ne devrait plus être vu sur la scène. J'utilise un objet partagé pour créer cet environnement de jeu multi-joueurs. Je suis nouveau dans l'utilisation de SharedObject et AS3.Création d'un jeu de type pacman à l'aide de Flash (AS3)
public function PlayerSelect()
{
nc = new NetConnection();
nc.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
nc.connect("rtmp://r92kq5ew6.rtmphost.com/g1");
select_screen.btn1.addEventListener(MouseEvent.MOUSE_UP, select1);
select_screen.btn2.addEventListener(MouseEvent.MOUSE_UP, select2);
select_screen.btn3.addEventListener(MouseEvent.MOUSE_UP, select3);
for(var i=0; i<circ_num; i++) {
circle_ary[i] = new Circle(); //linkage in the library
circle_ary[i].x=0;
circle_ary[i].y=0;
stage.addChild(circle_ary[i]);
}
}
public function netStatusHandler(event:NetStatusEvent):void
{
trace("connected is: " + nc.connected);
trace("event.info.level: " + event.info.level);
trace("event.info.code: " + event.info.code);
switch (event.info.code)
{
case "NetConnection.Connect.Success":
trace("Congratulations! you're connected");
so = SharedObject.getRemote("ballPosition", nc.uri, false);
so.connect(nc);
so.addEventListener(SyncEvent.SYNC, syncHandler);
break;
case "NetConnection.Connect.Rejected":
case "NetConnection.Connect.Failed":
trace ("Oops! you weren't able to connect");
break;
}
}
private function stageInit():void
{
for(var i=0; i<circ_num; i++) {
pos_ary[i] = new Array();
pos_ary[i][0] = Math.random()*stage.stageWidth;
pos_ary[i][1] = Math.random()*stage.stageHeight;
so.setProperty("dots", pos_ary);
}
}
// update clients when the shared object changes
private function syncHandler(event:SyncEvent):void
{
// when a sync event is fired
// update the information for all clients
//here we update states for all players
for (var i:String in so.data) //run through all players in the data array
{
if (i == "dots")
{
for(var j=0; j<circ_num; j++)
{
circle_ary[j].x = so.data["dots"][j][0];
circle_ary[j].y = so.data["dots"][j][1];
//pos_ary[j][0] = so.data["dots"][j][0];
//pos_ary[j][i] = so.data["dots"][j][i];
}
}
else if(player_ary[i] == undefined)
makePlayer(i); //if the player does not exist we create it
else if (i!=me) //we do not need to update our selves from the server, just everyone else
{
player_ary[i].x = so.data[i][0]; //here I am treating data like a 2d array
player_ary[i].y = so.data[i][1]; //where [i][0] is x poition data and
} //[i][1] is y position data
}
}
// function eatCircle --------------------------------------------------------------
function eatCircle():void {
for (var j:int = 0; j<circ_num; j++)
{
if (player_ary[me].hitTestObject(circle_ary[j]))
{
trace ("I ate the circle");
circle_ary[j].y = -100;
pos_ary[j][1] =-100;
so.setProperty("dots", pos_ary);
}
}
}
Quel est le problème? – Aaron
Est-ce l'autre joueur qui ne le voit pas disparaître? Ce n'est pas clair à 100% que ce n'est pas votre intention. Il suffit de relire la question et ça pourrait être ça? – Aaron