khleug35

Members
  • Content Count

    141
  • Joined

  • Last visited

  • Days Won

    3

Everything posted by khleug35

  1. Could I code for a function in timer.events directly?? here is my code Normally ,The following code is work for me!!!!!!! game.time.events.add(Phaser.Timer.SECOND * 4, player_kill, this); function player_kill() { player.kill(); } but Is it possible to code for a function in timer.events directly??? THX Maybe like this , but the following code is not work, did I made a mistake?? Thank you so much game.time.events.add(Phaser.Timer.SECOND * 4, player.kill(), this); //not work
  2. here is my code <script> var game = new Phaser.Game(372, 635, Phaser.AUTO, 'game'); game.state.add('menu',menu); game.state.add('Level1',Level1); game.state.start('menu'); </script> //Level1.js var Level1 = { init: function() { this.play = true; <---------/*I want to call it in Enemy: function(){this.init = function()*/--> }, preload: function() { this.load.im.......... }, create: function() { this.enemy = new this.Enemy(); this.enemy.init(); }, update: function() { ........ }, Enemy: function(){ this.init = function (){ console.log(this.play); <-----------/*I want to call this.play = true, but it show undefined*/ if(this.play == true){ <-----------/*I want to call this.play = true, but it show undefined*/ dosomething..... }else{ dosomething..... } } I want to call "this.play = true; " in Enemy: function(){ this.init = function () but it is not successful......the chrome console is display show "undefined" How is it possible to call this function??? thx very much
  3. OH!!!! Thanks!!!!When i update to Phaser CE 2.8.8!!!! It worked for me!!!!! https://phaser.io/download/stable Thanks!!!!!!samme!!!!!!
  4. My code is here var game = new Phaser.Game('100%','100%', Phaser.AUTO, '', { init: init, preload: preload, create: create, update: update, }); var background; function init(){ game.scale.scaleMode = Phaser.ScaleManager.SHOW_ALL; } function preload() { game.load.image('space', 'assets/images/space.png'); } function create(){ background = game.add.tileSprite(0, 0, game.world.width, game.world.height, 'space'); background.autoScroll(0, 30); game.physics.enable(background,Phaser.Physics.ARCADE); } function update(){} When I run the game first time, It was worked, I can success to load the background. but when I refresh the game, it have error message and can't run the game. it said that phaser.2.7.7.min.js:3 Phaser.Cache.getImage: Key "__default" not found in Cache. getItem @ phaser.2.7.7.min.js:3 phaser.2.7.7.min.js:3 Phaser.Cache.getImage: Key "__missing" not found in Cache. getItem @ phaser.2.7.7.min.js:3 phaser.2.7.7.min.js:3 Uncaught TypeError: Cannot read property 'base' of null so when this error is happen, I need to clear cache form chrome or go to other page then return the game, it can success to run the game. but when I refresh the game, an error occurred.Does anyone know what problem is that ?? Thanks you very much
  5. OH!!!!!!Thanks It work for me!!!!!!!!!!! Thanks!! samid737!!!!!!!!!! Thx for your link!!!! My problem is solved!!!!!!
  6. THX finally, I use addChild() to add the player sprite, like this , I make the graphics's element follow the user graphics = game.add.graphics(0, 0); game.physics.arcade.enable(graphics); graphics.beginFill(0xFF0000, 1); player.addChild(graphics.drawCircle(0, 0, 30)); but when I move the player right left, the graphics's element position will change....... the graphics's element is leave the player body, how to fix it to center, thx I think that the scale problem is make it happen the problem............. if (faceRight == true) { player.scale.x *= -1; player.anchor.x = 0.5; player.x = player.x - 10; faceRight = false; faceLeft = true; bullet_direction = 'right'; } } and player.body.velocity.x = -250; if (faceLeft == true) { player.scale.x *= -1; player.anchor.x = 0.5; faceLeft = false; faceRight = true; bullet_direction = 'left'; }
  7. I would like to create some object follow the player movement , this situation like to call game.debug.body(player); method.......... the green square follow/pin the player any idea??? THX
  8. OH!!!!!Super Many Thanks Great !!! It Work for me !!!!!!!! Thanks!! magig!!!!!!!!!! Thx for your link!!!! My problem is solved!!!!!!
  9. Hello everyone, I am developing a platform game like Super Mario style. I try to build a lives list system. like the photo that named "full_lives.PNG." i use this code to make the lives group (number of heart's icon)display on screen. //list the lives icon(number of heart's icon) on screen lives = game.add.group(); lives.fixedToCamera = true; for (var i = 0; i < player_health; i++) { //player_health = 12; lives.create(300 - (i * 30), 0, 'live'); } When enemy collide the player or player get hurt, it remove one live in lives group and remove one heart's icon from screen // When enemy collide the player or player get hurt, it remove one live in lives group and remove one heart's icon from screen var reduce_heart = lives.getFirstAlive(); player_health = player_health -1; if (reduce_heart) { reduce_heart.kill(); } when the player heal his life, the lives will increase one live in lives group and one heart's icon from screen. //when the player heal his life, the lives will increase one live in lives group and one heart's icon from screen. var increase_heart = lives.getFirstExists(false); player_health = player_health +1; if (increase_heart) { increase_heart.revive(); } Here is my Problem, The heart's icon is increase in the lives list last position, you can see the photo that named "increase_health_icon.PNG". var increase_heart = lives.getFirstExists(false); player_health = player_health +1; if (increase_heart) { increase_heart.revive(); } This code is revive the first remove heart's icon, but I hope it can revive heart's icon reverse, How to do it??? thank you very much. I am sorry about my poor English , sorry
  10. Hello everyone, I am developing a platform game like super Mario , I hope the enemy can move left and right horizontal and loop this. I just use very stupid way to make it. I use this code is work. if (enemy.x<= 450){ enemy.body.velocity.x = +200; } else if (enemy.x>= 800){ enemy.body.velocity.x = -200; } if I have more than one enemy, I need to set each of their values. I try to use game.add.tween eg game.add.tween(enemy).to({ x: enemy.x+80 }........, It also work!!!!!!! but same problem , I need to set each of their values. I try to use time.events, but no success. What are the easy way to set enemy auto move left and right horizontal and loop this? Thanks you very much.