Search the Community

Showing results for tags 'loop'.

More search options

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


  • HTML5 Game Coding
    • News
    • Game Showcase
    • Coding and Game Design
  • Frameworks
    • Phaser
    • Pixi.js
    • Babylon.js
    • Panda.js
    • melonJS
    • Haxe JS
    • Kiwi.js
  • General
    • General Talk
  • Business
    • Collaborations (un-paid)
    • Jobs (Hiring and Freelance)
    • Services Offered

Found 44 results

  1. Hey all! I add a music track that I want to loop using this code: music = new Phaser.Sound(game, "music", 1, true); It loops correctly everywhere except on IE. Has anyone has this issue? Is the work-around to have an event fire on sound complete?
  2. Audio loop duplicating - Bug?

    Hi there, I've stumbled across some very weird audio behavior and can't seem to avoid it. I'm trying to loop a marker of my audio file, which works well on itself. Whenever pausing and resuming the audio loop at least once however, as soon as the next loop point is reached it will not stop the currently running audio and play from the marker but just add a new layer of audio that plays from the marker instead, while the old one just continues to play. And it keeps doing that for every loop. //Create { this.sfx_music = this.sound.add("key); this.sfx_music.allowMultiple = false; this.sfx_music.addMarker('turbo', 116.8696, 7.3846, 1, true);'turbo'); } unpauseGame: function() { if( { = false; this.sfx_music.resume(); } }, pauseGame: function() { this.sfx_music.pause(); = true; } Pausing the game without pausing the music doesn't cause this problem, but It's mandatory for me to pause the music when pausing the game.. Could this be a bug in sound.pause() or sound.resume()? I'm using Chrome but I have the same behavior in firefox as well. Please help! Best Zampano
  3. Game loop and Animation question

    Hey everyone, So Im new to game development, although Im a full stack JS dev for general sites and apps. I started getting into canvas animation and now Im here trying to learn some game animation stuff. My question is this: Do you generally do just about all animation in the game loop with requestAnimationFrame()? Or can you simply have renderer.render(stage) called in the game loop while outside of it you use GSAP or some other tweening mechanic to change the positioning props on objects/sprites? Iv tried it and it works, I just would like to know if its dumb or nonperformant. I also tried using my regular js tweening library to call `renderer.render(stage);` in its update callback and it looks the same (im just doing a simple animation generating snow-like particles that float down). I know that the supported game loop in PIXI has stuff for velocity and whatever but I really like my animation library's ( easing and elasticity options. Will calling renderer.render(stage) in the game loop while tweening outside the loop still be 60FPS? Or do I need to be updating in the game loop? If I have to do it in the game loop, does anyone have any tips/references for easing and all of that? Because I dont want to have to write my own easing functions to update in the game loop (and I suspect most people arent), and rather use an animation API for that. Im also brand new to PIXI and maybe it has its own easing and whatever that works inside the game loop. Cheers
  4. Spawning enemies at random period

    Third time from me today :D, So I want to spawn these customers at random millisecs every loop... The problem is that when the first number is generated it uses it(this specific number) for every loop after that? Any ideas? this is how I'm trying to do it, but I guess there is a better solution... I can't create a variable, since the same thing is going to happen: * 10)*1000), this.createCustomer, this);
  5. Greetings, Quick question: How do I dynamically update the arguments of this loop from the update function to reflect the actual coordinates of the pointer? (This loop is found in the create() function) Game.mouseTimer = 100, Client.sendMousePos, Client.class, game.input.mousePointer.x, game.input.mousePointer.y ); I have already attempted several techniques, such as including this code snippet in the update function; However, it throws an Uncaught TypeError: Cannot set property '0' of undefined error. Game.mouseTimer.args[0] = game.input.mousePointer.x; Game.mouseTimer.args[1] = game.input.mousePointer.y; To go around the error, I tried to manually initialize the Game.mouseTimer.args array before the loop. This did indeed avoid the error; However, it only updated the arguments once. Thanks.
  6. Hello, I'm wondering if someone could help me solve this problem I have with 'Groups' in Phaser. So I have a group called 'enemy_wave' and it has 2 sprites attached to it: 'e_blue' and 'e_red'. Now, I want to 'kill' (sprite.kill();) 'e_blue' sprite and 'revive' (sprite.revive();) it later. Everytime I try to do that it also kills 'e_red', no matter how I put it. this.enemy_wave =; this.enemy_wave.enableBody = true; this.enemy_wave.physicsBodyType = Phaser.Physics.ARCADE; for (i = 0; i < system_var.length; i++) { for (j = 0; j < system_var[i].length; j++) { switch(system_var[i][j]){ case 'b': var e_blue = this.enemy_wave.create(40 + 40 * j, 40 + 40 * i, 'enemies'); this.enemy_wave.add(e_blue); break; case 'r': var e_red = this.enemy_wave.create(40 + 40 * j, 40 + 40 * i, 'enemies'); this.enemy_wave.add(e_red); break; } } } This is how I 'kill' sprites: this.enemy_wave.forEachAlive(function (e_blue) { e_blue.kill(); }, this); And this is how I 'revive' sprites: this.enemy_wave.forEachDead(function (e_blue) { e_blue.revive(); }, this); So yeah it doesn't matter if I kill 'e_blue' or 'e_red' because either way it 'kills'/'revives' all sprites attached to this group. How do I go about this? What seems wrong here? ~Thanks!
  7. Hey guys, I have a quick question about 'Groups' as I'm kinda new to this Phaser HTML5 game dev. So my plan is to create multiple groups and have control over each one of them. First thing that came into my mind is to create a 'for loop' and be done with! Problem is that I don't know how to assign different names for a variable (wave).Example: Instead of doing this: this.wave00 =; this.wave00.enableBody = true; this.wave00.physicsBodyType = Phaser.Physics.ARCADE; this.wave01 =; this.wave01.enableBody = true; this.wave01.physicsBodyType = Phaser.Physics.ARCADE; this.wave02 =; this.wave02.enableBody = true; this.wave02.physicsBodyType = Phaser.Physics.ARCADE; I am trying to do this: for(i=0; i<10; i++){ this.['wave'+i] =; this.['wave'+i].enableBody = true; this.['wave'+i].physicsBodyType = Phaser.Physics.ARCADE; } So I'm sure you got the idea but this (['wave'+i]) is the problem. Can someone help me with this? What is the correct way of writing it? I've been searching but maybe I'm not questioning this correctly. Thanks and sorry for the noob question!
  8. help with a loop

    Hi Im trying to make a level select buttons so a person can choose which level to play How can I make this.levelButton1,this.levelButton2 etc on the fly ? for (i = 1 ; i < 6; i ++){ this.levelButton = this.add.button(this.levelButtonWidth * (i * 1.8), 100, 'levelButton' + i); this.levelButton.inputEnabled = true;{ console.log('You Pressed LevelButton' + i); // pass this value to GameState }, this); } I have tried this.levelButton = this.add.button(this.levelButtonWidth * (i * 1.8), 100, 'levelButton' + i); but I keep getting a null reference any help would be appreciated Eric
  9. Hi I have a script that I wish to implement so that if the player hits an enemy 3 times the game restarts, but it constally loops when touching, where am I going wrong ?? create function this.currentHits = 3; this.collisionHasOccurred = false; update function :, this.enemies, this.youLose, null, this); youlose function : youLose : function(player, enemies){ if (!this.collisionHasOccurred) { this.currentHits --; this.collisionHasOccurred = true; } else { this.collisionHasOccurred = false; } console.log(this.currentHits); console.log(this.collisionHasOccurred); if (this.currentHits === 0) { //'Game'); console.log('GAME OVER'); } }, thanks in advance eric
  10. Hey, I was wondering if anyone knows how to play a MovieClip only once? For a code example, my code is pretty similar to the example below: Animation Thanks!
  11. Hi everyone. I have the looped timer : timer =; timer.loop(Phaser.Timer.SECOND * 3, this.endTimer, this); timer.start(); Everything works good, but i want to play sound every ticked second, how to implement this?
  12. Hi, friends I'm a game music composer who has been composing music and sfx for game projects for several year. If you need cool music and sfx for your game, take a visit at my collection here All of My Music and SFX is Royalty Free. You need to buy them at first and then you can use them in all of your commercial projects without any additional fee. If you're interested in hiring me, please check this link Best, JAK
  13. Does Phaser have any loop size limits?

    Hi Sorry if this is in the docs somewhere, but I couldn't find it. Could someone please tell me if Phaser (or possibly Brackets) is deliberately limiting the size of my loops, as I can't seem to get them to work over about 32000 iterations. I did notice that JSbin has something called "loop protection" but offers a code to turn it off. Is there a way to do this in Phaser?
  14. EDIT: It seems to happen only in version 2.4.8. In 2.4.7 works perfectly. I will submit an issue to github. Hi, guys. I'm having a trouble with a background music that plays on my game playState. It works well if the player dies before the audio loops (the audio duration is 21 seconds), but if the player survives more than 21 seconds and the audio loops, I can't stop the music. Instead, when the create function of my playState comes on, it creates another audio and plays simultaneously. I have read many post related to audio here, but can't solve the problem. This is how I do it: Audio preload in load.js:'music', 'assets/background_music.mp3'); And in play.js in the create function: ='music', 0.2, true);; And finally, in the gameOver function:; game.state.start('gameOver'); I had tried many approaches described here in the forum, as: Change the variable to, check if the before create, stop it before call destroy, restart, but nothing helps. Thanks for your attention Phaser version 2.4.8
  15. I want to loop a work a number of times and between each loop will be an interval (like setInterval in Javascript). I have used tween to make loops but don't know how to make intervals between them. You could use the example here to try: Hope you could help me. Thank you very much!
  16. Hello everyone, in my application, I normally only need to render the 3D view after the user has changed some settings of the confugration or the view is being used (with either the mouse , finger or keyboard) the rest of the time no rendering is needed. But how can I know if Babylon is doing something that needs? For example: Can I look somewhere if the camera has stopped moving? (Especially when it's deaccelerating) Or an animation is running? Thanks for your answer! Kevin
  17. Problem with loops

    Hi everybody! I have a problem with a loop in my game. The problem is this: I have a loop that after certain seconds it executes and generates some sprites in the game (it takes it from a group), it works fine the first time. But after the specified seconds pass and the loop executes again it throws me this error: "Uncaught TypeError: Cannot read property 'apply' of undefined" Here's the Code (there are 3 loops in total, but for the example i just focused in the first). /Creation of the fire traps this.fireballs =; this.fireballs.createMultiple(100, 'fireball'); this.fireballs.callAll('animations.add', 'animations', 'shoot', [0,1,2,3], 16, true); game.physics.arcade.enable(this.fireballs); this.fireballs.enableBody = true; //Multiple Fire traps this.loop1 =, this.activateMultipleFireTraps('1'), this); //this.loop2 =, this.activateMultipleFireTraps(2), this); //this.loop3 =, this.activateMultipleFireTraps(3), this); activateMultipleFireTraps: function(position){ if(position == '1'){ var firePositions = [[528, 7488], [528, 7360], [528, 7232], [528, 7088]]; var index = 0; for(index = 0; index < firePositions.length; index++){ var fire = this.fireballs.getFirstDead(); fire.anchor.setTo(0.5); fire.scale.setTo(0.5); fire.scale.x = -1; fire.reset(firePositions[index][0], firePositions[index][1]); fire.body.velocity.x = -150;'shoot'); } } else if(position == 2){ var firePositions = [[0, 7552], [0, 7424], [0, 7296], [0, 7168]]; var index = 0; for(index = 0; index < firePositions.length; index++){ var fire = this.fireballs.getFirstDead(); fire.anchor.setTo(0.5); fire.scale.setTo(0.5); fire.scale.x = 1; fire.reset(firePositions[index][0], firePositions[index][1]); fire.body.velocity.x = 150;'shoot'); } } else{ var firePositions = [[112, 7040], [256, 7040], [400, 7040]]; var index = 0; for(index = 0; index < firePositions.length; index++){ var fire = this.fireballs.getFirstDead(); fire.anchor.setTo(0.5); fire.scale.setTo(0.5); fire.scale.y = -1; fire.reset(firePositions[index][0], firePositions[index][1]); fire.body.velocity.y = 150;'shoot'); } } }, I dont know why it doesnt work. Thanks!
  18. Hello, I'm trying to animate clones of an object but with a delay between animation. You can find a test here : But as you can see, the delay between animation is not constant, after the first loop, all animation are not sync, how can i keep the same delay after all the loop ? Maybe it's not the right way of doing this, can someone help me with this ? In this configuration I can keep the delay between animation but some of them never end : Thanks !
  19. Seamless Audio Loops in Phaser

    I'm working on a game with seamless background music and figured I'd share my findings to help others. I'm just using Phaser's standard'', 0, 1, true) code to play loops. (Have since discovered I can also use sound.loopFull()). I didn't want to mess with outside solutions like seamlessLoop.js, which I'm not sure would work across all browsers anyway. Here's the run down on the file formats: OGG - Good for seamless loops in Firefox and Chrome. M4A - Good for seamless loops in iOS. When I first posted this I thought that I was stuck using the Apple Lossless codec (lossless = huge file sizes) because when I used any other M4A generating codec the resulting audio had blank space added at both ends. I wound up using the fre:ac open source audio converter which adds information for gapless playback according to its developer, who was extremely responsive and helpful (Thanks Robert!). Sure enough, the audio played seamlessly on my iPad with much smaller files. MP3 - Not good for seamless loops, but needed for IE. Even if your MP3 has no silence on either end, when the sound is done playing there will be a small audio gap before it loops. There are some techniques like the ones here that seem promising, so if I can overcome this issue I will post the code. Good for all other use cases because all browsers support it and it has the smallest file size of the three formats when exported with reasonable quality settings. So here's what I'm using to load my seamless loop audio. M4A is in a separate conditional because when I put it as the first option Firefox would load it instead of falling back to OGG and not play the sound. I'm loading all my other sounds as MP3s (in a different code block - not shown) to keep my total file size as low as possible. // load seamless intro audio loadLoop('musicIntro', 'intro_music_loop'); function loadLoop(key, file) { if (game.device.iOS || game.device.macOS) {, ['sounds/' + file + '.m4a']); } else { // Firefox and Chrome will use OGG // IE11 will fall back to MP3, which will have a small gap at the end before replaying, ['sounds/' + file + '.ogg', 'sounds/' + file + '.mp3']); } } Hope someone finds this helpful
  20. Read Json data with for loop

    Hello everyone, I have a texture atlas which is created by TextuePacker and there are different sizes images in it. Also i exported it with json hash file from it and load my phaser project as game.load.atlas(.., .., ...); The question is, how can i read all frame names and its properties from json file in a for loop? I've tried this, var frameData = game.cache.getFrameData('texture');for (var i = 0; i <; i++) { var name = frameData.getFrameByName(i).name; //or// var name = frameData.getFrame(i).name; // or many things console.log(name); }but nothing. Thank you all.
  21. Seamless loop?

    I'm totally new at this forum, so this might an old topic. If so, I'm sorry. Anyway, I'm working with a html & javascript game in which i want a 20 second .mp3 to start and then loop. I'm fine with the user interaction to play, and I also got it to loop. But is there a way to make the loop as seamless as possible? As it is now, there's a notable pause between the end and the start of the mp3. Thanks in advance!
  22. no audio sprite

    Hi all, Do you think there is a way to do the same thing like here but with many audio files (no audio sprite) ? : I tried to do it by myself but no succeed... Thank for any help !
  23. i tried different songs in different file formats (mp3,wav, ogg) music ='theme',1,true); // key, volume, loop'',0,1,true); //marker, position, volume, loop, forceRestartmp3 is not played at all and with wav or ogg the bug is the same.. i also tried playing the music with'theme',0.4);and it jumps too... (it sounds like a damaged cd but only on the first note - the first 200ms are played twice) all the other sounds (the short ones) don't have this problem.. i have no idea what to do - it seems that the file length is somehow a source of the problem (my audio file is a 30sec loop so it's not that long) thx in advance!
  24. Loop audio from specific point

    I want to loop an audio from a specific point. I'm using markers. I can specify starting point but the audio is not looping. Also, how do I specify in the marker that I want it to play till the end of the file? intro.duration, intro.length aren't the answers. var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create, update: update, render: render});var intro, marker;function preload() {'intro', 'intro.ogg');}function create() { intro ='intro'); marker = intro.addMarker('marker', 2.3, 8.26, true); // true, but not looping and 8.26 must be something like intro.duration or intro.<rest of the file> space = game.input.keyboard.addKey(Phaser.Keyboard.SPACEBAR);}function update() { if (space.isDown) {'marker', true); // // true, but not looping }}OK. I found some sort of a solution: var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create, update: update});var intro, marker;function preload() {'intro_in', 'intro_in.ogg');'intro_rest', 'intro_rest.ogg');}function create() { intro_in ='intro_in'); intro_rest ='intro_rest', 1, true); space = game.input.keyboard.addKey(Phaser.Keyboard.SPACEBAR);}function update() { if (space.isDown) {;, function() {;}, this); }} The idea: The audio is divided in 2 parts. First part 1 plays. And after some delay the second plays with a loop. ! And something important to point out: var song ='name', true); DOES NOT loop the song. BUT var song ='name', 1, true); DOES Is this a bug? I took a peek in the source code here but everything seems fine. ==== I'll mark this as answered tomorrow but I'll wait to see if anyone can propose a more elegant solution. Something with less code maybe.