Search the Community
Showing results for tags 'loops'.
-
Hi. I'm having trouble with an animation. The animation is 3 frames, and is a static image until the user ciicks in, and animates it, which should happen in a loop. Instead, the frames play once then the entire thing disappears from the screen. How do I get it to loop? Also, ideally I'd have it loop a number of times then stop. I see there's an example for loop counts in the Phaser documentation, but that doesn't seem to work either... preload: function () { this.load.spritesheet('spritesheet', 'pngs/sprites.png', 99, 79, 3); }, create: function () { this.sprites = this.game.add.sprite(760, 60, 'sprites'); this.sprites.inputEnabled = true; this.sprites.events.onInputDown.add(this.spritesanim, this); } spritesanim: function(){ this.animat = this.sprites.animations.add('swing'); this.animat.play('swing', 20, true); },
-
Hello. When I use forEachAlive loop on a group I see that it goes in ascending index order, I need to loop through group children in reverse order without changing their indexes or display order. I searched on google, in documentation ad in examples but I can't find a solution. I will be very grateful for any help.
-
I been having an issue while looping through 2 groups and got this error, what I think this means is one of the objects is undefined. Uncaught TypeError: Cannot read property 'width' of undefined This is code (which is in Typescript) that causes the error: for (var i = this.tris.children.length - 1; i >= 0; i--) { for (var s = this.squares.children.length - 1; s >= 0; s--) { if(Overlap(this.tris.children[i],this.squares.children[s])){ this.BreakTris(this.tris.children[i]); this.BreakSquare(this.squares.children[s]); } } } The error is given specifically for the Overlap function. Two loops which go through 2 groups in order to compare each sprite of both groups to each other and check for Overlap, which is as follows: function Overlap(spriteA, spriteB) { var boundsA = (spriteA instanceof Phaser.Sprite) ? spriteA.getBounds() : spriteA; var boundsB = (spriteB instanceof Phaser.Sprite) ? spriteB.getBounds() : spriteB; return Phaser.Rectangle.intersects(boundsA, boundsB); } I don't see what i'm doing wrong? Thanks for reading.
-
Hello, I have started developing with canvas and JS this week and have a few questions on the structure of a program..... When is it appropriate to create a new file that declares an object? so far I have been declaring my objects using the object literal method in a single file but its coming close to 300 lines and I am now wondering if I should start making new files for my objects. for example, I want to make a gun class which acts as a parent class for all gun types. I have made a new JS file and have added this: function Gun(){ this.x=0; this.y=0; this.image1=9; this.image2=10; this.width=36; this.height=32; this.pickedUp=false;}now, would it be more efficient to declare this using object literal in the other file? Or should I continue writing this one and make a loop function in this file that handles all the actions that I would normally put in the other (300 line) file?
- 5 replies
-
- loops
- javascript
-
(and 1 more)
Tagged with:
