Just trying to fix things now
This commit is contained in:
+14
-47
@@ -4,11 +4,6 @@
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
var scene = {};
|
||||
var player = require('player.js');
|
||||
|
||||
var assets = AssetBatch([
|
||||
{ path: 'test.png', type: Asset.TYPE_TEXTURE, format: Texture.FORMAT_RGBA }
|
||||
]);
|
||||
|
||||
// Pokemon DS-style camera: ~34 degrees elevation (atan(6/9)).
|
||||
// CAM_HEIGHT / CAM_DIST ratio controls the tilt - keep it under 0.7 for
|
||||
@@ -16,58 +11,30 @@ var assets = AssetBatch([
|
||||
const CAM_HEIGHT = 6;
|
||||
const CAM_DIST = 9;
|
||||
|
||||
var cam, camPos;
|
||||
var floorEntity;
|
||||
|
||||
function updateCamera() {
|
||||
var pp = player.getPosition().worldPosition;
|
||||
// Position is offset above and behind the player; lookAt the exact player
|
||||
// world position so the player projects to the center pixel every frame.
|
||||
camPos.localPosition = new Vec3(pp.x, pp.y + CAM_HEIGHT, pp.z + CAM_DIST);
|
||||
camPos.lookAt(new Vec3(pp.x, pp.y, pp.z));
|
||||
}
|
||||
|
||||
scene.init = async function() {
|
||||
assets.lock();
|
||||
await assets.loaded();
|
||||
|
||||
var texEntry = assets.entry(0);
|
||||
|
||||
// Camera
|
||||
cam = Entity.create();
|
||||
camPos = cam.add(Component.POSITION);
|
||||
cam.add(Component.CAMERA);
|
||||
scene.cam = Entity.create();
|
||||
var camPos = scene.cam.add(Component.POSITION);
|
||||
var cam = scene.cam.add(Component.CAMERA);
|
||||
camPos.localPosition = new Vec3(3, 3, 3);
|
||||
camPos.lookAt(new Vec3(0, 0, 0));
|
||||
|
||||
// Floor - infinite static plane at Y=0. Rendered as a large flat blue
|
||||
// slab using the default SHADER_MATERIAL (no texture needed).
|
||||
floorEntity = Entity.create();
|
||||
var floorPos = floorEntity.add(Component.POSITION);
|
||||
var floorPhysics = floorEntity.add(Component.PHYSICS);
|
||||
floorPhysics.bodyType = Physics.STATIC;
|
||||
floorPhysics.shape = Physics.SHAPE_PLANE;
|
||||
|
||||
var floorR = floorEntity.add(Component.RENDERABLE);
|
||||
// Floor - large flat slab, no texture needed.
|
||||
scene.floor = Entity.create();
|
||||
var floorPos = scene.floor.add(Component.POSITION);
|
||||
var floorR = scene.floor.add(Component.RENDERABLE);
|
||||
floorR.type = Renderable.SHADER_MATERIAL;
|
||||
floorR.color = Color.BLUE;
|
||||
floorPos.localScale = new Vec3(16, 0.2, 16);
|
||||
floorPos.localPosition = new Vec3(0, -0.1, 0);
|
||||
|
||||
// Player - spawns 1 unit above the floor so physics drops it cleanly.
|
||||
player.create(texEntry);
|
||||
|
||||
// Initialise camera at the correct angle from the player's spawn position.
|
||||
updateCamera();
|
||||
// floorPos.localScale = new Vec3(16, 0.2, 16);
|
||||
// floorPos.localPosition = new Vec3(0, -0.1, 0);
|
||||
};
|
||||
|
||||
scene.update = function() {
|
||||
player.update();
|
||||
updateCamera();
|
||||
};
|
||||
|
||||
scene.dispose = function() {
|
||||
player.dispose();
|
||||
Entity.dispose(floorEntity);
|
||||
Entity.dispose(cam);
|
||||
assets.unlock();
|
||||
Entity.dispose(scene.floor);
|
||||
Entity.dispose(scene.cam);
|
||||
};
|
||||
|
||||
module.exports = scene;
|
||||
|
||||
Reference in New Issue
Block a user