Search the Community

Showing results for tags 'loop'.



More search options

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • 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 40 results

  1. 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 = game.add.group(); 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!
  2. 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 = game.add.group(); this.wave00.enableBody = true; this.wave00.physicsBodyType = Phaser.Physics.ARCADE; this.wave01 = game.add.group(); this.wave01.enableBody = true; this.wave01.physicsBodyType = Phaser.Physics.ARCADE; this.wave02 = game.add.group(); 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] = game.add.group(); 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!
  3. 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?
  4. 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; this.levelButton.events.onInputDown.add(function(){ 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
  5. 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.game.physics.arcade.overlap(this.player, 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) { //this.game.state.start('Game'); console.log('GAME OVER'); } }, thanks in advance eric
  6. 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: http://pixijs.github.io/examples/index.html?s=basics&f=spritesheet.js&title=SpriteSheet Animation Thanks!
  7. Hi everyone. I have the looped timer : timer = this.game.time.create(false); 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?
  8. 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 http://bit.ly/JKMusicSFX 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 http://bit.ly/CustomMusicProject Best, JAK
  9. 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?
  10. 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: game.load.audio('music', 'assets/background_music.mp3'); And in play.js in the create function: game.music = this.add.audio('music', 0.2, true); game.music.play(); And finally, in the gameOver function: game.music.destroy(); game.state.start('gameOver'); I had tried many approaches described here in the forum, as: Change the this.music variable to game.music, check if the game.music.isPlaying before create, stop it before call destroy, restart, but nothing helps. Thanks for your attention Phaser version 2.4.8
  11. 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: http://phaser.io/examples/v2/tweens/tween-loop-event#g Hope you could help me. Thank you very much!
  12. 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
  13. 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: game.time.events.loop(Math.floor((Math.random() * 10)*1000), this.createCustomer, this);
  14. 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 = game.add.group(); 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 = game.time.events.loop(2000, this.activateMultipleFireTraps('1'), this); //this.loop2 = game.time.events.loop(4000, this.activateMultipleFireTraps(2), this); //this.loop3 = game.time.events.loop(6000, 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; fire.animations.play('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; fire.animations.play('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; fire.animations.play('shoot'); } } }, I dont know why it doesnt work. Thanks!
  15. Hello, I'm trying to animate clones of an object but with a delay between animation. You can find a test here : http://www.babylonjs-playground.com/#ACLYP#1 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 : http://www.babylonjs-playground.com/#ACLYP#2 Thanks !
  16. 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 sound.play('', 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) { game.load.audio(key, ['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 game.load.audio(key, ['sounds/' + file + '.ogg', 'sounds/' + file + '.mp3']); } } Hope someone finds this helpful
  17. 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 < frameData.total; 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.
  18. 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!
  19. Hi all, Do you think there is a way to do the same thing like here but with many audio files (no audio sprite) ? : http://phaser.io/examples/v2/audio/audio-sprite I tried to do it by myself but no succeed... Thank for any help !
  20. i tried different songs in different file formats (mp3,wav, ogg) music = game.add.audio('theme',1,true); // key, volume, loop music.play('',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 game.sound.play('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!
  21. 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() { game.load.audio('intro', 'intro.ogg');}function create() { intro = game.add.audio('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) { intro.play('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() { game.load.audio('intro_in', 'intro_in.ogg'); game.load.audio('intro_rest', 'intro_rest.ogg');}function create() { intro_in = game.add.audio('intro_in'); intro_rest = game.add.audio('intro_rest', 1, true); space = game.input.keyboard.addKey(Phaser.Keyboard.SPACEBAR);}function update() { if (space.isDown) { intro_in.play(); game.time.events.add(200, function() { intro_rest.play();}, 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 = game.add.audio('name', true); DOES NOT loop the song. BUT var song = game.add.audio('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.
  22. So I have 3 different characters (using the same sprite at the moment). They are supposed to roam given a predefined path for each. I am using 3 different loops so that they start at different times. I don't want them to start and stop at the same time. Trying to make it as natural as possible and so far I got this http://jsfiddle.net/Batzi/abs191e5/250/ Can someone suggest improvements? I need to make it look as smooth and natural as possible.
  23. Hey all, i've noticed a weird behaviour from the soundManager. The loop of an audio sprite's marker gets broken after switching states. So to further help explain my problem, this is how i am doing things: // start preload state this.load.audio("audioSprite", ["assets/audio/audioSprite.mp3", "assets/audio/audioSprite.ogg"]); then when onLoadComplete gets called: this.game.audioSprite = this.game.add.audio("audioSprite");this.game.audioSprite.allowMultiple = true; this.game.audioSprite.addMarker("themeSong", 0, 19.2, 1, true); //(key, startingPoint, duration, volume, loop)and 7 more markers//end preload state //start menu statethis.game.audioSprite.play("themeSong");//end menu state As long as i do not switch states, the "themeSong" will continue to play and loop, but if i switch state to, say levelSelect,the "themeSong" will continue to play to the end of the specified duration but will not loop!? Any help is appreciated
  24. ok I am trying to create a loop using javascript for function in order to import the same mesh multiple times but with different XYZ coordinates. The outcome of my code below shows only one instance of the mesh. What am i doing wrong ? Here is the code: <body> <canvas id="renderCanvas"></canvas> <script> window.addEventListener('DOMContentLoaded', function(){ // get the canvas DOM element var canvas = document.getElementById('renderCanvas'); // load the 3D engine var engine = new BABYLON.Engine(canvas, true); var createScene = function () { var scene = new BABYLON.Scene(engine); //Adding a light var light = new BABYLON.PointLight("Omni", new BABYLON.Vector3(20, 20, 100), scene); //Adding an Arc Rotate Camera var camera = new BABYLON.ArcRotateCamera("Camera", 0, 0.8, 100, BABYLON.Vector3.Zero(), scene); camera.attachControl(canvas, false); for (i=0; i<5; i++) { BABYLON.SceneLoader.ImportMesh("", "", "pantene_low.babylon", scene, function (newMeshes) { // Set the target of the camera to the first imported mesh if(i==4) { camera.target = newMeshes[0]; } newMeshes[0].position.x = i+10; }); } // Move the light with the camera scene.registerBeforeRender(function () { light.position = camera.position; }); return scene; } // call the createScene function var scene = createScene(); // run the render loop engine.runRenderLoop(function(){ scene.render(); }); // the canvas/window resize event handler window.addEventListener('resize', function(){ engine.resize(); }); }); </script> </body>
  25. When looping audio in Chrome (using BABYLON.Sound), the audio only being played once and then being stopped. In Firefox everything works as expected. First I experienced this issue in my project, then I checked the playground demo and got the same result. I use babylon 2.0, the playground uses babylon 2.1 beta. Chrome version is the latest at this moment - 42.0.2311.90 m