-
Posts
10 -
Joined
-
Last visited
Profile Information
-
Gender
Not Telling
Archer3CL's Achievements
-
Hi guys. I was wondering if i can change the sprite.damage() behavior. For example, I want to play the 'die' animation if sprite is dead but if i use damage() as the doc says And the code im using right now squash: function(sprite, pointer){ sprite.damage(this.inputPower); if(!sprite.alive){ sprite.body.velocity.y = 0; sprite.animations.play('die', 2, false, true); }}, So do i have to implement my own method? Thanks
-
Hi guys. Im following this tutorial and at some point i need to to this var device = new Phaser.Device();but running the game on console i got -> Uncaught TypeError: object is not a function on that line Any ideas? Thanks for your help
-
Im following this tutorial but im changing some of the sprites. So, when the game is running, sporadically this error appears %c %c %c Phaser v2.0.7 | Pixi.js v1.6.1 | WebGL | WebAudio %c %c http://phaser.io %c %c ♥%c♥%c♥ (03:01:25:504) at public_html/js/phaser.js:22011Uncaught TypeError: Cannot read property 'x' of undefined (03:02:20:821 | error, javascript) at Phaser.Sprite.setFrame (public_html/js/phaser.js:31278:33) at Phaser.Animation.play (public_html/js/phaser.js:44089:22) at Phaser.AnimationManager.play (public_html/js/phaser.js:43593:45) at Neon.item.spawnEnemy (public_html/js/Game.js:61:26) at Neon.Game.update (public_html/js/Game.js:43:23) at Phaser.StateManager.update (public_html/js/phaser.js:16546:35) at Phaser.Game.update (public_html/js/phaser.js:22122:24) at Phaser.RequestAnimationFrame.updateRAF (public_html/js/phaser.js:38277:19) at _onLoop (public_html/js/phaser.js:38263:30)> This is update update: function() { this._spawnRate += this.time.elapsed; if (this._spawnRate > 1000) { this._spawnRate = 0; Neon.item.spawnEnemy(this); } this._enemyGroup.forEach(function(enemy) { enemy.angle += enemy.rotateMe; }); if (!Neon._lives) { this.add.sprite((Neon.GAME_WIDTH - 594) / 2, (Neon.GAME_HEIGHT - 271) / 2, 'game-over'); this.game.paused = true; } }This is spawnEnemy spawnEnemy: function(game) { var dropPos = Math.floor(Math.random() * Neon.GAME_WIDTH); var dropOffset = [-27, -36, -38, -48]; var enemyType = Math.floor(Math.random() * 5); var enemy = game.add.sprite(dropPos, dropOffset[enemyType], 'enemy'); enemy.animations.add('anim', [enemyType], 10, true); enemy.animations.play('anim', 10, true); game.physics.enable(enemy, Phaser.Physics.ARCADE); enemy.checkWorldBounds = true; enemy.events.onOutOfBounds.add(this.removeEnemy, this); enemy.anchor.setTo(0.5, 0.5); enemy.rotateMe = (Math.random() * 4) - 2; game._enemyGroup.add(enemy); },And on my Preloader.js i declare my spritesheet like this this.load.spritesheet('enemy', 'img/enemy.png', 50, 50);My spritesheet is 200 x 50 and has 4 different sprites The only thing i tried is to comment the error line on spawnEnemy but if i do that in the game only shows the first sprite. Help is appreciated
-
The destroy function function destroy(enemy, bullet) { bullet.destroy(); enemy.destroy();}If bullet is detroyed there is no problem, but if enemy.destroy is called then the console throws "Cannot read property 'exists' of undefined"
-
I'm spawning multiple enemies using the group class in random places but when i try to check for overlap with my bullets the console throws "Cannot read property 'exists' of undefined" The code initializing enemies and bullets function create(){ enemies = game.add.group(); enemies.createMultiple(20, 'star', 0, false); enemies.enableBody = true; enemies.physicsBodyType = Phaser.Physics.ARCADE; bullets = game.add.group(); bullets.createMultiple(20, 'bullet', 0, false); bullets.enableBody = true; bullets.physicsBodyType = Phaser.Physics.ARCADE; bullets.setAll('outOfBoundsKill', true); bullets.setAll('checkWorldBounds', true);}The update function to check overlap function update(){ game.physics.arcade.overlap(enemies, bullets, destroy, null, this);}The random spawn function function randomSpawn() { if (game.time.now > nextEnemy) { nextEnemy = game.time.now + spawnRate; var enemy = enemies.getRandom(); var random = getRandomInt(0, 2); if (enemy) { enemy.exists = true; switch (random) { case 0: enemy.reset(leftSpawnPoint.x, leftSpawnPoint.y); break; case 1: enemy.reset(middleSpawnPoint.x, middleSpawnPoint.y); break; case 2: enemy.reset(rightSpawnPoint.x, rightSpawnPoint.y); break; } enemy.body.acceleration.y += 25; } }}Finally, the fire fuction function fire() { if ((game.time.now > nextFire) && selectedItem !== null) { nextFire = game.time.now + fireRate; var bullet = bullets.getFirstExists(false); if (bullet) { bullet.exists = true; bullet.key = selectedItem.key; bullet.tint = selectedItem.tint; bullet.reset(selectedItem.x, selectedItem.y); bullet.body.velocity.y -= 250; } }}As far as i know, the problem lies on the random spawning of the enemies, because they don't exist at the same time, so only the last enemy spawn has this property and those born before don't. Thanks for reading
-
lewster32 reacted to a post in a topic: Ignore decelerate on Collide and Focus on Browser
-
Archer3CL reacted to a post in a topic: Ignore decelerate on Collide and Focus on Browser
-
Hi! This time I'm trying to make 2 sprites (enemies vs bullets) collide (group vs sprite). I can detect and execute my function when the objects collide but when they do... the 'enemy' sprite pull back a little and I dont want this. What I want is that when the bullet collide with de enemy, the bullet disappear and the enemy keep moving forward. I'm using Arcade Physics and this is the code. Update function update() { game.physics.arcade.collide(enemies, bullet, destroy, null, this);}Destroy function destroy(bullet, enemy) { var result = checkIfWeak(enemy, bullet); switch (result) { case 0: enemy.destroy(); bullet.destroy(); break; case 1: bullet.destroy(); break; }}Enemy and Bullet physic properties //Enemygame.physics.arcade.enable(enemy);enemy.body.acceleration.y += 25;//Bulletgame.physics.arcade.enable(bullet);bullet.body.acceleration.y -= 50;And my next question is: Does Phaser have an option to keep my game running even after the user is no longer on the window / tab / browser? Thanks for the help
-
Thanks for the answer.About the first question, particularly on the game i'm making, i want to now if the user slide or swipe over a specific sprite. Never mind... i found the solution that i need in this topic http://www.html5gamedevs.com/topic/5449-directional-swipe/ And again thanks for the quick answer.
-
I'm kind of new with Phaser and I was wondering about this Is it possible to detect where on the world the active pointer was swipe OR in a specific area? I was getting the position of the pointer and check if it was inside of a Rectangle AND if the difference of the start y position of the pointer and the last y position is greater than 0 but... didnt work. From what I have read Phaser has at least 2 pointers enabled. Is it possible to have only one pointer enabled?Help appreciated.