Search the Community
Showing results for tags 'repeat'.
-
Hi, Im having an issue with tweens. Its a bit difficult to explain, so please bare with me.. this.tween = this.game.add.tween(this.itemToTween).to({ y: y+100 }, 100); It is a quick tween over a relatively large distance that is repeated many times. If the itemToTween is moved by say 15 pixels per frame (for example), the last frame is moved only 10 pixels to exactly end at position y+100. This 10 pixel move in the last frame as apposed to the normal 15 pixels per frame is causing hiccups/staggering on the tween repeat and other running tweens on other items are becoming out of sync position wise. The only solution I could think of was maybe doubling the distance and time of the tween and then manually checking on the tween update if the position is greater than y+100. In that case stop the tween and trigger the new tween and subtract the distance the original tween shot over y+100. This seems like such a hack though... Does anyone have a suggestion on a cleaner solution? Thanks.
-
Hi! I am a newbie to babylon js, and I already have problems. I have loaded textures to my object (stick/bar) and problem is when I resize my object, texture resizes too. I tried to apply texture after scaling object, but texture resizes anyway. I really don't want to create a new texture for every object just because its size changes. So, my questions are: Is there a way in babylon js to set its size to be fixed? Or is there a way to set texture to repeat itself rather than scale itself to wrap the object. Image is attached (mind the upper bar is longer and its texture is scaled <-- that's my problem).
- 27 replies
-
Hey! I want the weapons of a spaceship to shoot in volleys / bursts, meaning it should fire some bullets with a delay in between, reload and then repeat. I'm trying to accomplish this with simple repeat timers: // Slightly modified code fire = function() { for (var i = 0; i < weapons.length; i++) { var weapon = weapons[ i ]; if (game.time.now >= weapon.next) { // Reset reload delay (1000ms) weapon.next = game.time.now + weapon.rate; // Shoot 5 bullets with 100ms duration between game.time.events.repeat(100, 5, function() { new Bullet(game, { x: weapon.world.x, y: weapon.world.y, angle: ship.rotation }); }, game); } } } My problem is that, for some odd reason, all bullets shoot from the same weapon. The timer always takes the x, y and angle values of the last given element, no matter if i iterate the weapons with a loop or do it manually for each. Even random values don't work. Any idea? It makes no sense to me
-
Hello, I'm trying to get a button in my game to use other functions, and I haven't quite figured out how, other than brute forcing it. // Let's say I have everything preloaded and I'm in my game state filevar main = function(game) { var button1; var button2;};// and my prototype is something likemain.prototype = { create: function() { button1 = this.add.button(0, 0, 'button1', this.button1); button2 = this.add.button(100, 100, 'button2', this.button2); } button1: function() { // I might want to use otherfunc to do stuff while doing other stuff } button2: function() { // this is where I want to use button1's function and do other things } otherfunc: function() { // does more stuff }}Help is greatly appreciated.
-
Hey guys, I have used createPattern from Canvas for tiling sprites but I realized it's very expensive to use. Do you guys know any tips/other methods to do it that is faster than that? Thanks.