MicrosoftInternetExplorerでは、ローカル変数でparentを使うとappendChildが使えなくなる…。
-<About collision checking>(このあたりはまだドラフト)
-ステージオブジェクトの最小単位を8x8とする。
+IEではXMLHTTPRequest.onreadystatechangeのthisの値が他と異なるようだ。
+なので、
+request.onreadystatechange = function(){
+ と無名関数で書いて、内部でrequestインスタンスを参照
+};
+しないとうまく動かない。
*/
//
//定数
//
-var URL_PCD_Root = "http://192.168.6.242/pcd2013dev/www/";
+//var URL_PCD_Root = "http://192.168.6.242/pcd2013dev/www/";
+var URL_PCD_Root = "http://192.168.0.8/PCD2013GSCL/www/";
var URL_PCD_Auth = URL_PCD_Root + "auth.php";
var URL_PCD_Stage = URL_PCD_Root + "stage/";
var URL_PCD_Stage_Local = URL_PCD_Root + "./stage/";
this.timeStamp = 0;
//タイマーカウントの秒あたりの回数を設定
this.tickPerSecond = 60;
+ this.updateIntervalMs = 250;
//キーボード状態を格納するプロパティの設定
this.keyState = new Object();
this.keyState.upArrow = false;
timerTickEventListener.manager = this;
window.setInterval(timerTickEventListener, 1000/this.tickPerSecond);
timeStampTimerTickEventListener.manager = this;
- window.setInterval(timeStampTimerTickEventListener, 100);
+ window.setInterval(timeStampTimerTickEventListener, this.updateIntervalMs);
}
GameManager.prototype = {
//****プロトタイプ宣言****
timeStampTimerTick: function(){
//サーバーとの同期カウンタ・タイマー
//100msごとに呼ばれる
- this.timeStamp += 100;
- drawText(this.debugContext, "timeStamp:" + this.timeStamp, 0, 40);
+ this.timeStamp += this.updateIntervalMs;
+ drawText(this.debugContext, " timeStamp:" + this.timeStamp, 0, 40);
+
+ //update
+ if(this.userID != 0){
+ request = this.networkManager.CreateRequestObject();
+ request.onreadystatechange = function(){
+ //requestコールバックなのでthisはrequest!
+ //onloadedはステージプリロード用
+ switch(request.readyState){
+ case 0:
+ //console.log("XMLHttpRequest created.");
+ break;
+ case 1:
+ //console.log("open() called.");
+ break;
+ case 2:
+ //console.log("Response header received.");
+ break;
+ case 3:
+ //console.log("Response body receiving.");
+ break;
+ case 4:
+ //mainManager.debugOut("send() compleated.\n");
+ //mainManager.debugOut("status:" + this.status + ":" + this.statusText + "\n");
+ if(request.status == 0){
+ //alert("ネットワークにアクセスできません。" + this.status + ":" + this.statusText);
+ }else if((200 <= request.status && request.status < 300) || (request.status == 304)){
+ //console.log("ACK");
+ drawText(mainManager.debugContext, "ServertimeStamp:" + request.responseText, 0, 80);
+ }else{
+ //alert("サーバーがエラーを返しました。" + this.status + ":" + this.statusText);
+ }
+ break;
+ }
+ };
+ request.open('GET', URL_PCD_Root + "update.php?uid=" + this.userID);
+ this.networkManager.RequestObjectDisableCache(request);
+ request.send(null);
+ }
},
runStage: function(stage){
//****新たなステージを開始する****
loadStageFromNetwork: function(name, onLoaded){
//urlに存在するjavascriptファイルを利用してステージを作成する。
request = this.networkManager.CreateRequestObject();
- request.onLoaded = onLoaded;
- request.onreadystatechange = this.loadStageFromNetwork_HTTPStateChange
- request.open('GET', URL_PCD_Stage + name + ".js");
- request.send(null);
- },
- loadStageFromNetwork_HTTPStateChange: function(){
- //requestコールバックなのでthisはrequest!
- switch(this.readyState){
- case 0:
- //console.log("XMLHttpRequest created.");
- break;
- case 1:
- //console.log("open() called.");
- break;
- case 2:
- //console.log("Response header received.");
- break;
- case 3:
- //console.log("Response body receiving.");
- break;
- case 4:
- //mainManager.debugOut("send() compleated.\n");
- //mainManager.debugOut("status:" + this.status + ":" + this.statusText + "\n");
- if(this.status == 0){
- alert("ネットワークにアクセスできません。" + this.status + ":" + this.statusText);
- }else if((200 <= this.status && this.status < 300) || (this.status == 304)){
- //console.log("ACK");
- stage = new GameStage();
- eval(this.responseText);
- if(this.onLoaded != null){
- this.onLoaded(stage);
- } else{
+ request.onreadystatechange = function(){
+ //requestコールバックなのでthisはrequest!とは限らない(IE)
+ console.log("state:" + request.readyState);
+ switch(request.readyState){
+ case 0:
+ //console.log("XMLHttpRequest created.");
+ break;
+ case 1:
+ //console.log("open() called.");
+ break;
+ case 2:
+ //console.log("Response header received.");
+ break;
+ case 3:
+ //console.log("Response body receiving.");
+ break;
+ case 4:
+ //mainManager.debugOut("send() compleated.\n");
+ //mainManager.debugOut("status:" + this.status + ":" + this.statusText + "\n");
+ if(request.status == 0){
+ alert("ネットワークにアクセスできません。" + request.status + ":" + request.statusText);
+ }else if((200 <= request.status && request.status < 300) || (request.status == 304)){
+ //console.log("ACK");
+ var stage = eval(request.responseText);
mainManager.runStage(stage);
+ }else{
+ alert("サーバーがエラーを返しました。" + request.status + ":" + request.statusText);
}
- }else{
- alert("サーバーがエラーを返しました。" + this.status + ":" + this.statusText);
- }
- break;
- }
+ break;
+ }
+ };
+ request.open('GET', URL_PCD_Stage + name + ".js");
+ this.networkManager.RequestObjectDisableCache(request);
+ //IEで使えない…
+ //console.log("reqObject:" + request.toString());
+ request.send(null);
},
debugOut: function(str){
if(!/*@cc_on!@*/false)
NetworkManager.prototype = {
//from http://hakuhin.jp/js/xmlhttprequest.html
CreateRequestObject: function(){
+ var rq = null;
// XMLHttpRequest
try{
// XMLHttpRequest オブジェクトを作成
- return new XMLHttpRequest();
+ rq = new XMLHttpRequest();
}catch(e){}
// Internet Explorer
try{
- return new ActiveXObject('MSXML2.XMLHTTP.6.0');
+ rq = new ActiveXObject('MSXML2.XMLHTTP.6.0');
}catch(e){}
try{
- return new ActiveXObject('MSXML2.XMLHTTP.3.0');
+ rq = new ActiveXObject('MSXML2.XMLHTTP.3.0');
}catch(e){}
try{
- return new ActiveXObject('MSXML2.XMLHTTP');
+ rq = new ActiveXObject('MSXML2.XMLHTTP');
}catch(e){}
- // 未対応
- return null;
- },
- HTTPStateChange: function(){
- //requestコールバックなのでthisはrequest!
- switch(this.readyState){
- case 0:
- //console.log("XMLHttpRequest created.");
- break;
- case 1:
- //console.log("open() called.");
- break;
- case 2:
- //console.log("Response header received.");
- break;
- case 3:
- //console.log("Response body receiving.");
- break;
- case 4:
- //console.log("send() compleated.");
- //console.log("status:" + this.status + ":" + this.statusText);
- if(this.status == 0){
- console.log("Error");
- }else if((200 <= this.status && this.status < 300) || (this.status == 304)){
- console.log("ACK");
- }else{
- //console.log("NAK");
- }
- alert(this.responseText);
- break;
+ if(rq == null){
+ return null;
}
- }
+ return rq;
+ },
+ RequestObjectDisableCache: function(rq){
+ //call after open request.
+ //disable cache
+ //http://vird2002.s8.xrea.com/javascript/XMLHttpRequest.html
+ rq.setRequestHeader('Pragma', 'no-cache'); // HTTP/1.0 における汎用のヘッダフィールド
+ rq.setRequestHeader('Cache-Control', 'no-cache'); // HTTP/1.1 におけるキャッシュ制御のヘッダフィールド
+ rq.setRequestHeader('If-Modified-Since', 'Thu, 01 Jun 1970 00:00:00 GMT');
+
+ },
}
//
return canvas;
}
-function createCanvas(id, width, height, x, y, z, parent)
-{
- //識別名idで
- //width * heightの大きさのCanvasを
- //(x,y,z)に生成する。
- //parentには、Canvasタグを包含することになるDOMオブジェクトのidを指定する。
- canvas = document.createElement("canvas");
- parent = document.getElementById(parent);
-
- canvas.id = id;
-
- parent.appendChild(canvas);
-
- canvas.style.position = "absolute";
- canvas.style.top = y + "px";
- canvas.style.left = x + "px";
- canvas.style.zIndex = z;
-
- canvas.width = width;
- canvas.height = height;
-
- return canvas;
-}
-
function createDOMObject(typestr, idstr, parentidstr)
{
dobj = document.createElement(typestr);