Уважаемые флешеры, как добиться скорости соединения, загружаю в flash персонаж и двигаю стрелками. Все работает, но скорость очень низкая. Замеряю fps , успевает разогнаться до 11, в другом направлении до 2-3. Если бы передача была с одной скоростью в обе стороны одинаковая я бы понял. Почему когда открываешь вторую флешку персонаж начинает двигаться в 5 раз медленнее , что настроения нет продолжать. Что я не так передаю? Код:
Код:
package {
import flash.events.NetStatusEvent;
import flash.net.NetConnection;
import flash.net.NetGroup
import flash.net.GroupSpecifier;
import flash.events.Event;
import flash.display.MovieClip;
import alternativa.engine3d.collisions.EllipsoidCollider;
import flash.geom.Vector3D;
import alternativa.engine3d.core.Object3D;
import flash.text.TextField;
import flash.text.TextFormat;
import flash.utils.Timer;
import flash.events.TimerEvent;
public class GameMain extends MovieClip{
public var nc:NetConnection;
public var group:NetGroup;
public var world:GameWorld;
private var char2:Character;
private var char:Character;
private var controller:GameController;
public var scens:Object3D;
public var displacement:Vector3D;
public var speed:int;
public var left:Boolean;
public var down:Boolean;
public var inter:int;
public var right:Boolean;
public var up:Boolean;
public var obj:Object = {};
public var arrayNeigh:Array = [];
private var collider:EllipsoidCollider;
public var text1:TextField;
public var text2:TextField;
public var textTransform:TextFormat;
private var count1:int = 0;
private var count:int = 0;
public var timer:Timer = new Timer(1000, 0);
public var fps:Number = 0;
public function GameMain() {
nc = new NetConnection();
nc.addEventListener(NetStatusEvent.NET_STATUS, netStatus);
nc.connect("rtmfp:");
scens = new Object3D();
world = new GameWorld(scens);
char2 = new Character(stage, world);
addChild(char2);
char = new Character(stage, world);
controller = new GameController(stage, char,this);
addChild(char);
collider = new EllipsoidCollider(25, 25, 25);
text1 = new TextField();
addChild(text1);
text2 = new TextField();
addChild(text2);
textTransform = new TextFormat();
textTransform.color = 0xff0000;
textTransform.size = 24;
text1.x = 275;
text1.y = 5;
text2.x = 5;
text2.y = 5;
addEventListener(Event.ENTER_FRAME, efEvent);
timer.start();
timer.addEventListener(TimerEvent.TIMER, time);
}
public function netStatus(event:NetStatusEvent):void{
switch(event.info.code){
case "NetConnection.Connect.Success":
setupGroup();
break;
case "NetGroup.Connect.Success":
//setupGroup();
break;
case "NetGroup.Posting.Notify":
char2.containerCharacter.x = event.info.message.posx;
char2.containerCharacter.y = event.info.message.posy;
char2.containerCharacter.rotationZ = event.info.message.rotZ;
text1.text = (count1+count).toString()+" : "+event.info.message.schet.toString();
text1.setTextFormat(textTransform);
text2.text = " fps: "+event.info.message.fpss.toString();
text2.setTextFormat(textTransform);
break;
case "NetGroup.Neighbor.Connect":
arrayNeigh.push(event.info.neighbor);
break;
case "NetGroup.Neighbor.Disconnect":
for(var j:int = 0; j < arrayNeigh.length; j ++){
if(arrayNeigh[j] == event.info.neighbor){
arrayNeigh.splice(j, 1);
}
}
break;
}
}
public function time(e:TimerEvent):void{
fps = 0;
}
public function efEvent(e:Event):void {
fps++;
if(char.containerCharacter!=null){
displacement = new Vector3D( -speed * Math.sin(char.containerCharacter.rotationZ), speed * Math.cos(char.containerCharacter.rotationZ));
if(down){
if(speed<14){
speed+=5;
}
char.containerCharacter.x += displacement.x;
char.containerCharacter.y += displacement.y;
}
if(up){
if(speed>7){
speed-=5;
}
char.containerCharacter.x -= displacement.x;
char.containerCharacter.y -= displacement.y;
}
if(left){
if (up) {
char.containerCharacter.rotationZ -= 0.05;
} else if (down) {
char.containerCharacter.rotationZ += 0.05;
}
}
if(right){
if (up) {
char.containerCharacter.rotationZ += 0.05;
} else if (down) {
char.containerCharacter.rotationZ -= 0.05;
}
}
char.contain.x += (char.containerCharacter.x - char.contain.x) * 0.3;
char.contain.y += (char.containerCharacter.y - char.contain.y) * 0.3;
char.contain.z += (char.containerCharacter.z - char.contain.z) * 0.3;
char.contain.rotationY += (char.containerCharacter.rotationY - char.contain.rotationY) * 0.2;
char.contain.rotationX += (char.containerCharacter.rotationX - char.contain.rotationX) * 0.2;
char.contain.rotationZ += (char.containerCharacter.rotationZ - char.contain.rotationZ) * 0.2;
try{
for(var j:Number = 0; j < char.array.length; j ++){
var onGround:Boolean = collider.getCollision(char.bulletCoords, new Vector3D(char.displ.x, char.displ.y, 0), new Vector3D(), new Vector3D(), char2.containerCharacter);
if (onGround) {
count = 1;
}
}
}catch(e:Error){
trace("oshibka");
}
count1 = count1+count;
count = 0;
obj.posx = char.containerCharacter.x;
obj.posy = char.containerCharacter.y;
obj.rotZ = char.containerCharacter.rotationZ;
obj.schet = count1+count;
obj.fpss = fps;
obj.sender = group.convertPeerIDToGroupAddress(nc.farID);
group.post(obj);
}
}
public function setupGroup():void {
var groupspec:GroupSpecifier = new GroupSpecifier("game");
groupspec.postingEnabled = true;
groupspec.serverChannelEnabled = true;
groupspec.objectReplicationEnabled = true;
groupspec.routingEnabled = true;
groupspec.ipMulticastMemberUpdatesEnabled = true;
groupspec.addIPMulticastAddress("225.225.0.1:30000");
group = new NetGroup(nc,groupspec.groupspecWithAuthorizations());
group.addEventListener(NetStatusEvent.NET_STATUS,netStatus);
}
}
}