Jump to content

vmars316

Members
  • Content Count

    398
  • Joined

  • Last visited

Everything posted by vmars316

  1. Hello & Thanks , Can someone aim me at a w3schools how to "requestAnimationFrame()" ? I can't seem to find one . Thanks
  2. Thanks Ingolme I see I have lots more work to do . Should keep me busy for a while . Thanks again .
  3. Hello & Thanks , I am having trouble with my phone version of BenghaziGame . My viewport : <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/> Also , I changed the camvas dimensions from this: <canvas id="canvas" width="800" height="550" style="background-color:#992D2D"></canvas> to this: <canvas id="canvas" width="360" height="400" style="background-color:#992D2D"></canvas> And it looks like I'll need to adjust a bunch of other stuff to make it visually acceptable . Running the program on desktop , it all runs fine . But running same code on phone , the collision detection doesn't work , and the prog runs very , very slow . I could use some recommendations on what can I tweak to improve phone I am running it on my Lumia 640 windows phone . http://liesandcowpies.com/ gives options to run on phone or desktop . Thanks
  4. Hello & Thanks , A javascript Tutorial for BenghaziGame : I just wanted to let you know that I have written a javascript tutorial for my BenghaziGame , and to thank all you folks on this Forum who have helped me to convert this game to javascript . Benghazi Game is a shoot 'em up political satire browser game . But instead of bullets , we throw cowpies at politicians when we see them lying . How do we know when they are lying ? When their noses turn into long carrot noses , they are lying . The Tutorial game begins here : http://liesandcowpies.com/javascript/BenghaziGame.00-TUTORIAL.html I have also posted the whole Tutorial for download here : http://liesandcowpies.com/javascript/BenghaziGame-TUTORIALS.zip My disclaimer: I am going to let w3schools.com do most of the heavy lifting , and use their GameTutorial resources to do the explaining on specific keywords . Here is a list of their web pages that we will be using: http://www.w3schools.com/games/ http://www.w3schools.com/games/game_canvas.asp http://www.w3schools.com/games/game_components.asp http://www.w3schools.com/games/game_controllers.asp http://www.w3schools.com/games/game_obstacles.asp http://www.w3schools.com/games/game_score.asp http://www.w3schools.com/games/game_images.asp http://www.w3schools.com/games/game_sound.asp and more as the need arises . Thanks...Vern
  5. Hello & Thanks , A javascript Tutorial for BenghaziGame : I just wanted to let you know that I have written a javascript tutorial for my BenghaziGame , and to thank all you folks on this Forum who have helped me to convert this game to javascript . Benghazi Game is a shoot 'em up political satire browser game . But instead of bullets , we throw cowpies at politicians when we see them lying . How do we know when they are lying ? When their noses turn into long carrot noses , they are lying . The Tutorial game begins here : http://liesandcowpies.com/javascript/BenghaziGame.00-TUTORIAL.html I have also posted the whole Tutorial for download here : http://liesandcowpies.com/javascript/BenghaziGame-TUTORIALS.zip My disclaimer: I am going to let w3schools.com do most of the heavy lifting , and use their GameTutorial resources to do the explaining on specific keywords . Here is a list of their web pages that we will be using: http://www.w3schools.com/games/ http://www.w3schools.com/games/game_canvas.asp http://www.w3schools.com/games/game_components.asp http://www.w3schools.com/games/game_controllers.asp http://www.w3schools.com/games/game_obstacles.asp http://www.w3schools.com/games/game_score.asp http://www.w3schools.com/games/game_images.asp http://www.w3schools.com/games/game_sound.asp and more as the need arises . Thanks...Vern
  6. Ah , perfect , Thanks Don I knew it would be something simple , just couldn't see it ...Vern
  7. Hello & Thanks ; I am having trouble with my http://liesandcowpies.com/javascript/BenghaziGame.html Javascrtip and html are all one file : Prob: all buttons work fine, except for <button onmousedown="touchRightArrow" . the onmouseup="touchEndRight()" works fine . But I havent been able to figure out why <button onmousedown="touchRightArrow" isn't working . I need a new set of eyes to help me . I am happy to Post all code if necessary , but its 557 lines . <div id="canvasDiv" align="center" > <canvas id="canvas" width="800" height="550" style="background-color:#992D2D"></canvas> <br> <button onclick="myGameArea.pause()" ontouchstart="myGameArea.pause()" >Pause</button> <button onclick="myGameArea.play()" ontouchstart="myGameArea.play()" >Play</button> ___ <button onmousedown="touchLeftArrow()" onmouseup="touchEndLeft()" ontouchstart="touchLeftArrow()" ontouchend="touchEndLeft()">MoveLeft</button> _ <button onclick="touchUpArrow()" ontouchstart="touchUpArrow()">Throw</button> _ <button onmousedown="touchRightArrow" onmouseup="touchEndRight()" ontouchstart="touchRightArrow" ontouchend="touchEndRight()">MoveRight</button> ___ <button onclick="clearIt()" ontouchstart="clearIt()">Clear</button> <button onclick="quitIt()" ontouchstart="quitIt()">Quit</button> </div> // function touchRightArrow() { alert("function touchRightArrow() {"); thrower.directionX = 1; thrower.moveMe = true ; if (thrower.x > canvas.width -40) { thrower.moveMe = false ; } } // function touchEndRight() { //alert("function touchEndRight() {"); rightPressed = false ; thrower.moveMe = false ; drawThrower(); } //
  8. Hello ; I wrote a browser game in Enchant.js , where I did some collisions . It is contained in this .zip file : http://liesandcowpies.com/BenghaziGame/BenghaziGame-Demo/BenghaziGame.zip The file you are probable most interested is this one : BenghaziGameTest.js I stopped using enchantjs because they apparently stopped developing it . So I rewrote it in Phaser , here : http://liesandcowpies.com/testMe/vm-phaser/vm-vertical-collision-Web.html Didn't care for Phaser too much . It is so laaarge . So I rewrote it in Quick.js , here : http://liesandcowpies.com/quickjs/BenghaziGame.html Runs great , but the DOCs weren't very good . Then I thought 'why keep fiddling with all these languages . Since they are all based on javascript , why not just learn javascript .' So I am writing it in javascript here : http://liesandcowpies.com/javascript/BenghaziGame.html It is almost complete . Just having trouble with the 'MoveRight' button . The folks on this Forum are awesome !!! Anyways , take a look at enchant.js code : http://liesandcowpies.com/BenghaziGame/BenghaziGame-Demo/BenghaziGame.zip Happy Trails...
  9. Ah , working real well , Thanks Again Onwards ! http://liesandcowpies.com/javascript/BenghaziGame-09-Sound.html I am hoping to turn this into a Tutorial ...
  10. Hey dsonesuk , Thanks a lot ! I am studying it a bit .
  11. Thanks Folks , The code is for a computer game: http://liesandcowpies.com/javascript/BenghaziGame-starter-08-TCT-Collisions.html Here is the code to play sound: Here is line to play sound: and here is the 'playAudio function': Everytime there is a collision between a cowpie and a person , I need to play/replay that sound . So , I need to know 'how to replay sound from cache' , without any controls visible . Thanks
  12. Ooooh... , Thanks Newbie: In the mean time I discovered the format below : My question on that is ; Does the playThis file remain in memory ? Or does it get released after the audio.play(); ? If it remains in memory , how can I access it multiple times ? Thanks
  13. What I am passing into playAudio is this: And when I code the following , I get same error: Thanks
  14. Hello & Thanks , I am getting an error : Uncaught SyntaxError: Unexpected token < on the line <audio src=playThis> in this code : Pls , what am I doing wrong ? Thanks
  15. Hello & Thanks , I am getting the following error: Whole code is here: I think it has to do with the placement of : truth01 = new TargetImages(); But I can't figure out where it should go . Thanks
  16. Oh , ok , I get it . function startGame() { canvas = document.getElementById("canvas"); // get the canvas ctx = canvas.getContext('2d'); // create canvas Context; ctx.drawImage(cowpieImg, 150, 150); ctx.drawImage(cowpieImg, 150, 200, 64, 64); } // EndOf function startGame() Thanks
  17. Thanks , Yes , I am having difficulty with the distinction between 1) cowpie the image (cowpie.png) 2) var cowpie = new Cowpie(); 3) var cowpies = [document.getElementById("cowpie")]; I haven't worked with multiple copies of an image , along with multiple copies of same definition . It looks like I need two arrays , one for multiple cowpie.png's and one for the definitions of each of the cowpie.png Is that correct ?
  18. Hello & Thanks , I am getting this error: Uncaught TypeError: Failed to execute 'drawImage' on 'CanvasRenderingContext2D': The provided value is not of type '(HTMLImageElement or HTMLVideoElement or HTMLCanvasElement or ImageBitmap)' on this line: ctx.drawImage(cowpies[i], cowpies[i].x, cowpies[i].y, cowpies[i].width, cowpies[i].height); I got no error msg from the 'onload' . Haven't figured out what I am doing wrong . Pls , take a look .
  19. Yes , Thanks , I am reading the Arrays Tutorial http://www.w3schools.com/js/js_arrays.asp now.
  20. Thanks , this line was problem : Cowpie.prototype.update = function() { then this one : var cowpie = new Cowpie(); I'll try to do better next time . A related question , I don't have much experience with arrays : Array defined like this : var cowpies = [document.getElementById("cowpie")]; I am getting a '174 Uncaught TypeError: Cannot read property 'idActive' of undefined' on this line : if (!cowpies.cowpie.idActive) {cowpies.pop(cowpie);}; in : if(e.keyCode == 87 || event.keyCode == 38) { // shoot W or upArrow // check cowpies array if idActive = false Delete item // 1st active cowpie already set up in function startGame() for (var i = cowpies.length - 1; i >= 0; i--) { cowpiesCount = i ; if (!cowpies[i].cowpie.idActive) {cowpies[i].pop(cowpie);}; alert("cowpies[i].cowpie.idActive = " + i + " "+ cowpies[i].cowpie.idActive ); } cowpie = new Cowpie; cowpies[i].cowpie.update; cowpies.push(cowpie); } I think I am messing up on the array syntax . Pls , what should it be ? Thanks
  21. Hello & Thanks , I am getting 'Uncaught SyntaxError: Unexpected identifier' on : Cowpie.prototype.update = function() { for (var i = cowpies.length - 1; i >= 0; i--) { cowpieCount = i ; if (cowpies[i].cowpie.idActive) { self.y = self.y+ (self.speedY * self.directionY); // always -1 } } else { cowpies[i].pop(this.cowpie);} } } and if I comment the above out , then I get same for : var cowpie = new Cowpie(); and so on , down the line . Until I dismiss the whole section below . var Cowpie = (function () { var self = this; this.idTag = 'cowpie'; this.idActive = true; this.x = thrower.x; this.y = thrower.y; this.width= 64; this.height = 64; this.speedX = 0; this.speedY = 5; this.visible = true; this.directionY = -1; this.moveMe = false ; } // Cowpie.prototype.update = function() { for (var i = cowpies.length - 1; i >= 0; i--) { cowpieCount = i ; if (cowpies[i].cowpie.idActive) { self.y = self.y+ (self.speedY * self.directionY); // always -1 } } else { cowpies[i].pop(this.cowpie);} } } // var cowpie = new Cowpie(); // var Thrower = function () { var self = this; this.idTag = 'thrower'; this.x = (canvas.width / 2); this.y = canvas.height - 64; this.width= 64; this.height = 64; this.speedX = 1; this.speedY = 0; this.visible = true; this.directionX = 5; this.moveMe = false ; } Thrower.prototype.update = function() { self.x = self.x + (self.speedX * self.directionX); // always either +1 or -1 } } // var thrower = new Thrower(); thrower.idTag ; // = 'thrower'; // function startGame() { myGameArea.start(); }
  22. Oops , <> not working , here's the code: <!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width, initial-scale=1.0"/> <meta charset="utf-8" /> <title>move pieThrower</title> <!-- [url=http://liesandcowpies.com/javascript/]http://liesandcowpies.com/javascript/[/url] --> <style> canvas { border:1px solid #d3d3d3; background-color: #f1f1f1; } #assets { visibility: hidden; } </style> </head> <body onload="startGame()"> fromWhere= <span id="fromWhere">fromWhere</span><br> idTag= <span id="idTag">idTag</span><br> this.idTag= <span id="thisIdTag">this.idTag</span><br> this.visible= <span id="this.visible"> this.visible</span><br> this.tripsMax= <span id="this.tripsMax"> this.tripsMax</span><br> this.tripsCnt= <span id="this.tripsCnt"> this.tripsCnt</span><br> this.directionX= <span id="this.directionX"> this.directionX</span><br> this.x= <span id="this.x"> this.x</span><br> thrower x,y,w,h= <span id="thrower.xywh">thrower.x,y,w,h</span><br> <div align="center"> <table style="text-align: left; width: 100%;" border="0" cellpadding="2" cellspacing="2"> <tbody> <tr> <td style="width:70%";><p id="traceMsg">traceLog goes here:</p> </td> <td style="width:30%";> <canvas id="canvas" width="300" height="300"></canvas> </td> </tr> </tbody> </table> </div> <div id="assets"> <img id="truth01" src="sprites/truth01.png" width="64" height="64" /> <img id="truth02" src="sprites/truth02.png" width="64" height="64" /> <img id="lies01" src="sprites/lies01.png" width="64" height="64" /> <img id="lies02" src="sprites/lies02.png" width="64" height="64" /> <img id="cowpie" src="sprites/cowpie.png" width="32" height="32" /> <img id="thrower" src="sprites/thrower.png" width="64" height="64" /> <audio id="closeDoor" src="sounds/CloseDoor.ogg"></audio> </div> <script type='text/javascript'> // var oneTraceLine = ""; var traceYESorNO = false; var updateFor1stTime = 0; var fromWhere = "fromWhere"; var timesInTripsCk=0; var visible = true; var thisx=0; var tripsMax=0; priorTripsMax = 0; var thisIdTag; var holdThrower_x = 0; var idTag = "truth01"; var idTagTh = "thrower"; var tripsCnt=0; var directionX=1 ; var addit = 0; // canvas = document.getElementById("canvas"); // get the canvas ctx = canvas.getContext('2d'); // create canvas Context; var targetImgsCnt = 0; var idTag = "truth01"; var totalTrips = 0; var targetImgs = [document.getElementById("truth01"), document.getElementById("lies01"), //, document.getElementById("truth02"), document.getElementById("lies02"), document.getElementById("thrower") ] ; // // function startGame() { var Thrower = function () { var self = this; this.idTag = 'thrower'; this.x = (canvas.width / 2); this.y = canvas.height - 64; this.width= 64; this.height = 64; this.speedX = 1; this.speedY = 0; this.visible = true; this.directionX = 5; this.moveMe = false ; this.update = function() { self.x = self.x + (self.speedX * self.directionX); // always either +1 or -1 } self.moveMe = false ; } } // thrower = new Thrower(); thrower.idTag ; // = 'thrower'; thrower.x ; // = 0; thrower.y ; // = canvas.height - 64; thrower.width ; // = 64; thrower.height ; // = 64; thrower.speedX ; // = 1; thrower.speedY ; // = 0; thrower.visible ; // = true ; thrower.directionX ; // = 1; thrower.moveMe ; // = true ; // myGameArea.start(); } // function updateGameArea() { myGameArea.clear(); targetImgsCnt = 4; if(thrower.visible) { if(thrower.moveMe) {thrower.update();} ctx.drawImage(targetImgs[targetImgsCnt], thrower.x, thrower.y, thrower.width, thrower.height); /*120*/ document.getElementById("thrower.xywh").innerHTML = thrower.x; } } // var myGameArea = { start : function() { thrower.moveMe = false ; interval = setInterval(updateGameArea, 5); // updateGameArea(); }, clear : function() { ctx.clearRect(0, 0, canvas.width, canvas.height); }, stop : function() { clearInterval(this.interval); } } // document.addEventListener("keydown", keyDownHandler, false); document.addEventListener("keyup", keyUpHandler, false); document.addEventListener("mousemove", mouseMoveHandler, false); function keyDownHandler(e) { if(e.keyCode == 39 || event.keyCode == 68) { // rightPressed = true; // alert("keyDownHandler: rightPressed"); thrower.directionX = 7; thrower.moveMe = true; } else if(e.keyCode == 37 || event.keyCode == 65) { // leftPressed = true; // alert("keyDownHandler: leftPressed"); thrower.directionX = -7; thrower.moveMe = true; } } function keyUpHandler(e) { if(e.keyCode == 38 || event.keyCode == 87) { rightPressed = false; } else if(e.keyCode == 40 || event.keyCode == 83) { leftPressed = false; } } function mouseMoveHandler(e) { var relativeX = e.clientX - canvas.offsetLeft; // alert("function mouseMoveHandler(e)"); } // // </script> </body> </html>
  23. Hello & Thanks , In my game , I check for leftArrow and rightArrow down to move sprite (Thrower) , and also for keyup , to stop movement . But I am getting sprite movement pauses on all keydown ? Is there a way to speed things up ? See/run game (so far) : http://liesandcowpies.com/javascript/BenghaziGame-starter-04-ThrowerONLY.html Thanks
  24. Yes , like this : var Thrower = function () { var self = this; this.idTag = 'thrower'; this.x = (canvas.width / 2); this.y = canvas.height - 64; this.width= 64; this.height = 64; this.speedX = 1; this.speedY = 0; this.visible = true; this.directionX = 5; this.moveMe = false ; this.update = function() { self.x = self.x + (self.speedX * self.directionX); // always either +1 or -1 } self.moveMe = false ; } } Thanks
×
×
  • Create New...