Sam987X

Members
  • Content count

    8
  • Joined

  • Last visited

Everything posted by Sam987X

  1. Hi ive been making a game with phaser and ive set out my game to have each game state a separate java-script and then loads the js file when it needs game.add.tween(BlackFade).to( {alpha: 1}, 100, "Linear", true ) console.log(BlackFade.alpha) if (BlackFade.alpha >= 0.9 ){game.state.start('endGame');} WebSocket connection to 'ws://localhost:8125/' failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED VM143:870 This is the error i get ^^
  2. Hi i'm quite new with phaser but i'm making a game at the moment for a class project and i was wondering if their is a way to choose a specific sprite from a group of sprites.like maybe by order of how they were created or something . any help would be much appreciated
  3. Collision error with arcade physics

    Hi i'm quite new to phaser but ive been making this game for a school project where you control a helicopter and when the helicopter body collides with the water refill building it refills the water but if i go up against the side of the building and change direction it flips my helicopter so that it flys the other direction which then makes the helicopter overlapping the water refill building and my game crashes and i get this error Game.js:342 Uncaught ReferenceError: refill is not defined at Function.<anonymous> (Game.js:342) at Phaser.Physics.Arcade.collideSpriteVsSprite (phaser.js:80431) at Phaser.Physics.Arcade.collideSpriteVsGroup (phaser.js:80520) at Phaser.Physics.Arcade.collideHandler (phaser.js:80369) at Phaser.Physics.Arcade.overlap (phaser.js:80121) at Object.update (Game.js:341) at Phaser.StateManager.update (phaser.js:30658) at Phaser.Game.updateLogic (phaser.js:38763) at Phaser.Game.update (phaser.js:38707) at Phaser.RequestAnimationFrame.updateRAF (phaser.js:61260) function Refill() { water = 3 } game.physics.arcade.overlap(player, WaterBuildings, function (overlappingPlayer, overlappingWaterBuildings) { refill() }); any help would be much appreciated
  4. Window resize/fullScreen

    Hi in my game i have got it so that when i click on the screen it will toggle full screen and it works perfectly without any problems but when i go and debug my code i get these errors .Any help would be much appreciated Uncaught TypeError: Cannot read property 'dispatch' of undefined at Phaser.ScaleManager.fullScreenChange (phaser.js:37411) at HTMLDocument._fullScreenChange (phaser.js:36175) WebSocket connection to 'ws://localhost:8125/' failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED game.scale.fullScreenScaleMode = Phaser.ScaleManager.SHOW_ALL; game.input.onDown.add(gofull, this); function gofull() { if (game.scale.isFullScreen) { game.scale.stopFullScreen(); game.state.restart(); } else { game.scale.startFullScreen(false); game.state.restart(); } this.scale.pageAlignHorizontally = true; this.scale.pageAlignVertically = true; } .
  5. Timed events loop

    Hi so im using phaser trying to get my program to subtract 1 from my varriable every second, how do i go about doing this im trying to use somthing like this var CountDownTime = 3 function GameStartCountDown(CountDownTime){ CountDownTime -- } setInterval(GameStartCountDown, 1000)
  6. Overlap with groups problem

    Hi i am quite new to phaser, but I've been making this game and in my game i have the player dropping water from a helicopter on burning buildings, the program spawns 5 buildings then adds them to the group buildings and in my update function it checks when the water is overlapping the buildings it will destroy the water, it does this but the water gets destroyed if i drop the water between buildings and also destroys it at the same height regardless of how tall the buildings are. Any help would be much appreciated ps i included a picture of my game at the moment to give you an idea of what my problem is thanks! shorter code function create() { building = game.add.sprite(20, 426, 'building1.'); buildings = game.add.group(); //creates initial building function SpawnBuildings(){ building = game.add.sprite(building.x + Math.floor(Math.random() * 200)+200,605, 'building'+Math.floor(Math.random()*10/2+1)+'.'); building.anchor.setTo(0,1) game.physics.arcade.enable(building); building.body.immovable = true; building.body.allowGravity = false; building.scale.setTo(.75,.75) buildings.add(building); //spawns the rest of buildings function update() { if (checkOverlap(waterDrop, buildings)) { waterDrop.kill(); } } whole project : window.onload = function() { var game = new Phaser.Game(864, 648, Phaser.CANVAS, 'gameScreen', { preload: preload, create: create, update: update, render: render }); function preload() { game.load.image('sky', 'images/sky.png', 1728, 1296); game.load.image('road', 'images/Road.png'); game.load.spritesheet('player', 'images/Helicopter.png', 100, 28, 5); game.load.image('dirt', 'images/dirt.png', 60, 60); game.load.image('water', 'images/water1.png', 'images/water2.png'); game.load.image('building1.', 'images/Buildings/1.png'); game.load.image('building2.', 'images/Buildings/2.png'); game.load.image('building3.', 'images/Buildings/3.png'); game.load.image('building4.', 'images/Buildings/4.png'); game.load.image('building5.', 'images/Buildings/5.png'); game.load.spritesheet('fire', 'images/fire2.png', 528, 549, 2); } var timer; var total = 0; var player; var building; var waterDrop; var buildings; var Grounded; var LeftX = 0 var RightX = 1296 function create() { //Game Hud varriables points = 0 ; water = 10; time = 50; count = 0; //level bounds //this.game.world.setBounds(0, 0, 1296, 600); //letterBox scaling fullscreen game.scale.fullScreenScaleMode = Phaser.ScaleManager.SHOW_ALL; game.input.onDown.add(gofull, this); function gofull() { if (game.scale.isFullScreen) { game.scale.stopFullScreen(); game.state.restart(); } else { game.scale.startFullScreen(false); game.state.restart(); } this.scale.pageAlignHorizontally = true; this.scale.pageAlignVertically = true; } game.physics.startSystem(Phaser.Physics.ARCADE); buildings = game.add.group(); waterDrops = game.add.group(); waterDrop = game.add.sprite(-1000, 0 + 10, 'water'); sky = game.add.tileSprite(0, 0, 1296,this.game.height, 'sky') dirt = game.add.tileSprite(0, 600, 1296,this.game.height, 'dirt') road = game.add.tileSprite(0, 600, 1296,20, 'road') player = game.add.sprite(100, 415, 'player'); building = game.add.sprite(20, 426, 'building1.'); game.world.swap(building,sky); game.world.sendToBack(building) WaterBuilding = game.add.sprite(20, 426, 'building1.'); //buildings.add(building); game.physics.arcade.enable([player, building, waterDrop,WaterBuilding]); game.physics.arcade.enable([buildings, waterDrop]); game.physics.arcade.gravity.y = 200; var fly = player.animations.add('fly'); player.animations.play('fly', 30, true) //set player image anchor player.anchor.setTo(.5,.5) player.body.bounce.y = 0.1; player.body.collideWorldBounds = true; player.body.setSize(70,26,-12) game.camera.follow(player); WaterBuilding.body.allowGravity = false; WaterBuilding.body.immovable = true; building.body.allowGravity = false; building.body.immovable = true; if (count < 5){ SpawnBuildings() } if (count => 3){ game.world.swap(buildings, sky); } //Hud text Score, water, timeLeft scoreText = game.add.text(20, 16, 'Score:', { fontSize: '32px', fill: '#000' }); scoreText.fixedToCamera = true; waterLeft = game.add.text(700, 16, 'Water:', { fontSize: '32px', fill: '#000' }); waterLeft.fixedToCamera = true; //timeLeft timeLeft = game.add.text(700, 66, 'Time:', { fontSize: '32px', fill: '#000' }); timeLeft.fixedToCamera = true; //time left countdown timer = game.time.create(false); timer.loop(1000, TimeCountdown, this); function TimeCountdown() { if (time > 0) { time -- } } timer.start() EndBackground = game.add.tileSprite(0, -1296, 1296,this.game.height, 'sky') //Keybord keys //arrow keys this.leftKey= game.input.keyboard.addKey(Phaser.Keyboard.LEFT); this.rightKey= game.input.keyboard.addKey(Phaser.Keyboard.RIGHT); this.upKey= game.input.keyboard.addKey(Phaser.Keyboard.UP); this.downKey= game.input.keyboard.addKey(Phaser.Keyboard.DOWN); //A & B button(red and blue)/A & S keys this.AKey= game.input.keyboard.addKey(Phaser.Keyboard.A); this.SKey= game.input.keyboard.addKey(Phaser.Keyboard.S); this.RKey= game.input.keyboard.addKey(Phaser.Keyboard.R); game.input.keyboard.addKeyCapture([ Phaser.Keyboard.LEFT, Phaser.Keyboard.RIGHT, Phaser.Keyboard.A, Phaser.Keyboard.S, Phaser.Keyboard.R]); } function hitBuilding (waterDrop, buildings) { points =+1 } function WaterDropping(){ waterDrop = game.add.sprite(player.x, player.y + 10, 'water'); game.physics.arcade.enable(waterDrop); waterDrop.body.gravity.y = 3000; var Water = waterDrop.animations.add('Water'); waterDrop.scale.setTo(.5,.5) waterDrops.add(waterDrop); } function SpawnBuildings(){ building = game.add.sprite(building.x + Math.floor(Math.random() * 200)+200,605, 'building'+Math.floor(Math.random()*10/2+1)+'.'); building.anchor.setTo(0,1) game.physics.arcade.enable(building); building.body.immovable = true; building.body.allowGravity = false; building.scale.setTo(.75,.75) buildings.add(building); fire = game.add.sprite(building.x+(building.width/2),building.y-building.body.height/2,'fire'); fire.scale.setTo(.25,.25); var blaze = fire.animations.add('blaze'); fire.animations.play('blaze', 8, true); fire.anchor.setTo(.5,.5) count ++; } function RestartGame(){ game.state.restart() } function AddScore(points){ points =+ 10; } function Refill(){ water = 10 } function update() { //var LeftX = 0 //var RightX = 1296 this.game.world.setBounds(LeftX, 0, RightX, 600); game.physics.arcade.collide(player, buildings,RestartGame); game.physics.arcade.collide(player, WaterBuilding, Refill) //game.physics.arcade.collide(waterDrop, buildings, AddScore) if (checkOverlap(waterDrop, buildings)) { waterDrop.kill(); AddScore(points) points = 1 } else{ points = 0 } /*if (checkOverlap(waterDrop, WaterBuilding)) { waterDrop.kill(); } */ if (count < 4) { SpawnBuildings() } if (time == 0) { EndBackground.y = 0 water = 5 } //update HUD text water,time, score scoreText.text = "Score:"+points timeLeft.text = "Time:"+time waterLeft.text = "Water:"+water if (water < 0) { water = 0 } if (this.leftKey.isDown) { player.body.setSize(70,26,12) player.body.setSize(70,26,12) player.body.velocity.x = -150; player.scale.x = -1; if (player.angle != -20) { player.angle -= 5 } } else if ((this.leftKey.isDown) && (player.angle == 30)) { player.angle = 0 player.body.velocity.x = -150; player.scale.x = -1; if (player.angle <= -20) { player.angle -= 5 } } if ((this.rightKey.isDown)) { player.body.setSize(70,26,-12) player.body.velocity.x = 150; player.scale.x = 1; if (player.angle <= 20) { player.angle += 5 } } else if ((this.rightKey.isDown) && (player.angle == 330)) { player.body.setSize(70,26,-12) player.angle = 0 player.body.velocity.x = 150; player.scale.x = 1; if (player.angle <= 20) { player.angle += 5 } } if (this.upKey.downDuration(1)) { LeftX =+ 1296 RightX =+ 1296 } if (!((this.leftKey.isDown) || (this.rightKey.isDown))) { player.angle = 0; player.body.velocity.x = 0; } function ResetAngle(player){ player.angle = 0} if (this.AKey.isDown) { player.body.velocity.y = -185; } if (this.RKey.downDuration(1)) { LeftX = 0; RightX = 1296 this.game.world.setBounds(LeftX, 0, RightX, 600); game.state.restart() } if ((this.SKey.downDuration(1)) && water > 0) { water -= 1 WaterDropping() } } function checkOverlap(spriteA, spriteB) { var boundsA = spriteA.getBounds(); var boundsB = spriteB.getBounds(); return Phaser.Rectangle.intersects(boundsA, boundsB); } function render() { game.debug.body(buildings); game.debug.spriteInfo(building, 32, 82); //game.debug.body(fire); game.debug.body(player); game.debug.spriteInfo(player, 32, 250); // } }
  7. Overlap with groups problem

    Yes this worked thank you !
  8. Overlap with groups problem

    I added in the code but my building bodys are not bigger than the image