2016-07-13 7 views
0

javascriptの値をあるページから別のページに割り当てることを試みていました。 コンセプトは、ユーザーがホイールを回転させ、タスクを取得して別のページにリダイレクトされるということです。そこで、彼は自分の仕事を見なければならない。シンプルに聞こえますが、私は困っています。ここで JavaScriptに値を送信してリダイレクトされたページに表示する方法

は、私がこれまで

マイgame.jsファイル

// the game itself 
 
var game; 
 
// the spinning wheel 
 
var wheel; 
 
// can the wheel spin? 
 
var canSpin; 
 
// slices (prizes) placed in the wheel 
 
var slices = 8; 
 
// prize names, starting from 12 o'clock going clockwise 
 
var slicePrizes = ["Task 8", "Task 1", "Task 2", "Task 3", "Task 4", "Task 5", "Task 6", "Task 7"]; 
 
// the prize you are about to win 
 
var prize; 
 
// text field where to show the prize 
 
var prizeText; 
 

 
window.onload = function() { \t 
 
    // creation of a 458x488 game 
 
\t game = new Phaser.Game(458, 488, Phaser.AUTO, ""); 
 
    // adding "PlayGame" state 
 
    game.state.add("PlayGame",playGame); 
 
    // launching "PlayGame" state 
 
    game.state.start("PlayGame"); 
 
} 
 

 
// PLAYGAME STATE 
 
\t 
 
var playGame = function(game){}; 
 

 
playGame.prototype = { 
 
    // function to be executed once the state preloads 
 
    preload: function(){ 
 
      // preloading graphic assets 
 
      game.load.image("wheel", "wheel.png"); 
 
\t \t game.load.image("pin", "pin.png");  
 
    }, 
 
    // funtion to be executed when the state is created 
 
    \t create: function(){ 
 
      // giving some color to background 
 
    \t \t game.stage.backgroundColor = "#880044"; 
 
      // adding the wheel in the middle of the canvas 
 
    \t \t wheel = game.add.sprite(game.width/2, game.width/2, "wheel"); 
 
      // setting wheel registration point in its center 
 
      wheel.anchor.set(0.5); 
 
      // adding the pin in the middle of the canvas 
 
      var pin = game.add.sprite(game.width/2, game.width/2, "pin"); 
 
      // setting pin registration point in its center 
 
      pin.anchor.set(0.5); 
 
      // adding the text field 
 
      prizeText = game.add.text(game.world.centerX, 480, ""); 
 
      // setting text field registration point in its center 
 
      prizeText.anchor.set(0.5); 
 
      // aligning the text to center 
 
      prizeText.align = "center"; 
 
      // the game has just started = we can spin the wheel 
 
      canSpin = true; 
 
      // waiting for your input, then calling "spin" function 
 
      game.input.onDown.add(this.spin, this); \t \t 
 
\t }, 
 
    // function to spin the wheel 
 
    spin(){ 
 
      // can we spin the wheel? 
 
      if(canSpin){ 
 
       // resetting text field 
 
       prizeText.text = ""; 
 
       // the wheel will spin round from 2 to 4 times. This is just coreography 
 
       var rounds = game.rnd.between(2, 4); 
 
       // then will rotate by a random number from 0 to 360 degrees. This is the actual spin 
 
       var degrees = game.rnd.between(0, 360); 
 
       // before the wheel ends spinning, we already know the prize according to "degrees" rotation and the number of slices 
 
       prize = slices - 1 - Math.floor(degrees/(360/slices)); 
 
       // now the wheel cannot spin because it's already spinning 
 
       canSpin = false; 
 
       // animation tweeen for the spin: duration 3s, will rotate by (360 * rounds + degrees) degrees 
 
       // the quadratic easing will simulate friction 
 
       var spinTween = game.add.tween(wheel).to({ 
 
        angle: 360 * rounds + degrees 
 
       }, 3000, Phaser.Easing.Quadratic.Out, true); 
 
       // once the tween is completed, call winPrize function 
 
       spinTween.onComplete.add(this.winPrize, this); 
 
      } 
 
    }, 
 
    // function to assign the prize 
 
    winPrize(){ 
 
      // now we can spin the wheel again 
 
      canSpin = true; 
 
      // writing the prize you just won 
 
      prizeText.text = slicePrizes[prize]; 
 
      
 

 
      window.location="http://Localhost/example/page2.php"; 
 
      
 
    } 
 

 
       
 
}

+0

可能な複製[JavaScriptからPHP](http://stackoverflow.com/questions/2798926/javascript-to-php) –

+0

こんにちはNeil、宿題のように見える...;)まず、してください問題を解消し、うまく動作していないものについて詳しく説明します。うまくいかないものについては、あなたが調査したものや解決しようとしているものについて言及してください。自分で解決する努力を表明することなく質問を投稿するだけであれば、質問は「遅延、デバッグ・イット・フォー・ミー」と表示され、閉鎖される可能性があります。乾杯! –

+0

申し訳ありませんが、デューク、私の悪い。私はあまりにも急いでいた。私はそれを少し下に説明したことを願っています。 –

答えて

0

winPrize(){ 
 
      // now we can spin the wheel again 
 
      canSpin = true; 
 
      // writing the prize you just won 
 
      prizeText.text = slicePrizes[prize]; 
 
      
 

 
      window.location="http://Localhost/example/page2.php"; 
 
      
 
    }

ここで、コード化されてきたものですPrizText.text = slicePrizes [prize]; は、同じhtml/phpページで賞金を印刷します。しかし、私はユーザ/参加者を window.location = "http://Localhost/example/page2.php"で別のページにリダイレクトしようとしていました。 と表示され、そこにタスクが表示されます。 私はウェブで見つかったあらゆる情報を調べてみましたが、うまくいくものはありませんでした。私はPHP変数と隠れたフォームを作り、その変数を次のランディングページに割り当てることを試みました。しかし、うまくいきませんでした

関連する問題