Jump to content

astralaaron

Members
  • Posts

    1,254
  • Joined

  • Last visited

Everything posted by astralaaron

  1. Yes but I think that you will need to do this with PHP
  2. when you go down to the next line it ads a "\n" the newline character and I think that javascript doesn't allow that in the middle of a string, the "\" is the escape character and escapes the \n character
  3. I am pretty sure that you can just explode by "\n" you will have the array of the lines, then do a loop on that array and explode by the ","
  4. $line .= $matrix[$i][$x] . ($x < (sizeOf($matrix[0]) -1) ? "," : "\r\n") ; try like this with -1
  5. If you look at the page source code it will look like the map grid, the \n doesn't show on the page edit: to load it back into the array you can just do explode("\n",$lines), and then explode(",",$line)
  6. I did this test and the array loops out like you are trying to do. Make sure that $_POST['mapname'] is set so it runs that part of the code. <?php $matrix = array( array(10, 10, 01, 03, 04, 01, 03, 05, 02, 01), array(10, 10, 01, 03, 04, 01, 03, 05, 02, 01), array(10, 10, 01, 03, 04, 01, 03, 05, 02, 01), array(10, 10, 01, 03, 04, 01, 03, 05, 02, 01), array(10, 10, 01, 03, 04, 01, 03, 05, 02, 01), array(10, 10, 01, 03, 04, 01, 03, 05, 02, 01), array(10, 10, 01, 03, 04, 01, 03, 05, 02, 01), array(10, 10, 01, 03, 04, 01, 03, 05, 02, 01), array(10, 10, 01, 03, 04, 01, 03, 05, 02, 01), array(10, 10, 01, 03, 04, 01, 03, 05, 02, 01) ); for($i = 0; $i < sizeOf($matrix); $i++) {$line = "";$size = sizeOf($matrix[$i]); for($x = 0; $x < $size; $x++) { $line .= $matrix[$i][$x] . ($x < ($size-1) ? "," : "\n") ; // edit 2 } echo($line);}?>
  7. I am thinking something like this will work for you for($i = 0; $i < sizeOf($matrix); $i++) {$line = ""; for($x = 0; $x < sizeOf($matrix[0]); $x++) { $line .= $matrix[$i][$x] . ($x < sizeOf($matrix[0]) ? "," : "\n") ; // edit 2 } fwrite($file, $line);} edit: fixed a syntax error
  8. just give it an id and edit the style like you are doing to the 'large' id
  9. Ok here is a test I put together, and it is failing exactly the same way as my project. <!DOCTYPE html><html><head> <title>test</title> <style type="text/css"> body { margin:0; } #wrapper { margin:0px; position:relative; width:100%; } #container { margin:0 auto; width:640px; height:480px; } </style> <script type="text/javascript"> function test() { var that = this; alert('constructing'); var SCREEN_W; var SCREEN_H; var screenContext; var bufferContext; this.init = function() { alert('initiating'); var screen; screen = document.getElementById("mycanvas"); SCREEN_W = screen.width; SCREEN_H = screen.height; var backBuffer = document.createElement("canvas"); backBuffer.width = SCREEN_W; backBuffer.height = SCREEN_H; screenContext = screen.getContext("2d"); bufferContext = backBuffer.getContext("2d"); that.clearFrame(); bufferContext.fillStyle = "#ff0000"; bufferContext.fillRect(0,0,10,10); that.renderFrame(); alert('after test'); } this.clearFrame = function () { bufferContext.clearRect(0, 0, SCREEN_W, SCREEN_H); alert('frame clear'); } this.renderFrame = function() { alert('rendering'); screenContext.clearRect(0, 0, SCREEN_W, SCREEN_H); alert('test'); screenContext.drawImage(bufferContext, 0, 0); // this seems to be failing, same line in my project alert('rendered'); //this alert never executes } } var t = new test(); document.addEventListener("DOMContentLoaded", t.init ,false); </script> </head><body> <div id="wrapper"> <div id="container"> <h1>Test</h1> <canvas id="mycanvas" width="640" height="480"> upgrade your browser </canvas> </div> </div></body></html>
  10. The entire thing is pretty big, I will make a smaller example
  11. yes I have, it is also[object CanvasRenderingContext2D] Edit: I also made sure I could draw directly to the gameScreen
  12. I made a typo in my post, I do have it like that :gameScreen.drawImage(buffer, 0, 0);
  13. Ignolme your example is very clear however the image is still not drawing. I have stepped through each line with alerts to find where it is failing and it seems like on this line it is failing: gameScreen = drawImage(backBuffer, 0, 0); an alert immediately before that line with shows the backBuffer variable is ok: alert(backBuffer); // outputs: [object CanvasRenderingContext2D] This is strange..
  14. I am trying to do this right now and having some trouble getting the back buffer to copy over to my viewable canvas.var buffer = document.createElement("canvas");buffer.width = SCREEN_W; //also tried buffer.w and buffer.hbuffer.height = SCREEN_H;var backBuffer = bufferHtml.getContext("2d");alert(backBuffer); //this worksalert(backBuffer.width); // undefined var htmlCanvas = document.getElementById("game");var gameScreen = htmlCanvas.getContext("2d"); backBuffer.fillStyle = "#ff0000";backBuffer.fillRect(0,0,10,10); gameScreen.drawImage(backBuffer, 0, 0); Please let me know what I am doing wrong, I am messing around with it and searching around but can't seem to find a fix. EDIT: yes SCREEN_W and SCREEN_H are defined, 640 / 480
  15. Try doing var_dump($_COOKIE['value']); to see the data type
  16. I think it is similar to what I am doing with game states (or levels) in JavaScript. I create a 'class' for each level or menu and use a normal array to hold the current states of the program. The last element in the array would be the current state. So if you had one state running and wanted to have an options menu pop up over that then you would just push that menu class on to the array of states.
  17. It looks like you are getting an answer of 1.3 and then 3.9if you echo out a break line in between them it would look right echo '<br />'; EDIT: I ran the code you posted and got: 0.453.9 so, 0.45 and 3.9
  18. The backslash ( \ ) can fix that problem too by escaping the quote ( ' ) . <?php if($messageSent){ echo '<script type=\'text/javascript\'> sNotify.addToQueue("Your message has been sent");</script>'; };?>
  19. I think you are missing the point
  20. After reading your post again I see exactly what you are saying, does this make the animations any smoother in JS? I haven't noticed a flicker. Even if it doesn't I think I will be doing it as you are saying because it makes good sense.
  21. This seems like it will work out. Like I was saying I don't think you need to inherit the class at all in JS, the functions in the parent class are all empty in C++. After doing this test I think I won't have a problem organizing the levels. Here it is for anyone that is interested (it is not a full game level manager just a test) <!DOCTYPE html><html> <head> <script type="text/javascript">var states = new Array(); function AState(){ this.something = "a"; } AState.prototype.init = function() { this.something = "A SOMETHING"; } AState.prototype.getSomething = function() { return this.something; } function BState(){ this.something = "b"; } BState.prototype.init = function() { this.something = "B SOMETHING"; } BState.prototype.getSomething = function() { return this.something; }var a = new AState();var b = new BState(); document.addEventListener("DOMContentLoaded", function() { states.push(a); alert('still working'); alert(states[states.length - 1].getSomething()); states[states.length - 1].init(); alert(states[states.length - 1].getSomething()); states.pop(); states.push(; alert(states[states.length - 1].getSomething()); states[states.length - 1].init(); alert(states[states.length - 1].getSomething()); var sa = document.getElementById('asd'); var sb = document.getElementById('xyz'); sa.addEventListener("click", function(){ alert('level complete, entering new level'); states.pop(); states.push(a); alert(states[states.length - 1].getSomething()); }, false); sb.addEventListener("click", function(){ alert('level complete, entering new level'); states.pop(); states.push(; alert(states[states.length - 1].getSomething()); }, false); }, false);</script></head><body> <p id="asd">level A</p><p id="xyz">level B</p></body></html> Thanks for the assistance /*EDIT: I have a typo in that code where I used states.push(; instead of states.push(;for some reason I am not able to edit it on this post. It is a bit confusing to me though because the code still works with that typo.isn't Javascript case sensitive? EDIT 2: well..for some reason I cannot enter a lowercase b into the forum I guess I did have it correct in my code so that would explain it not failing. the forum is capitalizing my b's*/ ( // there...if you put the parentheses around a b the forum capitalizes it.
  22. If you are using ajax why do you need iframes to make this work in the first place? couldn't you just load the content into the current page into <div>'s ? Then it might be easier to access the variables
  23. It is hard to say what is going on from your example. Are you trying to do a shape tween or motion tween? When you are tweening with the timeline and not with code just make sure the keyframes are correct and add the tween to the frames between them.
×
×
  • Create New...