Jump to content

FalseProphet

Members
  • Posts

    49
  • Joined

  • Last visited

    Never

Everything posted by FalseProphet

  1. Still seeking an answer for this. Any javascript gurus happen to have experience with this kind of thing?
  2. I'm not sure what you mean by structure. I'm trying to send keypresses to a canvas element. My html document looks like this: <!DOCTYPE HTML> <HTML> <HEAD> <script type="text/javascript" src="scripts/glib.js"></script> <script type="text/javascript" src="scripts/glib_common.js"></script> </HEAD> <BODY> <!--onload="init()" onkeydown="evtKeyboard.KeyDown(event)" onkeyup="evtKeyboard.KeyUp(event)" onclick="evtMouse.GetMouseState(event)"> --> <canvas id="scene" style="border:1px solid #ff0000; width:500px; height:500px;"> Your browser does not support a Canvas element! </canvas> <div id="debug" style="position: relative; width:500px;height:200px; border:1px solid #0010ff"></div> <script>init();</script> </BODY> </HTML>
  3. wat..? I currently have: <div id="scene_input" onkeydown='evtKeyboard.KeyDown(event)' onkeyup="evtKeyboard.KeyUp(event)" onclick='evtMouse.GetMouseState(event)' style="width:100px; height:100px; border:1px solid #ff0000"></div> None of the onkey events work. However, onclick does... In body, onkey events work just fine. However placing them inside of body is not a possibility for my current project. I don't get what you mean by your post.. Using addEventListener() inside of a javascript script works for exactly what I described in my first post. However it it seems to pause setTimeout and setInterval for some reason.
  4. As the title states, I want to detect when a keypress occurs but I don't want to use something like <body onkeydown="dothis(event)"></body> Is it possible? If so, how?
  5. Hi, I am pretty new to Javascript and would like to play with the Canvas and I have a couple questions. First off, how do I record frame rate or operations per second properly? In my current code I only get around 170 FPS with nothing on the canvas and the canvas being default size: // GetElapsedMilliseconds = Function() { var time = new Date(); return time.getMilliseconds(); } if (GetElapsedMilliseconds() - oldTime >=1000) { OPS = count; count = 0; oldTime = GetElapsedMilliseconds(); } ++count; loop = setTimeout('Main()', 1); Another thing, am I doing Javascript's OOP implementation correctly? myscene = new _Context("thecanvas"); function _Context(id) { /* description: Retrieve the canvas context by id, if it can't throw an error and reason. */ if (document.getElementById(id)) { this.canvas = document.getElementById(id).getContext("2d"); } else { alert("Error\nUnable to find element ID: " + id); return null; } this.DrawText = function(x, y, string, size, font, color) { // draw some text inside of the canvas /* description: Draw text to the canvas. */ this.canvas.font = size + "px " + font; this.canvas.fillStyle = color; this.canvas.fillText(string, x, y); } }
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.