Search the Community
Showing results for tags 'high'.
-
var canvas = document.getElementById("renderCanvas"); var engine = new BABYLON.Engine(canvas, true); var initBallSpeed = 0.05; var ballSpeed = initBallSpeed; var xDirection = 1; var yDirection = 1; var boardX = -3.0; var boardY = 3.0; var keyState = {}; var MainScene = function () { // This creates a basic Babylon Scene object (non-mesh) var scene = new BABYLON.Scene(engine); // This creates and positions a free camera (non-mesh) var camera = new BABYLON.FreeCamera("camera1", new BABYLON.Vector3(0, 0, -20), scene); //camera.attachControl(canvas, true); var light = new BABYLON.HemisphericLight("hemi", new BABYLON.Vector3(0, 1, 0), scene); //Setup the bat for the scene. Dont know what else to call it. var bat = BABYLON.Mesh.CreateBox("bat", 0.5, scene); bat.scaling.x = 5.0; bat.position.y = -5.0; //Setup the ball var ball = BABYLON.Mesh.CreateSphere("ball", 5, 0.5,scene); ball.position.y = bat.position.y + 1; ball.position.x = bat.position.x; //Register keypress actions with the ball scene.actionManager = new BABYLON.ActionManager(scene); window.addEventListener('keydown',function(e){ keyState[e.keyCode || e.which] = true; },true); window.addEventListener('keyup',function(e){ keyState[e.keyCode || e.which] = false; },true); // scene.actionManager.registerAction(new BABYLON.ExecuteCodeAction( // BABYLON.ActionManager.OnEveryFrameTrigger, // function (evt) { // })); //Setup the walls // Top Wall var topWall = BABYLON.Mesh.CreateBox("topWall", 0.5, scene); topWall.position.y = 6.0; topWall.scaling.x = 25.0; // Left Wall var leftWall = BABYLON.Mesh.CreateBox("leftWall", 0.5, scene); leftWall.position.x = -6.0; leftWall.position.y = 1.0; leftWall.scaling.y = 25.0; // Right Wall var rightWall = BABYLON.Mesh.CreateBox("rightWall", 0.5, scene); rightWall.position.x = 6.0; rightWall.position.y = 1.0; rightWall.scaling.y = 25.0; var enemy = BABYLON.Mesh.CreateBox("enemy1", 1.0, scene); enemy.position.x = boardX; enemy.position.y = boardY; var matBB = new BABYLON.StandardMaterial("matBB", scene); matBB.emissiveColor = new BABYLON.Color3(1, 1, 1); enemy.material = matBB; scene.registerBeforeRender(function(){ ball.position.x += ballSpeed * xDirection; ball.position.y += ballSpeed * yDirection; if(ball.position.y < -7){ ball.position.y = bat.position.y + 1; ball.position.x = bat.position.x; ballSpeed = initBallSpeed; xDirection = yDirection = 1; } if(ball.intersectsMesh(rightWall, true)){ xDirection = -1; } if(ball.intersectsMesh(leftWall, true)){ xDirection = 1; } if(ball.intersectsMesh(topWall, true)){ yDirection = -1; } if(ball.intersectsMesh(bat, true)){ yDirection = 1; if(ballSpeed <= 0.25) ballSpeed+=0.01; } if(ball.intersectsMesh(enemy, true)) { xDirection = -1; yDirection = -1; enemy.material.emissiveColor = new BABYLON.Color3(1, 0, 0); } if (keyState[37] || keyState[65]){ bat.position.x-=ballSpeed*2; } if (keyState[39] || keyState[68]){ bat.position.x+=ballSpeed*2; } }); return scene; }; var scene = MainScene(); engine.runRenderLoop(function () { scene.render(); }); // Resize window.addEventListener("resize", function () { engine.resize(); }); Either I am really high or the enemy block is turning red before my ball can even collide with the block. Any ideas?
- 1 reply
-
- frustrated
- high
-
(and 3 more)
Tagged with:
-
So, I've begun fiddling with the tutorial example, but noticed that my fan was running a lot faster than it usually does. I checked the system monitor and noticed a CPU usage of around 50-60% when running the game code. This happens in both Firefox and Chrome. Is this normal? Any workarounds? It even slows down my code editor and other tasks. Sometimes it freezes for about 10 seconds, then continues but leaves the computer in a very sluggish state. - Scrolling vastly slowed down, programs shut down very slow etc. What is even more disconcerting is that nothing in the system monitor indicates any resource hog after I shut the browser down, yet the problems persist until I reboot. PS: I run Ubuntu 12.04 on a a i5 quad-core 2.5 GHz, 4 GB RAM. Bonus question: When upgrading from 1.1.3 to 1.1.5 gravity seems to get botched resolving A LOT slower than it should (and does in 1.1.3). What gives?