ItsYaBoiWesley

Members
  • Content Count

    21
  • Joined

  • Last visited

About ItsYaBoiWesley

  • Rank
    Member

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

  1. ItsYaBoiWesley

    So, what's the deal with sound?

    Can anyone help me out here? I suppose I need more explicit instruction...
  2. ItsYaBoiWesley

    So, what's the deal with sound?

    I looked at this code. While I found it helpful, I still don't know the exact line of code that unlocks. What exactly does the unlocking? I'm just confused - JavaScript is still pretty new for me so looking at the Phaser code is a little confusing.
  3. ItsYaBoiWesley

    So, what's the deal with sound?

    Ok, can you give me an example of an "allow" function to allow this on initialization?
  4. ItsYaBoiWesley

    So, what's the deal with sound?

    Hi! I've been trying to get my JavaScript game to play sound using the HTML5 audio stuff. I am getting a security error when I run the ".play" method. From my research, this is a new security measure implemented into Google Chrome regarding auto-play on websites. Does anyone know how to get around it? Uncaught (in promise) DOMException: play() failed because the user didn't interact with the document first. I've tried the "SoundJS" and "HowlerJS" libraries. Both of these libraries are rendered inoperable by the new error. The only workaround I've found is making audio play (running ".play()" on a keypress) This makes sense, as Chrome doesn't want its users being caught off guard with random audio. However, I need my game to play audio on its own accord. (sound effects, some ambiant music randomly begins, etc) Right now, I'm trying the instructions found here. When I put that exact code into my code, it throws the error - but when I play the demo on their site of presumably the same code, it runs fine and I can hear the sound in their example. How come I can here everything fine in their example, but their exact code throws an error in mine? (And doesn't play any sound!) Any help with this issue would be awesome. I'm so tired of trying different libraries, different methods, trying to work with the "Promise" system, and more. So believe me, any help would be GREATLY appreciated! Yikes! 😂
  5. ItsYaBoiWesley

    Trying to Save a Class Javascript

    Thanks! I got it now. I added an exportString and importString methods to my classes. They simply take all relevant data about an entity, stick it in an array, and stringify it. Then this data is easy to transport.
  6. ItsYaBoiWesley

    Trying to Save a Class Javascript

    Hi! I'm trying to save game data in JavaScript, using "localStorage". I have a class called "Entity" with its own variables and functions. I have an array called "loadedEntities" which contains instances of the Entity class. For example var zombie = new Entity(args) var spider = new Entity(args) loadedEntities = [zombie, spider] I want to save the entirety of "loadedEntities." To do this, I use JSON.stringify(loadedEntities). (I save the entire array in one big gulp) Then, when I want to load the data back into the game, I use JSON.parse(). (My load function sets loadedEntities equal to whatever JSON.parse() returns.) Now, whenever I try to run a function on an entity, (The entity class has its own functions. So, loadedEntities[0].move() or loadedEntities[1].attack()) I get the following error: loadedEntities[i].attack is not a function //i is a good and proper variable. Everything works fine when a "New Game" is selected. The issue definitly has to do with saving My theory is that when I save instances of the Entity class, the data might get saved but the functions, like "attack()" don't get saved or something. I don't know, what do you guys think?
  7. ItsYaBoiWesley

    Initializing a 2D Array with a Ton of Zeroes

    This worked, thanks!
  8. Hi! I'm trying to make a 2D array with a ton of zeroes. For some reason, this does not work. (By does not work, I mean I get errors when accessing the array. If I initialize the array manually, it's smooth sailing.) var blankRow = []; for(var x = 0; x < world[0].length; x++) { blankRow.push(0); } for(var y = 0; y < world.length; y++) { processedWorld.push(blankRow); } It pushes the blank row full of zeroes (the horizontal axis) then pumps that into the destination array (processedWorld, the vertical axis) What am I screwing up P.S. "world" is a different array from "processedWorld" and has already been defined, and works perfectly.
  9. ItsYaBoiWesley

    Encode Every Pixel into Array Quickly

    Well, sorry guys! I've changed my entire system 😕 No longer doing color based collision detection, I am rather doing a more conventional system with a genuine tilemap, which is then translated into canvas visual output. Thanks for all of the support, though! I hope someone in the future finds this helpful!
  10. ItsYaBoiWesley

    Encode Every Pixel into Array Quickly

    Oh, so I got down the pixel color thing. As in, I can get the pixel color of an X, Y, coordinate. But I need to get it into this format for the pathfinding library. var grid = [[0,0,1,0,0], [0,0,1,0,0], [0,0,1,0,0], [0,0,1,0,0], [0,0,0,0,0]]; That's what's giving me trouble. I've tried some iteration stuff but I'm confused. (Obviously this will be a much bigger array than the example)
  11. ItsYaBoiWesley

    Encode Every Pixel into Array Quickly

    Ok, cool! But how do I map the data from getImageData into an array?
  12. ItsYaBoiWesley

    Encode Every Pixel into Array Quickly

    Hi! I'm making a maze game which uses color based collision detection, for the sake of using image mazes easily. My player detects if there is black in front of it, if there is not it can walk in that direction, if there is it will be stopped. Now I'm coding the enemy, using "easystarjs" for pathfinding. They require an array of walkable (white in my game) and non-walkable (black in my game) information. So, I thought of making a 2D array, which has a slot for every pixel. Using for loops, I would encode every pixel into its proper position on the array using either 1 (wall/black pixel) or 0 (not-wall/white pixel) I come from a C++ background, so I didn't think how slooowwww this would be in JavaScript. Is there any faster way I can do what I'm trying to do? It's likely this will need to run in the game LOOP, because the player moves.
  13. ItsYaBoiWesley

    CreateJS Noob - Problem with my Sprite class

    Oh my god! Updating the version worked! Thank you so much, the sprite is now moving happily across the screen. However, the sprite is not animated. It remains of frame 0 as it moves. (And yes, I fixed those names to be consistent in the class) I'm gonna keep working on figuring out why the sprite doesn't animate, it's probably just some dumb bug. But any insight you could give might help.
  14. ItsYaBoiWesley

    CreateJS Noob - Problem with my Sprite class

    Great! That issue has been solved. I also found those variables I needed to rename, thanks! New problem. When I hit a key, these errors appear repeatedly as I hold down or press the key. Still no sprite. My thoughts are that it has to do with the Sprite.draw() function. Uncaught RangeError: Maximum call stack size exceeded at a.b._normalizeFrame (createjs-2013.12.12.min.js:13) at a.b._normalizeFrame (createjs-2013.12.12.min.js:13) at a.b._normalizeFrame (createjs-2013.12.12.min.js:13) at a.b._normalizeFrame (createjs-2013.12.12.min.js:13) at a.b._normalizeFrame (createjs-2013.12.12.min.js:13) at a.b._normalizeFrame (createjs-2013.12.12.min.js:13) at a.b._normalizeFrame (createjs-2013.12.12.min.js:13) at a.b._normalizeFrame (createjs-2013.12.12.min.js:13) at a.b._normalizeFrame (createjs-2013.12.12.min.js:13) at a.b._normalizeFrame (createjs-2013.12.12.min.js:13) Thank you SO MUCH for all of this help! It's so great that you're so willing to be helpful!
  15. ItsYaBoiWesley

    CreateJS Noob - Problem with my Sprite class

    Ok. Same error. Here are both of my files in full. HTML: <!DOCTYPE html> <html> <head> <title>Cat & Mouse EYESIGHT DEMO</title> </head> <body> <link href="normalize.css" type="text/css" rel="stylesheet" /> <canvas id="demoCanvas" width="1000" height="1000"></canvas> <script language="javascript" type="text/javascript" src="http://code.createjs.com/createjs-2013.12.12.min.js" ></script> <script src="init.js"></script> </body> </html> INIT.JS: init = function() { var stage; var queue; var context; var canvas; var WIDTH = 1024; var HEIGHT = 768; class Circle { constructor() { //window.alert("constructor"); this.circ = new createjs.Shape(); //window.alert("E constructor"); } draw(x, y, s) { //window.alert("drawing"); this.circ.graphics.beginFill("DeepSkyBlue").drawCircle(0, 0, s); this.circ.x = x; this.circ.y = y; stage.addChild(this.circ); } } class Sprite { constructor(src, frameWidth, frameHeight) { window.alert("DEBUG constructor. " + src + ", " + frameWidth + ", " + frameHeight); // Create bat spritesheet this.spriteSheet = new createjs.SpriteSheet({ "images": [queue.getResult(src)], "frames": {"width": frameWidth, "height": frameHeight}, "animations": { "flap": [0,4] } }); window.alert("DEBUG econstrucor"); } draw(x, y) { var animation = new createjs.Sprite(this.spriteSheet, "ani"); animation.regX = 99; animation.regY = 58; animation.x = enemyXPos; animation.y = enemyYPos; animation.gotoAndPlay("ani"); stage.addChildAt(animation,1); } } function queueLoaded(event) { // Add background image var backgroundImage = new createjs.Bitmap(queue.getResult("backgroundImage")) stage.addChild(backgroundImage); } window.alert("initialized"); canvas = document.getElementById('demoCanvas'); context = canvas.getContext('2d'); context.canvas.width = WIDTH; context.canvas.height = HEIGHT; stage = new createjs.Stage("demoCanvas"); //QUEUE: queue = new createjs.LoadQueue(false); queue.installPlugin(createjs.Sound); queue.on("complete", queueLoaded, this); createjs.Sound.alternateExtensions = ["ogg"]; window.alert("createJS did stuff"); queue.loadManifest([ {id: 'backgroundImage', src: 'assets/background.png'}, {id: 'mouse', src: 'assets/mouse.png'}, ]); queue.load(); window.alert("manifest loaded"); var objX = 100; var objY = 100; var Spi = new Sprite('mouse', 198, 148); window.alert("rdy"); document.addEventListener('keydown', function(event) { if(event.keyCode == 37) { objX -= 10; } if(event.keyCode == 38) { objY -= 10; } else if(event.keyCode == 39) { objX += 10; } else if(event.keyCode == 40) { objY += 10; } Spi.draw(objX, objY); stage.update(); }); window.alert("done"); }() As you can see, everything is in the function like you said. 😕