4

私は Babylonjs を初めて使用し、BabylonJs を使用して画像を表示/表示したいのですが、衝突検出を使用してキーボード (左矢印キー、右矢印キー、上矢印キー、下矢印キーなど) を使用して画像を移動したいと考えています。すべてのマウス イベントを無効にしたい。

画像を表示するためのコードを以下に書きましたが、それは正しい方法ではないと思います..

  var playerMaterial = new BABYLON.StandardMaterial("ground", scene);
    playerMaterial.diffuseTexture = new BABYLON.Texture("/images/mail.png", scene);
    playerMaterial.specularColor = new BABYLON.Color3(0, 0, 0);
    player.material = playerMaterial;
    player.position.y = 1;
    player.position.x = -84;
    player.size = 20;

誰かが私にどうすればよいか教えてもらえますか?

ありがとう
ラビランジャン

4

1 に答える 1

4

カメラと光源もあると仮定すると、コードは基本的に正しく見えます。ここに遊び場のエントリがあります。

そして、後世のために、そのコードは次のとおりです。

var scene = new BABYLON.Scene(engine);

//Create a light
var light = new BABYLON.PointLight("Omni", new BABYLON.Vector3(-60, 60, 80), scene);

//Create an Arc Rotate Camera - aimed negative z this time
var camera = new BABYLON.ArcRotateCamera("Camera", Math.PI / 2, 1.0, 210, BABYLON.Vector3.Zero(), scene);
camera.attachControl(canvas, true);

//Creation of a repeated textured material
var materialPlane = new BABYLON.StandardMaterial("texturePlane", scene);
materialPlane.diffuseTexture = new BABYLON.Texture("textures/grass.jpg", scene);
materialPlane.specularColor = new BABYLON.Color3(0, 0, 0);
materialPlane.backFaceCulling = false;//Allways show the front and the back of an element

//Creation of a plane
var plane = BABYLON.Mesh.CreatePlane("plane", 120, scene);
plane.rotation.x = Math.PI / 2;
plane.material = materialPlane;

私は彼らのデモの 1 つから始めて、最小限の例を得るためにほとんどのものをハッキングしました。私はbackFaceCulling = false(それ以外の場合、画像は一方向からしか見えないため)に残して、specularColor設定に追加しました。

別のアプローチは、diffuseTextureを次のように置き換えることemissiveTextureです。

materialPlane.emissiveTexture = new BABYLON.Texture("textures/grass.jpg", scene);

次に、ライトをコメントアウトしても、まだ表示されます。(実際、光を当てたままだと白とびしてしまいます。)

(キーボード制御と衝突検出の質問については、新しい質問を開始することをお勧めします。または、バビロンのサンプルとチュートリアル ビデオに取り組んでください。)

于 2015-04-07T17:33:21.850 に答える