Search the Community

Showing results for tags 'null'.



More search options

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • HTML5 Game Coding
    • News
    • Game Showcase
    • Coding and Game Design
  • Frameworks
    • Phaser
    • Pixi.js
    • Babylon.js
    • Panda.js
    • melonJS
    • Haxe JS
    • Kiwi.js
  • General
    • General Talk
  • Business
    • Collaborations (un-paid)
    • Jobs (Hiring and Freelance)
    • Services Offered

Found 12 results

  1. Hi, I am trying to make a simple game and have been running into many problems. The problem I am facing now is that I cannot fix this error in my javascript. It says that it cannot read the 'setSize' property on my 'player' sprite, but it works perfectly fine on my other sprites. Next it says that it cannot read the 'velocity' property of the 'player' sprite, but when I comment out the 'setSize' property it works. I just cannot figure out what is wrong, have I misspelled something? I cannot seem to find the problem, so any help would be appreciated. Btw, it worked yesterday, but when I loaded it up today it was no longer working... Html: <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Simple Canvas Game</title> <link href="https://fonts.googleapis.com/css?family=Syncopate:700" rel="stylesheet"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <style> html { background: black } canvas { margin: auto; } h1 { font-family: 'Syncopate', sans-serif; color: rgb(194, 68, 91); text-align: center; margin: 0 auto; font-size: 25px; } h2 { color: white; font-size: 8px; font-family: 'Syncopate', sans-serif; } </style> </head> <body> <header> <h1>Crafty Heroes</h1> </header> <footer> <h2>&copy; SoulesteDesigns 2017</h2> </footer> <script src="phaser.js"></script> <script src="game.js"></script> </body> </html> game.js: // VARIABLES // variables for static objects var walls; var house; var gate; var gate2; // variables for character var cursors; var player; var left; var right; var up; var down; var game = new Phaser.Game(550, 540, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render: render }); // ADD HOUSES function addHouse(image) { house = game.add.physicsGroup(); house.create(-250, -240, 'greenhouse'); house.setAll('body.immovable', true); } // ADD FENCES OR WALLS function addWalls(image) { walls = game.add.physicsGroup(); // fences up top walls.create(-90, -200, 'fencefront'); walls.create(5, -200, 'fencefront'); walls.create(100, -200, 'fencefront'); walls.create(195, -200, 'fencefront'); // fences to right walls.create(288, -200, 'fenceright'); walls.create(288, -135, 'fenceright'); walls.create(288, -70, 'fenceright'); walls.create(288, -5, 'fenceright'); // fences at bottom walls.create(5, 59, 'fencefront'); walls.create(100, 59, 'fencefront'); walls.create(195, 59, 'fencefront'); // fences to left walls.create(-91, -200, 'fenceleft'); walls.create(-91, -135, 'fenceleft'); // set the walls to be static walls.setAll('body.immovable', true); } // PRELOAD IMAGES FOR ITEMS, PLAYERS, ETC. function preload() { // preload player game.load.spritesheet('player', 'hero.png', 64, 64); // preload houses game.load.image('greenhouse', 'greenhouse.png'); // preload fences game.load.image('fencefront', 'fencefront.png'); game.load.image('fenceleft', 'fenceleft.png'); game.load.image('fenceright', 'fenceright.png'); // fence that has adjusted hit boundary game.load.image('gate', 'fenceleft.png'); game.load.image('gate2', 'fencefront.png'); // preload ground game.load.image('ground', 'tiles2.png'); } // ADD THINGS TO GAME function create() { // set area that the player may travel to game.world.setBounds(-250, -250, 550, 550); // set background color game.stage.backgroundColor = ('#3c6f42'); gate = game.add.physicsGroup(); game.physics.startSystem(Phaser.Physics.ARCADE); gate = game.add.sprite(-91, -70, 'gate'); gate.name = 'gate'; game.physics.enable([gate], Phaser.Physics.ARCADE); // This adjusts the collision body size to be a 100x50 box. // 50, 25 is the X and Y offset of the newly sized box. gate.body.setSize(15, 90, -2, 3); gate.body.immovable = true; gate2 = game.add.physicsGroup(); game.physics.startSystem(Phaser.Physics.ARCADE); gate2 = game.add.sprite(-90, 59, 'gate2'); gate2.name = 'gate2'; game.physics.enable([gate2], Phaser.Physics.ARCADE); // This adjusts the collision body size to be a 100x50 box. // 50, 25 is the X and Y offset of the newly sized box. gate2.body.setSize(90, 15, 3, 3); gate2.body.immovable = true; // adding the ground var ground = game.add.sprite(-224, -100, 'ground', 1); var ground = game.add.sprite(-224, -60, 'ground', 1); var ground = game.add.sprite(-224, -20, 'ground', 1); var ground = game.add.sprite(-224, 20, 'ground', 1); var ground = game.add.sprite(-184, 20, 'ground', 1); var ground = game.add.sprite(-144, 20, 'ground', 1); // add player image and place in screen player = game.add.sprite(-232, -100, 'player'); player.smoothed = true; player.scale.set(.9); player.body.setSize(30, 40, 16, 16); player.body.immovable = false; // player will "collide" with certain images like walls and houses player.collideWorldBounds = true; // ANIMATION FOR PLAYER CONTROLS down = player.animations.add('down', [0,1,2,3], 10, true); left = player.animations.add('left', [4,5,6,7], 10, true); right = player.animations.add('right', [8,9,10,11], 10, true); up = player.animations.add('up', [12,13,14,15], 10, true); // enable physics in the game (can't go through walls, gravity, etc.) game.physics.enable([player, house, walls, gate], Phaser.Physics.ARCADE); game.physics.startSystem(Phaser.Physics.P2JS); game.physics.startSystem(Phaser.Physics.ARCADE); game.physics.p2.enable(player); // make sure to add this code to add items/walls/buildings addHouse(); addWalls(); // enable keyboard arrows for controls cursors = game.input.keyboard.createCursorKeys(); // camera will follow the character game.camera.follow(player); } // what happens when player does something function update() { // player will now collide with these images rather than pass over them game.physics.arcade.collide(player, house); game.physics.arcade.collide(player, walls); // PLAYER CONTROLS player.body.velocity.set(0); // player presses left key if (cursors.left.isDown) { player.body.velocity.x = -100; player.play('left'); } // player presses right key else if (cursors.right.isDown) { player.body.velocity.x = 100; player.play('right'); } // player presses up key else if (cursors.up.isDown) { player.body.velocity.y = -100; player.play('up'); } // player presses down key else if (cursors.down.isDown) { player.body.velocity.y = 100; player.play('down'); } // player does not press anything else { player.animations.stop(); } } function render() { game.debug.bodyInfo(gate2, 32, 32); game.debug.body(gate2); game.debug.bodyInfo(player, 32, 32); game.debug.body(player); }
  2. Cannot read property 'normal' of null

    First off BabylonJS is awesome! I am having a problem with CSG currently. This error I get only seems to happen on Chrome on Windows. Edge on Windows and all Mac works fine. I have an app that is creating CSG on the fly. This is for a foam case building app that I am working on. For a gun shape that has two circles for finger notches as seen in the 2d image below. You can also see in the image below the points of the polygon I am rendering. We've added two circles to the render as well. When I run this as a `CSG subtract` in BabylonJS on Chrome on Windows for certain shapes, with an example below. I get the following error: Uncaught TypeError: Cannot read property 'normal' of null at Plane.splitPolygon (eval at globalEval (app.js:1), <anonymous>:48668:68) at Node.build (eval at globalEval (app.js:1), <anonymous>:48826:28) at Node.build (eval at globalEval (app.js:1), <anonymous>:48836:27) at Node.build (eval at globalEval (app.js:1), <anonymous>:48836:27) at Node.build (eval at globalEval (app.js:1), <anonymous>:48836:27) at Node.build (eval at globalEval (app.js:1), <anonymous>:48836:27) at Node.build (eval at globalEval (app.js:1), <anonymous>:48836:27) at Node.build (eval at globalEval (app.js:1), <anonymous>:48836:27) at Node.build (eval at globalEval (app.js:1), <anonymous>:48836:27) at Node.build (eval at globalEval (app.js:1), <anonymous>:48836:27) This error is a little bit beyond my understanding of Babylon. I don't think that I have any complex lines where the lines are over lapping one another and I also don't know how to catch this error. Would be great to be able to catch the error if we can't fix it. Again thanks for the great library.
  3. Hi, How can I retrive heightmap vertices? I tried with the following: var Positions = ground.getVerticesData(BABYLON.VertexBuffer.PositionKind); It returns null. Is there a speical way to get all the vertices from my height map?
  4. I have searched a few times on this forum for this issue, but I can't seem to fix it based on the results. I want to set up collision based on a polyline, so I add the info GW.game.load.tilemap('collision', 'assets/ghost-wizard.json', null, Phaser.Tilemap.TILED_JSON);And then: GW.map = GW.game.add.tilemap('collision');GW.layer = GW.map.createLayer('collision');On the createLayer line it is throwing the error, 'collision' is the name of the layer as well as the tilemap. When I inspect the element sent to the createLayer method I notice that the layer property is a completely emptya array. I have not altered the tilted JSON info at all. I am using Phaser version 2.0.5 dev branch. Any tips to help figure this one out. Or let me know if you have if any other info is needed. Thanks
  5. When trying to clean up my stage on game over, I loop through my game object groups and destroy all children inside explicitly. Then I destroy the (now empty) groups: cleanGroup(Grp1); // Grp1 is child of Stage groupcleanGroup(Grp2); // Grp2 is child of Stage groupcleanGroup(Grp3), // Grp3 is child of Stage groupcleanGroup(Stage);var cleanGroup = function(Grp) { if (Grp.children) { while (Grp.children.length) Grp.removeChildAt(0).destroy(); } Grp.destroy(); }However, this always gives me a hole bunch of error messages like: this.children is null this.parent is null o is null The error messages are constantly repeating as if it where within a loop anywhere inside the Pixi render enginge. Why is this and how could this be solved? Do I need to destroy my created sprites and groups at all or is it enough just to remove all of my references to them and let the garbage collection do the rest? Would this be reliable?
  6. Hi guys, i'm having trouble with this code , the error is "Cannot read property 'velocity' of null" in player.body.velocity.y = Math.abs(playerSpeed); <!doctype html> <html lang="en"> <head> <meta charset="UTF-8" /> <title>Drop Wizard</title> <script type="text/javascript" src="phaser.min.js"></script> <style type="text/css"> body { margin: 0; } </style></head><body><script type="text/javascript">var game = new Phaser.Game(480, 320, Phaser.CANVAS, '', { preload: preload, create: create, update: update });var playerSpeed = 150;var player;var platformGroup;function preload() { game.load.image("platform180","platform180.png"); game.load.image("platform120","platform120.png"); game.load.image("player","player.png"); game.load.image("ground","ground.png");}function create() { platformGroup = game.add.group(); game.physics.startSystem(Phaser.Physics.ARCADE); player = game.add.sprite(240,0,"player"); player.anchor.setTo(0.5); game.physics.enable(player,Phaser.Physics.Arcade); game.physics.arcade.gravity.y = playerSpeed; addPlatform(240,60,"platform180"); addPlatform(340,140,"platform120"); addPlatform(140,140,"platform120"); addPlatform(420,220,"platform120"); addPlatform(60,220,"platform120"); addPlatform(100,316,"ground"); addPlatform(380,316,"ground"); game.input.onDown.add(changeDir,this);}function addPlatform(posX,posY,asset){ platform = game.add.sprite(posX,posY,asset); platform.anchor.setTo(0.5); game.physics.enable(platform,Phaser.Physics.ARCADE); platform.body.allowGravity = false; platform.body.immovable = true; platformGroup.add(platform);}function update() { player.body.velocity.y = Math.abs(playerSpeed); player.body.velocity.x = 0; player.body game.physics.arcade.collide(player, platformgroup, movePlayer); if(player.y>320){ player.y = 0 } if(player.x<12){ player.x=12; playerSpeed*=-1 } if(player.x>468){ player.x=468; playerSpeed*=-1 }trace(player); trace(player.body) trace(player.body.velocity)}function movePlayer(){ player.body.velocity.x = playerSpeed} function changeDir(){ playerSpeed *= -1; }</script></body></html>
  7. game.load.image (load is null?)

    Hi there guys I have one that is bugging me. I'm an old back end dev, but new to js. And in the process of my first decent project, I encountered this issue. In my custom main 'class', I keep a this.game which I instantiate to a phaser Game. Doing a console.debug on it, I can verify that it's a valid Game object. Adding states to it works fine, but in my preload, I realised that 'this.game.load.image()' borks out, because 'cannot read image on null'. console.debug this.game.load yields NULL console.debug this.game yields a valid phaser Game It is like load is not in there, and it makes no sense, all the documentation is doing it this way. If you look at my console debug below, that is where I am checking it. It fails the game.load check directly after instantiating Game. var SwagMain = function (resX, resY, renderer, parentElement, antiAlias) { if (typeof(antiAlias) === 'undefined') antiAlias = true; if (typeof(parentElement) === 'undefined') parentElement = ''; this.resolutionX = resX; this.resolutionY = resY; this.renderer = renderer; this.parentElement = parentElement; //this.antiAlias = antiAlias; this.game = null; this.initialise();}SwagMain.prototype.initialise = function () { console.log('initialise running...'); if (this.game === null) { this.game = new Phaser.Game( this.resolutionX, this.resolutionY, this.renderer, this.parentElement ); console.log('------------- -- - - - -----------'); console.debug(this.game); console.log('------------- -- - - - -----------');Hope someone can show me where I am being an idjit. Thanks. Marlon
  8. Hey everyone, I am a little new to phaser but I am currently having a problem that I am sure not many of you would have encountered due to its uniqueness. so right now I am creating a game that needs to be destroyed a number of times. The reason I do this is because after I destroy the game the players will view the high scores of other players (multiplayer games) and that it accomplished by routes without reloading. after a duration I will be routed back to a new instance of the game. I have pin pointed the error from logs. It comes from the this.context.createBuffer in the unlock function. For some reason after the 5th time I create a game and I do a mouse click i get an error when phaser tries to create the buffer due to context being null. TypeError: null is not an object (evaluating 'this.context.createBuffer'). Would this be some memory leaks? Every time the game finishes I call destroy on the game to clean up resources and set it to null for garbage collection, but as of now I am stumped. Can anyone help??? Thank you!
  9. Hi, I'm learning to make games Phaser, watching a tutorial to create the Pong. For starters, I have to draw all elements in screen, which are ball and two rackets. Failure to draw the ball, the ball is only draws and no draws snowshoes. The code is as follows <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Pong</title> </head> <body> <div id="ejemplo"></div> <script src="phaser.min.js"></script> <script> window.onload = function(){ var game = new Phaser.Game(640, 480, Phaser.CANVAS, 'ejemplo', { preload: preload, create: create, update: update }); var playerBet; var computerBet; var ball; var computerBetSpeed = 190; var ballSpeed = 300; function preload() { game.load.image('bet', 'assets/rocket.png'); game.load.image('ball', 'assets/ball.png'); game.load.image('background', 'assets/backg.png'); } function create() { game.add.tileSprite(0, 0, 640, 480, 'background'); ball = game.add.sprite(game.world.centerX, game.world.centerY, 'ball'); ball.anchor.setTo(0.5, 0.5); ball.body.collideWorldBounds = true; ball.body.bounce.setTo(1, 1); computerBet = createBet(620, game.world.centerY); playerBet = createBet(20, game.world.centerY); computerBet.body.collideWorldBounds = true; computerBet.body.bounce.setTo(1, 1); computerBet.body.immovable = true; } function update () { } //Funciones function createBet(x, y) { var bet = game.add.sprite(x, y, 'bet'); bet.anchor.setTo(0.5, 0.5); bet.body.collideWorldBounds = true; bet.body.bounce.setTo(1, 1); bet.body.immovable = true; return bet; } }; </script> </body> </html> and failure I get is: Uncaught TypeError: Can not set property 'collideWorldBounds' of null In line 39, that is: ball.body.collideWorldBounds = true; Help me please!!
  10. Sprites not recycling

    Hi, I'm new (another one) with phaser. I did a test game without problems (or almost) but now I'm doing a game that throws objects ad infinitum. In order to do this I'm sprite recycling. I have a group of sprites with outOfBoundsKill and checkWorldBounds set to true. And then when it's time to throw an object I fetch the first that does not exists. Here's my code: // Coinsthis.coins = this.add.group();this.coins.enableBody = true;this.coins.physicsBodyType = Phaser.Physics.ARCADE;this.coins.createMultiple(4, 'coin');this.coins.setAll('outOfBoundKill', true);this.coins.setAll('checkWorldBounds', true);And this is the function to throw coins (from the bottom of the world to the top): throwSomething() { this.coin = this.coins.getFirstExists(false); this.coin.reset(this.throwers_x[droperNumber], this.throwers_y); this.coin.animations.add('spin', [0, 1, 2, 3, 4, 5, 6, 7], 10, true); this.coin.play('spin'); this.coin.body.gravity.y = -300; this.dropingTimer = this.game.time.now + 2000;}The moment all coins are created there's no coins with exists set to false. It should be, since outOfBoundKill is on. The animation add and play, and the body.gravity were in the create function at the beginning, but I changed to test things. Any ideas?
  11. Hi everyone, i followed the tutorial on http://www.photonstorm.com/phaser/tutorial-making-your-first-phaser-game, till World Building. There i got the issue that ground.body.immovable = true; can not be set, since ground.body is null. I am using version 2.0 of phaser, maybe that is part of the problem. I hope someone can help me out, thanks in advance.
  12. onInputDown is null

    Hello, I basically cloned the Phaser example 02 - Click on an image and I am getting an error when trying to add the listener to my sprite. Error: Uncaught TypeError: Cannot call method 'add' of null The problem line is commented below. Has anyone else come across this? function preload() { game.load.image('pic','assets/Pic.jpg');}function create() { var img = game.add.sprite(0,0,'pic'); img.input.enabled = true; //Here is where I get the error //Uncaught TypeError: Cannot call method 'add' of null img.events.onInputDown.add(listener, this);}function listener(){ console.log("click");}