erich

Members
  • Content Count

    76
  • Joined

  • Last visited

1 Follower

About erich

  • Rank
    Advanced Member

Contact Methods

  • Twitter
    webdesigneire

Recent Profile Visitors

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

  1. Hi, Hope someone can help if I try to do a key press my animation stops until I let go of the key. (keys a and d) to move left and right - is there a way for the key press .onDown to be used once or an aletrantive way to have my animation play when the key is held down, I've tried using the docs but can't seem to find a solution eg demo below http://html5gamer.mobi/2019/ code snippet when pressing d if (this.keyRight.isDown){ this.player.anims.play('walkProper'); this.player.flipX = false; this.player.setVelocityX(150); } Thanks in advance Eric
  2. Hi everyone, quick question, I googled that you can't add velecity to a group so I wrote this script and it works fine, but am I pulling to many resourses on the cpu if I create mulitble enemies at once on the screen, at present I have 2 enemies but will add more in laymans terms I have an external json file for the enemy x,y, key, velocity etc.., I then push each enemy into an empty array, and use a for loop in the update function to check collision against a wall and reverse the velocity here's the 2 parts I wrote in the create function : //create an empty array this.en = []; for (var i = 0; i <this.levelData.enemyData.length; i ++){ // add sprite to stage this.enemy = this.add.sprite(this.levelData.enemyData.x, this.levelData.enemyData.y, this.levelData.enemyData.key); //enable physics this.game.physics.arcade.enable(this.enemy); //give it a speeed for x this.enemy.body.velocity.x = this.levelData.enemyData.vel; this.enemy.scale.setTo(0.5); this.enemy.anchor.setTo(0.5); //push enemy into the array this.en.push(this.enemy); }; in the update function // enemy stuff for (var i=0; i < this.en.length; i++){ //hits wall this.game.physics.arcade.collide(this.en, this.collisionLayer, function(){ var hitRight = this.en.body.blocked.right; var hitLeft = this.en.body.blocked.left; if (hitRight){ this.en.body.velocity.x = - this.levelData.enemyData.vel; this.en.scale.setTo(-0.5,0.5); } if (hitLeft){ this.en.body.velocity.x = this.levelData.enemyData.vel; this.en.scale.setTo(0.5, 0.5); } }, null, this); // player hits enenmy this.game.physics.arcade.overlap(this.player, this.en, this.hitEnemy); } am I right or is there a better way to do it ? also on a seconadry note I originally used this in the update function this.game.physics.arcade.collide(this.en, this.collisionLayer, this.reverseEn, null, this); reverseEn : function(enemy, layer){ var hitRight = enemy.body.blocked.right; var hitLeft = enemy.body.blocked.left; var speed = enemy.body.velocity.x; if (hitRight){ enemy.body.velocity.x = -30; enemy.scale.setTo(-0.5,0.5); // console.log('hit right wall at ' + speed); } if (hitLeft){ enemy.body.velocity.x = 30; enemy.scale.setTo(0.5, 0.5); // console.log('hit left wall at ' + speed); } }, but speed is set at 0 and not at the this.en.bodyvelocity.x eg 30 - why is that ? hope it makes sense - thanks in advance Eric
  3. Hi you can use the this.game.input.activePointer.isDown to use the screen as a button - I used it in one of my original games http://html5gamer.mobi/phaser2/oscar/ I made so you can press a mouse button on the screen (mobile use) or you can press the up cursor on a computer to jump sample code if (this.cursors.up.isDown || this.game.input.activePointer.isDown){ this.playerJump(); } else if (this.cursors.up.isUp || this.game.input.activePointer.isUp){ this.isJumping = false; } Hope that helps Eric
  4. Hi If anyone is interested I created a basic enemy path chase system. It may be of use to someone else trying to make one themselves or to create a better version of it. The basics of the sytem are quite simple (mainly 2 functions) - I created a map array and a group of enemies - In the update function I use the chaseMe() function for the enemies to use their "line of sight" to start the chase if the player isclose to the x and y on the stage - If the player escapes, there is a short timer that will move the enemy (moveMonster() function) in a random direction where it may "see" you again and start the chase again It is pretty basic - the demo is below, use cursor keys to move the player http://html5gamer.mobi/projects/6/ You can view the source code in the browser (ctrl + u) or download the full demo in the zip file attached Eric 6.zip
  5. erich

    collide using array

    I found my error, I had this.player.body.immovable set to true
  6. (posted in phaser 3 instead of the phaser forum by mistake) Hi I'm hoping someone can hep me, I'm trying to create basic map using an array with 2 different images, one is a wall, the other is a floor. I've created twp groups but when i use this.game.physics.arcade.collide(this.player, this.blocks, null, this.hitBlock, this); I've used the collide function before on other games with no issues - this is my first time using a 2d array but I can't see where the issue is happening code below : cursor controls to move link example :http://html5gamer.mobi/projects/6/ var GameHipster = GameHipster || {}; GameHipster.GameState = { init : function() { //keyboard controls this.cursors = this.game.input.keyboard.createCursorKeys(); this.upKey = this.game.input.keyboard.addKey(Phaser.Keyboard.W); this.downKey = this.game.input.keyboard.addKey(Phaser.Keyboard.S); this.leftKey = this.game.input.keyboard.addKey(Phaser.Keyboard.A); this.rightKey = this.game.input.keyboard.addKey(Phaser.Keyboard.D); this.actionKey = this.game.input.keyboard.addKey(Phaser.Keyboard.P); this.PLAYER_SPEED = 400; this.BULLET_SPEED = 500; this.score = 0; }, // end init preload : function() { },//end preload //executed after everything is loaded create: function() { blockdata = [ [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], [1,0,0,0,0,0,0,0,0,0,0,0,0,0,1], [1,0,0,0,0,0,0,0,1,0,0,0,0,0,1], [1,0,0,0,0,0,0,0,0,0,0,0,0,0,1], [1,0,0,0,0,0,0,0,0,0,0,0,0,0,1], [1,0,0,0,0,0,0,0,0,0,0,0,0,0,1], [1,0,0,0,0,0,0,0,0,0,0,0,0,0,1], [1,0,0,0,0,0,0,0,0,0,0,0,0,0,1], [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], ]; this.blocks = this.add.group(); this.blocks.enableBody = true; this.floors = this.add.group(); this.floors.enableBody = true; var floor, block, i, j, col; var ROWS = blockdata.length; var COLS = blockdata[0].length; //console.log('R : ' + ROWS + ' C : ' + COLS); //console.log(blockdata[2][3]); for (i =0; i < COLS; i++) { for (j =0; j < ROWS; j++){ //col =1; col = (blockdata[j]); if (col ==0){ floor = this.floors.create( 1 + (i*64),1 +(j*64), 'block' + col); floor.anchor.setTo(0.5); } if (col ==1){ block = this.blocks.create( 1 + (i*64),1 +(j*64), 'block' + col); block.anchor.setTo(0.5); block.body.immovable =true; } } }; this.player = this.add.sprite(this.game.world.width / 2, this.game.world.height / 2, 'player'); this.player.anchor.setTo(0.5); this.player.scale.setTo(0.2); this.game.physics.arcade.enable(this.player); this.player.body.immovable = true; //ui this.uiBlocked = false; //text var style = {font : '20pt Arial', fill : '#fff'}; this.scoreLabel = this.add.text(10,10, 'SCORE : ', style); this.scoreText = this.add.text(130,10, '0', style); this.refreshStats(); }, //executed multiple times per second update: function() { this.player.body.velocity.x = 0; this.player.body.velocity.y = 0; this.game.physics.arcade.collide(this.player, this.blocks, null, this.hitBlock, this); this.keyboardControls(); }, // end update keyboardControls : function(){ //init keyboard controls if (this.cursors.left.isDown|| this.leftKey.isDown){ //this.player.angle += 5; this.player.body.velocity.x = -this.PLAYER_SPEED; } else if (this.cursors.right.isDown || this.rightKey.isDown){ //this.player.angle -= 5; this.player.body.velocity.x = this.PLAYER_SPEED; } if (this.cursors.up.isDown || this.upKey.isDown){ //thrust this.player.body.velocity.y = -this.PLAYER_SPEED; } if (this.cursors.down.isDown || this.downKey.isDown){ //thrust this.player.body.velocity.y = this.PLAYER_SPEED; } if (this.actionKey.isDown){ this.fireBullet(); } },// end function hitBlock : function(player, block){ console.log('hit'); }, endGame : function(player, enemy){ this.game.state.start('GameState'); }, refreshStats : function(){ this.scoreText.text = this.score; } }; Any help is appreciated Eric
  7. great read ! I foung intelXDK quite easy to port to the Google store for Android in my experience, I might try phonegap again (I had no joy the 1st time round) I haven't tried the leaderboard stuff yet - its on my to do list...... Eric
  8. very clever idea - well done
  9. was looking for the same - any good online examples ?
  10. have a look at: http://phaser.io/examples/v2/basics/01-load-an-image should be : create: function() { game.add.sprite( 0, 0, 'flag' ); },
  11. well done - thats really good ! Eric