kleepklep

Members
  • Content Count

    63
  • Joined

  • Last visited

About kleepklep

  • Rank
    Advanced Member

Profile Information

  • Gender
    Not Telling

Recent Profile Visitors

966 profile views
  1. I really wish this wasn't the case, but as someone pointed out to me in another post: http://phaser.io/docs/2.4.4/Phaser.Sprite.html#filters filters : Array.<Filter> Sets the filters for the displayObject. IMPORTANT: This is a webGL only feature and will be ignored by the Canvas renderer. Pretty cool portfolio! Whatever you were going to use filters for I really don't think you need them. There's plenty of eye candy already! What were you going to use them for, though? There might be a tricky way to accomplish what you were looking to do without filters.
  2. The game has to be set to Phaser.WEBGL in order for filters to work. I would share the code I used, but I scrapped it because filters were of no use to me since my game must run on Canvas. Note that Canvas has better browser support than WebGL: http://caniuse.com/#feat=canvas vs. http://caniuse.com/#feat=webgl. You might be better off just applying your filters in Photoshop like I wound up doing. Your require problem is likely because you are using \ instead of / in some cases or the file is not at the specified location.
  3. My first attempt to seamlessly loop an MP3 using a marker failed. I noted the duration of my original MP3, copied a piece of the front of it onto the tail end, loaded in the extended file and used the code below. There is still a gap in IE music.addMarker('loop', 0, 7.594666666666667, .25, true);music.play('loop');Will try some two sound trickery next.
  4. 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
  5. I tried all AAC encoding profiles and was unable to load and play any of the files with an AAC extension. I suppose because IE supports AAC in MP4, which I take to mean AAC audio inside an MP4 video file, not an AAC audio file.
  6. I had, but I must have screwed something up in my test code, because sprite.body.data.SetSleepingAllowed(false) works both on sprites created and box2d enabled in Phaser and on bodies loaded in from R.U.B.E. generated scenes. Although body.bodyDef.allowSleep is never updated, the debugger indicates that the body does stay awake. Thanks for pointing me back in the right direction! I'm guessing this also means that I could use body.data.SetLinearVelocity(x, y) rather than setting body.data.m_linearVelocity.x like I'm doing.
  7. Here's what I wound up doing. On my seesaw platforms I assign a collision category like so: seesaw.body.setCollisionCategory(1);On my ball objects I add a callback: ball.body.setCategoryContactCallback(1, function (body1, body2, fixture1, fixture2, begin) { if (begin) { //console.log(body1.name, 'hit seesaw', body2.name); body2.onBallLand(body1); } else { //console.log(body1.name, 'left seesaw', body2.name); body2.onBallLeave(body1); }}, this);The onBallLand and onBallLeave functions add or remove balls from an array that tells me what's on a seesaw. I'm updating a variable that holds each ball's starting y position when it lands and when the seesaw starts moving. When the seesaw stops moving I calculate each ball's y distance moved and if it's negative lob it upward with applyForce(0, vy * 4). I tried using velocity.y initially but was getting readings that didn't make sense, like a positive when a ball was being lifted upward. This is likely because I am updating each seesaw's position in synch with an animation using animations.currentAnim.onUpdate and animations.currentAnim.onComplete which are firing less often that each box2d update.Anyway, if anyone has a similar issue and needs some help let me know!
  8. Digging into this some more, I should be able to use SetAllowSleeping(false) or allowSleep = false, but can't figure out how to access these.
  9. I'd be interested in what you came up with. Hopefully you're following this post!
  10. I also want to point out that even if you uncheck "Sleeping allowed" in R.U.B.E., the body can still go to sleep, in which case it will not react even if you change the linear velocity. I don't see anything about sleep in the Phaser Box2D plugin API, so perhaps it wasn't implemented. To force a body to stay awake, which is not recommended from a performance standpoint but was necessary for my purposes, you can set body.data.m_sleepTime = 0 or use body.applyForce(0, 0) in Phaser's update function. With these 2 lines of code in my update function if have a wheel that follows / accelerates to the mouse / pointer and then stops. Yes, the plus sign is intentional since the quadrant system is different in R.U.B.E. wheel.data.m_linearVelocity.x = (wheel.x + game.input.x) * 0.05;wheel.data.m_sleepTime = 0;This code does the same thing for bodies generated within Phaser. sprite.body.velocity.x = (sprite.x - game.input.x) * n;//sprite.body.applyForce(0, 0); // doesn't seem to be necessary in this case!
  11. Took me forever to figure this out so wanted to share so someone else doesn't have to take forever to figure this out! If you load in a R.U.B.E. generated Box2d scene, setting body.velocity.x or body.velocity.y will not work, nor will body.moveLeft(n), body.moveRight(n), body.moveUp(n) and body.moveDown(n). You have to set body.data.m_linearVelocity.x and body.data.m_linearVelocity.y instead.
  12. Here's the actual callback code if anyone needs it! sprite.animations.currentAnim.onComplete.add(function () { console.log('animation complete');}, this);
  13. Here's the code I'm using to add images to my R.U.B.E scene in Phaser rather than in R.U.B.E, which worked better for my purposes. I right clicked in R.U.B.E.'s properties panel, added a new custom property called img (set to string) and I'm linking an image to a body if the property is defined. Alternately, you could use the body names as image names (they don't all have to be different) instead of a custom variable, but I was already using it for something else. If all of your images are defined outside of R.U.B.E. you won't need to call updateRubeSprites() in Phaser's update function. Hope someone finds this is helpful! // add images to RUBE generated bodiesfunction addImages(){ for (var i = 0; i < levelScene.bodies.length; i++) { var n = levelScene.bodies[i].name; var b = levelScene.getBody(n); // levelScene.bodies[i] breaks if (b.data.customProperties) { var img = getProp(b, 'img'); if (img){ console.log(i, b.name, img); var s = game.add.sprite(0, 0, img); s.anchor.setTo(0.5, 0.5); b.sprite = s; s.body = b; } } }}// get custom properties from RUBE generated bodiesfunction getProp(body, key) { var arr = body.data.customProperties; for (var i = 0; i < arr.length; i++) { //console.log(arr[i]); if (arr[i].name == key) { //console.log(arr[i].int); if (arr[i].int) { return arr[i].int; } else if (arr[i].string) { return arr[i].string; } } }}
  14. Ha, I didn't think to try it the other way around! Thanks! It turns out that you have to define both the body's sprite and the sprite's body to get this to work. var bridgeSprite = game.add.sprite(0, 0, 'log');bridgeSprite.anchor.setTo(0.5, 0.5);bridgeBody.sprite = bridgeSprite;bridgeSprite.body = bridgeBody;Note that if you do this and are using phaser-rube.js's removeBodyAndSprites function that the sprite would stick around. So you'd need to use body.sprite.destroy() to get rid of it.
  15. How can I attach a sprite to an existing body? I am loading in a world created using R.U.B.E., so I cannot simply create sprites and use game.physics.box2d.enable(sprite). I'm not seeing anything in any of the public or extra examples that come with the paid plugin. body.sprite = sprite doesn't work.