デバッグ
PlayCanvasのスクリプトを作成するためには、ブラウザの開発ツールにアクセスして使用する方法を知っていることが重要です。
Chrome、Firefoxや他のブラウザでは、ブラウザに直接組み込まれているDeveloper Toolがあります。通常、Mac上でALT-CMD-I、WindowsではF12キーを押すことでアクセスすることができます。またはブラウザのメニューを使用して開発者ツールにアクセスすることができます。
スクリプトのデバッグ
スクリプトをデバッグするためには、Developer Tools (Chrome)でSourcesタブを選択します。Sourcesペインの左上隅にあるアイコンをクリックして 'navigator' を開きます。以下のようなものが表示されるはずです:
Firefoxでは次のようになります:
ナビゲータには、自身で書いたPlayCanvasスクリプトを含む、現在アクティブなタブで実行している全てのスクリプトがリストされます。ナビゲーターからスクリプトを探し、選択するとソースコードが開きます。これで、ブレイクポイントを設定してデバッグが行えます。
各ブラウザには、JavaScriptをデバッグする方法の手順が詳述されています。これらのドキュメントをお読みください:Chrome, Firefox, Safari, Edge / Internet Explorer。
Debugging on Mobile Devices
On Android, it is possible to connect to the mobile Chrome browser via the desktop Chrome browser devtools and USB cable. Google Developer documentation has the detailed steps for the setup.
iOS debugging requires access to a Mac and Apple has outlined the steps needed to enable developer options to start debugging.
In the situation where either it's not possible to connect to the web view directly from Chrome or Safari (e.g. a web view in another app) or don't have access to a Mac, the following libraries and services can help and are simple to add to projects:
- RemoteJS - Allows developers to view the console output remotely in a desktop browser and also execute JS in the console which makes it very powerful. The console output can be delayed or slow though.
- vConsole or Eruda - Adds a widget DOM object to the page that can be expanded to show console output, network requests, the page elements and more.