Jump to content

Search the Community

Showing results for tags 'foreach'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • HTML5 Game Coding
    • News
    • Game Showcase
    • Facebook Instant Games
    • Web Gaming Standards
    • Coding and Game Design
    • Paid Promotion (Buy Banner)
  • Frameworks
    • Pixi.js
    • Phaser 3
    • Phaser 2
    • Babylon.js
    • Panda 2
    • melonJS
    • Haxe JS
    • Kiwi.js
  • General
    • General Talk
    • GameMonetize
  • Business
    • Collaborations (un-paid)
    • Jobs (Hiring and Freelance)
    • Services Offered
    • Marketplace (Sell Apps, Websites, Games)

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


Website URL


Twitter


Skype


Location


Interests

Found 6 results

  1. I have an array of items (stored as strings) I am displaying on screen as sprites, in an inventory. I want to update my array when an item is removed from my inventory, so I want to write a function that resets the x position of the objects. I can log out the right object and the right index value, but I can't seem to set the position of the object using this function. Any ideas ? example: inventory('key', 'rock', 'sword', 'note'); resetSlots: function() { //for every item in inventory, slot position is index number. inventory.forEach(function(item, index){ item.x = index * 150; console.log(item.x); //this returns "undefined" }) },
  2. Hi , I m new user of phaser and i develop a retro shoot them up for the GameOFF jam . i have a problem in my game state : enemyTween: function(){ this.enemyPool.forEachAlive(function(enemy){ enemyTween = this.game.add.tween(enemy) }) TypeError: this.game is undefined [En savoir plus] why i cant acces to game and other event into function of group? (sorry for my bad english)
  3. So in my game the player object is made up of several different sprites, so I made a Group called "player," and tried to add an object to it, "rover_proto." I am also trying to use forEach() to change attributes of each item belonging to the group. Here is my code: function createGameScene() { // format: (game, name, addToStage, enableBody, physicsBodyType) player = game.add.group(game.world, 'player', true, true, Phaser.Physics.P2); Rover_proto = player.create(0, 0, 'Rover_proto'); //player.setAll('body', true, true, false); //Group collision player.forEachExists(function (item){ item.body.setCollisionGroup(playerCollision); item.body.collides(wallCollisionGroup); item.body.createGroupCallback(wallCollisionGroup, hurt_rover, player); });}So when I comment out the setAll() is says that "item.body is null." I thought that using game.add.group allows you to enableBody for each item in the group, at least I think it worked that way in Arcade (I am using P2 now which is what is causing me this trouble). So that's when I added in player.setAll(), to hopefully give everything a body. However, if I uncomment it, then the program gives two errors: "TypeError: item.body.setCollisionGroup is not a function" and "TypeError: This.body.preUpdate is not a function." I don't understand why these problems are being caused. I remember using arcade the only way to fix the problem of objects in a group not having bodies was to use the game.add.group() method which I did use in this code. I've also used forEach before, but here it's not working. Is there something I'm missing? Am I using these functions wrong? Can forEach only be called during Update() and not Create() or something? How can I create a body and physics and set collisions, etc. for each object in a group if game.add.group() isn't working (and why isn't it working)? Thank you for your time, --jagd
  4. Hi, I have this code: console.log("top dead: " + this.topGrp.countDead()); // 3 this.topGrp.forEachDead((child) => { console.log("destroy top"); // only 2 times in chrome's console child.destroy(); }, this); topGrp is a group the function countDead() returns 3, and then forEachDead is iterating only 2 time, I see this in the console and only 2 object in my game are destroyed... help?? thanks! Lior
  5. Hello there. Im new to phaser so im trying to learn it, but in the process i have came across a few troubles with groups and forEach method. Here is what i have: starGroup.forEach(function(eachStar) { if (gameBegun==true && planeSprite.body.hitTest(eachStar.x+8, eachStar.y+30) && eachStar.frame<=30) { eachStar.animations.play('taken', 24, false, true); } if(eachStar.frame>50)// this line here doesnt work for some reason { alert('easf'); }});So if you notice that if(eachStar.frame>50), it doesnt work, for some strange reason it doesnt work. It works if i do frame<50. So its really odd. < works > doesnt work. I also have a problem if i say eachStar.destroy(), i also seted it to true like so: eachStar.destroy(true) but it gives me the following error: "Type Error: eachStar is undefined." eachStar.kill() works but i want to completely remove eachStar under certain circumstances. So whats causing such problems? Thanks.
  6. Hi guys, I use the following (shortened) code: updateGroups() { console.log(this.tiles); this.tiles.forEach(function(tileGroup) { var tile = tileGroup.getAt(0); var value = tile.val; var valueText = tileGroup.getAt(1); if (value == 0) { this.emptyTiles.add(tileGroup); } else { this.occupiedTiles.add(tileGroup); } }, this); }As I made sure (with logging it to the console) the group "tiles" has children, each themselves being a group with two children. Firebug throws the error "tileGroup is undefined" for line "var tile = tileGroup.getAt(0);" Why? What's going wrong here?
×
×
  • Create New...