Search the Community

Showing results for tags 'Groups'.



More search options

  • 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
  • Frameworks
    • Phaser 3
    • Phaser 2
    • Pixi.js
    • Babylon.js
    • Panda 2
    • melonJS
  • General
    • General Talk
  • Business
    • Collaborations (un-paid)
    • Jobs (Hiring and Freelance)
    • Services Offered

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 93 results

  1. Hi, I have two groups, one is players that move from right to left. The other is opponents that move from left to right. The two groups collide which is exactly what I want. I also want the players in the players_group to collide with each other and the opponents in the opponents_group to collide with each other. The idea is that you can drop players in lanes and they push the opponents backwards if there are more players in the lane than opponents. Currently some of the players overlap each other rather than stacking up against each other when they collide. I currently have the following code in my update function this.game.physics.arcade.collide(this.player_group, this.opponent_group); Thx.
  2. Hello everyone, I wondered what the best course of action might be if you're using RequireJS with Phaser and wanting to access groups from other scripts. For instance, on the 'create' method (currently housed in its own script file) I have a bunch of groups that exist, but they only exist within that context, and it would be great to be able to access them say from another area that handles the game's update loop, etc. Current all I'm doing is this, it does work, but I can't help but wonder that it's not a nice way of doing it: this.game.groups = {};// And the groupsthis.game.groups.explosions = explosions;this.game.groups.damageHits = damageHits;Have any of you guys run in to this before? Many thanks, - D
  3. Hello! I'm still beginner in game programming, and I have headache right now because of physics with sprite groups. I know how to make sprite with P2 physics, and how to make them kinematic. But what I'm trying right now is to make group with same settings, and after couple of hours today, couple of tutorials I have no idea how to make it proper way. grounds = this.add.group(); // Create a group grounds.enableBody = true;grounds.physicsBodyType = Phaser.Physics.ARCADE; grounds.kinematic = true;This code don't collide with player (arcade/p2js) grounds = this.add.group(); // Create a group grounds.enableBody = true;grounds.physicsBodyType = Phaser.Physics.P2JS;grounds.kinematic = true;This could collide, but "grounds" aren't kinematic. Can someone help me? I have no idea.
  4. Hey guys, I did a search of the forums as well as the Phaser/Pixi docs and came up short (let me know if it's answered anywhere else). I'm trying to create a mechanic whereby the player is able to pick up and drop sprites. I've been able to achieve pickups by using the group.add() function where the group parent is the player sprite, but when using .remove() to drop the sprite, the sprite just completely disappears. Its position, alpha, scale etc all look sensible and haven't been modified. What I have seen however is that the sprite parent name changes to being undefined, which seems unhealthy as when it spawns in the world its parent appears to be "__world". I also tried directly calling addChild() inherited from Pixi which is used in the Phaser groups, and the result was the same. It's easy to reproduce, my code is below. This is in .create() this.testGroup = game.add.group(PLAYER) this.testLight = game.add.sprite(300, 300, "buttonGradient");This is in .update() if (PLAYER_OBJECT.inputIsActive("y")) { this.testGroup.add(this.testLight); } if (PLAYER_OBJECT.inputIsActive("u")) { this.testGroup.remove(this.testLight); }Does anyone know if my setup is bad, or if there are other ways to achieve my desired effect? I had a look at the group remove example on the official examples page and the same thing happens there - I don't know if it's a bug or an intentional result of the system. Thanks in advance!
  5. Hi All, I've just started using Phaser over the last couple of days and am liking it very much. I've never attempted any serious programming with Javascript, but seem to be catching on quickly thanks to all the available Phaser documentation. My question concerns the performance hit of using "emitters" in place of "groups". I understand that the emitter functions are basically an extension to the groups functions. What I'm doing is creating an endless scroller/runner game format. As the screen scrolls, pre-composed "scene" sections are chosen randomly, then generated off screen and scroll by from right to left. These scenes are composed of platforms, coins, enemies, and various objects. I've been using an emitter for each type of scene object (i.e coin emitter, enemy emitter, platform emitter, etc). Each emitter will generate a scene that will then scroll by, after a certain time has elapsed, another scene will be chosen at random, then generated and allowed to scroll by. I've been using emitters instead of simple groups because it requires less coding on my part to generate each scene. This has been working just fine with no lag or noticable hit in performance so far. My concern is that as the game gets more complicated with more scene objects, will I eventually start to see a hit in performance? The reason I feel this way is that it seems that emitter particles get several physics properties automatically applied to them, some of which i'm not using. Will using emitters instead of groups for this eventually create a performance disadvantage? What would you use to continually generate scrolling scene content?
  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?
  7. Hi all, I'm looking for a way to group buttons so I can animate between them. For example I have 15 levels in my game split between 3 worlds so 5 levels per world. I want to show buttons to these levels with 5 on the screen at one time, when the user clicks an arrow, the first 5 buttons slide left off screen and the next 5 slide in from the right. I initially thought of adding buttons to a group much like you do with sprites, then animating the groups on/off screen but it doesn't seem as though I can do this. What would be the correct way of doing this? Thanks, Martin
  8. Hi, I'm new (another one) with phaser. I did a test game without problems (or almost) but now I'm doing a game that throws objects ad infinitum. In order to do this I'm sprite recycling. I have a group of sprites with outOfBoundsKill and checkWorldBounds set to true. And then when it's time to throw an object I fetch the first that does not exists. Here's my code: // Coinsthis.coins = this.add.group();this.coins.enableBody = true;this.coins.physicsBodyType = Phaser.Physics.ARCADE;this.coins.createMultiple(4, 'coin');this.coins.setAll('outOfBoundKill', true);this.coins.setAll('checkWorldBounds', true);And this is the function to throw coins (from the bottom of the world to the top): throwSomething() { this.coin = this.coins.getFirstExists(false); this.coin.reset(this.throwers_x[droperNumber], this.throwers_y); this.coin.animations.add('spin', [0, 1, 2, 3, 4, 5, 6, 7], 10, true); this.coin.play('spin'); this.coin.body.gravity.y = -300; this.dropingTimer = this.game.time.now + 2000;}The moment all coins are created there's no coins with exists set to false. It should be, since outOfBoundKill is on. The animation add and play, and the body.gravity were in the create function at the beginning, but I changed to test things. Any ideas?
  9. Hi there. It seems fixedToCamera works fine for me when I don't scale down the image at all (it is a background sky image), but the second I scale either the group containing the sky or even the whole game.world the background stops following the camera. What I would like is when I zoom out for the sky to expand, but then remain fixed to the camera afterwords when the camera moves etc... Thanks for any help/suggestions. -DRG
  10. Hi! I'm trying to figure out how to detach a sprite from a Group. Currently you add it with the group as a two-step process: 1) Create the Sprite 2) Add it to the group: group.add(sprite) But if I want to detach it from the group, so I can handle it individually, I have no other option than "destroy", which removes the Sprite. Setting the parent to null doesn't work either. The objective is that when a specific condition is met, the tween that is applied to all elements in the group as a whole doesn't apply to this particular sprite. Thank you!
  11. Cross posted from here. I've got a prefab class that inherits from Group. var PipeGroup = function(game, x, y, collisionGroup, collidesWith) {Phaser.Group.call(this, game);var topPipe = this.create(0,0,'pipes');topPipe.physicsEnabled = true;topPipe.body.kinematic = true;topPipe.body.setRectangle();topPipe.body.setCollisionGroup(collisionGroup);topPipe.body.collides(collidesWith);this.x = x;this.y = y,}; PipeGroup.prototype = Object.create(Phaser.Group.prototype);PipeGroup.prototype.constructor = PipeGroup;And in my main game's create function: create = function() { .. this.playerCG = game.physics.createCollisionGroup(); this.pipeCG = game.physics.createCollisionGroup(); // add our player to the stage this.player = this.add.sprite(game.world.width/3,220,'bird'); // enable physics on our player this.player.physicsEnabled = true; // add our player to the player collision group this.player.body.setCollisionGroup(this.playerCG); this.player.body.collides([this.pipeCG], this.death, this); .. game.time.events.loop(Phaser.Timer.SECOND,this.generatePipes, this);}and generatePipes looks like: generatePipes: function() { var pipeY = game.rnd.integerInRange(-120,120); var pipes = new PipeGroup(game,game.world.width + 32, pipeY, this.pipeCG, this.playerCG); this.player.body.collides([this.pipeCG], this.death, this);}However, the player is never colliding with the pipes. Can you modify a collision group after the create phase of a state? I'm a bit at a loss to figure out why this doesn't work.
  12. Hey all I've used the Prototype pattern explained here and in various forum posts: http://examples.phaser.io/_site/view_full.html?d=sprites&f=extending+sprite+demo+1.js&t=extending%20sprite%20demo%201 This works if I maintain a reference to an object. For example: var player = new FooBar.Player(this.game, x, y); I can then call the functions that I've written in the FooBar.Player class that is an extension of the Phaser.Sprite class. However, I can't access those functions if I use group callback functions: playerGroup.foreach(function(player){ player.somethingCustom(); }; => TypeError: Object [object Object] has no method 'somethingCustom' Is there a way to extend a sprite, add it to a group and maintain its classiness?
  13. Hello phaser community, I observed some kind of misbehaviour with group nesting. It seems that the reference for the nested group is lost and PIXI.DisplayObjectContainer is exposed instead. Look at the following Testcode. There is a sprite in a group which is added itself to another group. When I try to retrieve the nested group with #getAt it returns a PIXI.DisplayObjectContainer and not the Phaser.Group object. I think this is not an expected behaviour ? I digged that deep because my initial problem was (and still is) that #countDead is not working with nested group items because of this behaviour (It's not iterating over the nested group elements but over the corresponding PIXI Containers., with the lack of the alive attribute). I couldn't find a back reference from DisplayObjectContainer to the Phaser.Group object. With this I could have build a workaround but I couldn't find anything to map PIXI objects to Phaser objects. //create a base group to start withbaseGroup = @game.add.group()//add another nested group (to create the misbehaviour)nestedGroup = @game.add.group()baseGroup.add(nestedGroup)//now create a sprite to have a non-group type to addsprite = @game.add.sprite(0, 0, 'cap');//add it to the nested groupnestedGroup.add(sprite)//Now let's do some testing://output: sprite should be found in child group: expected: (true) is trueconsole.log 'sprite should be found in child group: expected: (true) is', nestedGroup.getAt(0) == sprite//output: base group should container the nested group: expected: (true) is false console.log 'base group should container the nested group: expected: (true) is', baseGroup.getAt(0) == nestedGroup //output: group#getAt should not expose PIXI Container: expected: (Phaser.Group) is (PIXI.DisplayObjectContainer)console.log 'group#getAt should not expose PIXI Container: expected: (Phaser.Group) is', baseGroup.getAt(0) //Test with countDead which uses group#iterate//First of all: set sprite dead. This is only a flag and should be reflected in method group#countDead.sprite.alive = false//default ist already true, for the sake of consistency.nestedGroup.alive = true//Sprite is DEAD, nestedGroup is ALIVE. Test it://output: our sprite is dead, so this should be 1 is 1 console.log 'our sprite is dead, so this should be 1 is', nestedGroup.countDead()//output: our nested group is alive should be 0 is 1 console.log 'our nested group is alive should be 0 is', baseGroup.countDead()I know that there was an update in a commit between 1.1.3 and 1.1.4 (see this commit). It seems to be related, because of the following selected code line. When nesting a group it's unerlaying PIXI object is added. But the reference to the Phaser.Group is lost at this point isn't it ? So all following calls to group#getAt(index) is return a PIX object and not the Phaser.Group object. add: function (child) { if (child.group !== this) { if (child.type && child.type === Phaser.GROUP) { child.group = this; // Do we lose the reference to the Phaser.Group itself here ? this._container.addChild(child._container); (Source: github) My workaround for now is to maintain a own list/array of group items. It would be great to depend on Phaser's own display list. Thanks for reading. Regards George
  14. Guys I have the following code to make a star sprite and 2 firstaidbox(added through group) sprites.what i want is that when i click the star the firstaid boxes should dim(alpha=0.5) and vice versa.however the mouse event doesnt seem to work when I click the firstaid boxes. function create () { starimage = game.add.sprite(100,100,"star"); starimage.inputEnabled=true; starimage.events.onInputDown.add(listener,this) bots=game.add.group();//the firstaid boxes for(var i=2;i<4;i++) { var myvar=bots.create(i*100,100,'firstaid'); myvar.inputEnabled=true; myvar.events.onInputDown.add(listener,this); } } function listener(sprite, pointer) { if(sprite==starimage) { sprite.alpha = 0.5; bots.alpha=1; } if(sprite==bots) { alert("clicked"); sprite.alpha = 0.5; starimage.alpha=1; } }
  15. I'm making a game where you make words by clicking letters. Eventually these letters will be images, but for now I'm trying to make something like a button: a clickable square with some text over it. I was familiar with how to do this in AS3, but now I don't have addchild at my disposal to build a combination of sprites. I thought that maybe I had to use groups to combine the button and the text, but this would mean that for every lettersquare I make a new group, which seems wrong. In examples I only see groups being used to handle multiple sprites, but the real use of them is unclear to me. So i guess I have two questions: - How do I make a button with dynamic text? - When and how do I use groups?
  16. Hi there! I'm having an issue with trying to figure out best practices with creating multiple sprites on a screen. I've been using this blog post as a reference for how to structure my game into classes: http://toastedware.com/?p=258 and so far it's been great. I like how neat it leaves my code. However, I've been trying to create multiple instances of a class and whenever a new instance appears, the previous one loses all of its properties and just drops into the ether. Any advice on how to move forward? I've tried creating a group, but I'm not sure how to pass the class into it. For reference, here is my game so far: https://github.com/JLevstein/tigertail/tree/master/js
  17. Hi, Is it possible to add text to a group? Or is it limited to only sprites? I tried code like this to no avail: foo = game.add.group();foo.create(0,0,'bar'); // adding a spritefoo.add.text(0, 10, 'some text', { 'font': '22px Helvetica', fill: '#fff' }); // doesn't workIf text can't be added to a group is there some workaround for creating text that can be manipulated along with sprites as part of the same unit? Thank you
  18. Hi, I'm just starting out with Phaser, really like it so far and have managed to figure most things out from the examples and this forum. I was wondering if there was any way to add a tween to a group? I am guessing you might use the forAll function, but I'm not sure how this works. This is what I would like to do: game.add.tween(titleScreen).to({alpha: 0},2000,Phaser.Easing.Linear.None,true);Where titleScreen is a group of sprites that comprise my title screen. Thanks, Anton