Nexus7のwebviewにおける挙動(enchant.js)

282 views
Skip to first unread message

unia

unread,
Apr 25, 2013, 1:20:02 PM4/25/13
to android-g...@googlegroups.com
みなさま

uniaと申します。

私は現在、enchant.jsを用いてゲームを作ろうとしております。
Nexus7(実機)でデバッグしたところ思うような挙動をしません。
他の端末なら思うように動きます。

目的の動きとしては、「緑色の背景の中央に黄色の正方形が表示されており、
その正方形をタッチすると2回のアラートの後に黄色が白色になる」です。
ですが、Nexus7では2回のアラートのあと、黄色が白色になりません。
おそらく再描画ができていないと思われます。
(アラートの後、黄色が移動するようなコードを書いても移動しませんでした。)

調べても原因がわからないので、皆様のお力をお貸しください。

以下、コードと環境です。

ーーーーー
端末:Nexus7
OS:4.2.2
ーーーーー
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<meta name="viewport" content="width=device-width, user-scalable=no">
<meta name="apple-mobile-web-app-capable" content="yes">
<script type="text/javascript" src="../javascripts/enchant.min.js"></script>
<style type="text/css">
body {
    margin: 0;
    padding: 0;
}
</style>
</head>
<body>
  <script type="text/javascript">
    enchant();
    window.onload = function(){
        var game = new Game(320, 320);
        var label = new Label('Hello, enchant.js! I am unia529!');
        game.rootScene.addChild(label);

        game.onload = function() {
        var scene = game.rootScene;
        scene.backgroundColor = "green";
    // エンティティを生成, シーンに追加
    var entity = new Entity(); // 生成
            entity.width = 30; // 幅を設定
    entity.height= 30; // 高さを設定
    entity.x = scene.width/2 - entity.width/2;
            entity.y = scene.height/2 - entity.height/2;
    entity.backgroundColor = "yellow"; // 背景色を設定
    scene.addChild(entity); // シーンに追加
 
    //タッチ開始時に呼ばれる関数を登録
    entity.ontouchstart = function() {
        alert("ontouchstart");
    };
    //タップ時に呼ばれる関数を登録
    entity.ontap = function() {
    alert("touch");
    };

    entity.addEventListener( 'touchstart', function() {
    setTimeout(function(){
  //クリック時の処理
  alert("タッチされました");
  // confirmメッセージ
  // confirm(' this is sample code', 'yes', 'no');
  entity.backgroundColor = "white";
                // scene.removeChild(entity);
    }, 0);
    });

        };
        game.start();
    }
  </script>
</body>
</html>
ーーーーー
package com.example.cockroach_android;

import android.os.Bundle;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.view.Menu;
import android.webkit.WebChromeClient;
import android.webkit.WebView;

public class MainActivity extends Activity {

  @SuppressLint("SetJavaScriptEnabled")
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    WebView mainView = (WebView)findViewById(R.id.main1);//WebViewの読み込み
    mainView.getSettings().setJavaScriptEnabled(true); //Javascriptの有効化
    mainView.getSettings().setBuiltInZoomControls(true);//ズームの有効化
    mainView.setWebChromeClient(new WebChromeClient()); // JSのalert機能の有効化
    mainView.setVerticalScrollbarOverlay(true); // 右10pxの余白を消す
    mainView.loadUrl("file:///android_asset/views/index.html");//assetsフォルダのファイルを読み込み
  }

  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
  }
}

ーーーーー

Reply all
Reply to author
Forward
0 new messages