TIS

Members
  • Content Count

    4
  • Joined

  • Last visited

  1. TIS

    enemy spawning

    Thank you But i think this is not the problem. The problem is just there when i try it with enemy = function(index, game){ this.enemyRed2 = game.add.sprite(200, 200, 'enemyRed');};and enemies.push(new enemy());Then i get the error "ReferenceError: game is not defined". If i just type it like this.enemyRed2 = add.sprite(200, 200, 'enemyRed');i get the error: "add is not defined". I tried a lot of things, but i can't figure it out :S
  2. TIS

    enemy spawning

    Thank you. And thanks for the good tip. Here is the rest of the game. <!doctype html><html> <head> <script src="js/phaser.min.js"></script> <script src="src/boot.js"></script> <script src="src/preload.js"></script> <script src="src/gametitle.js"></script> <script src="src/thegame.js"></script> <script src="src/gameover.js"></script> <style> body{margin:0} </style> <script> (function() { var game = new Phaser.Game(800, 600, Phaser.CANVAS, "game"); game.state.add("Boot",boot); game.state.add("Preload",preload); game.state.add("GameTitle",gameTitle); game.state.add("TheGame",theGame); game.state.add("GameOver",gameOver); game.state.start("Boot"); })(); </script> </head> <body> </body></html>var boot = function(game){ console.log("%cStarting the game", "color:white; background:red");}; boot.prototype = { preload: function(){ this.game.load.image("loading","assets/loading.png"); }, create: function(){ this.scale.scaleMode = Phaser.ScaleManager.SHOW_ALL; this.scale.pageAlignHorizontally = true; this.scale.setScreenSize(); this.game.state.start("Preload"); }}var preload = function(game){}preload.prototype = { preload: function() { var loadingBar = this.add.sprite(160,240,"loading"); loadingBar.anchor.setTo(0.5,0.5); this.load.setPreloadSprite(loadingBar); this.game.load.spritesheet("numbers","assets/numbers.png",100,100); this.game.load.image("gametitle","assets/title.png"); this.game.load.image("play","assets/play.png"); this.game.load.image("gameover","assets/gameover.png"); this.game.load.spritesheet("dude", "assets/dude.png", 22, 40); this.game.load.spritesheet("enemyRed", "assets/enemyRed.png", 22, 40); }, create: function() { this.game.state.start("GameTitle"); }}var gameTitle = function(game){}var gameTitle;var playButton;gameTitle.prototype = { create: function() { gameTitle = this.game.add.sprite(400,160,"gametitle"); gameTitle.anchor.setTo(0.5,0.5); playButton = this.game.add.button(400,320,"play",this.playTheGame,this); playButton.anchor.setTo(0.5,0.5); }, playTheGame: function(){ this.game.state.start("TheGame"); }}
  3. TIS

    enemy spawning

    Hi, i just want to spawn an enemy. But i can't figure out whats wrong with my code. It gives me the error "ReferenceError: game is not defined" I highlited the parts where i stuck. var theGame = function(game){};enemy = function(){ this.enemyRed2 = game.add.sprite(200, 200, 'enemyRed');};var player;var cursors;var enemies = [];theGame.prototype = { create: function() { this.game.stage.backgroundColor = '#c3c5a3'; player = this.game.add.sprite(100, 100, 'dude'); player.anchor.setTo(0.5, 0.5); player.animations.add('walk', [0, 1, 2, 3], 10, true); //player.animations.add('left', [0, 1, 2, 3], 10, true); this.game.physics.arcade.enable(player); cursors = this.game.input.keyboard.createCursorKeys(); this.wasd = { up: this.game.input.keyboard.addKey(Phaser.Keyboard.W), down: this.game.input.keyboard.addKey(Phaser.Keyboard.S), left: this.game.input.keyboard.addKey(Phaser.Keyboard.A), right: this.game.input.keyboard.addKey(Phaser.Keyboard.D), }; enemies.push(new enemy()); }, update: function() { player.rotation = this.game.physics.arcade.angleToPointer(player); player.body.velocity.y = 0; player.body.velocity.x = 0; if (cursors.down.isDown || this.wasd.down.isDown) { player.body.velocity.y = 150; } else if (cursors.up.isDown || this.wasd.up.isDown) { player.body.velocity.y = -150; } if (cursors.left.isDown || this.wasd.left.isDown) { player.body.velocity.x = -150; } else if (cursors.right.isDown || this.wasd.right.isDown) { player.body.velocity.x = 150; } if (player.body.velocity.y != 0) { player.animations.play('walk'); } else if (player.body.velocity.x != 0) { player.animations.play('walk'); } if (player.body.velocity.y == 0 && player.body.velocity.x == 0) { player.animations.stop(); player.frame = 0; } }}