
kleepklep
Members-
Posts
63 -
Joined
-
Last visited
Everything posted by kleepklep
-
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.
-
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.
-
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.
-
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
-
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.
-
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.
-
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!
-
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.
-
I'd be interested in what you came up with. Hopefully you're following this post!
-
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!
-
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.
-
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; } } }}
-
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.
-
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.
-
Looks like this has nothing to do with my body being kinematic. As an experiment, I made the kinematic body a sensor and welded a dynamic body to it. Still no flinging power!
-
Discovered the problem. I have my game set to Phaser.CANVAS. It appears that none of the filters work in this mode.
-
I should mention that I am updating the y position of the platform using body.y. I'm doing this using a timer because I have to synchronize its movement with an animation. None of these other options do anything to the kinematic body: body.applyForce(0, -100), body.moveUp(-100), body.velocity.y = -100
-
Hello, I'm converting a Box2D project from Flash and World Construction Kit to HTML5 using Phaser and R.U.B.E. and ran into something I'm not sure how to solve. I have round bodies that land on a kinematic body which is repositioned when the user clicks on it so that it flings them a little bit. Not quite like a catapult, but more like if you were on one end of a seesaw and you were lifted up quickly so you got some air. The bodies get air in the Flash version, but in the Phaser version they don't get any. I've attached videos to illustrate this. I checked all of my variables (density, friction, gravity, etc.) and didn't find any differences. I tried changing the position of the platform more quickly, but that didn't help. I have other cases where I lift up a square body quickly to fling a round body when it hits a sensor above it. In my Flash version I don't have to do anything but that, but in Phaser I also have to use applyForce(x, y) on the body to compensate for the lack of power. That's an easy fix for that case, but for this one I'm not sure how I would handle it. I suspect that World Construction Kit might be updating the linear and angular velocity of the platform when it is repositioned which might give it that extra kick. If that's the case and Phaser doesn't do this, I'll have to calculate and update those variables manually somehow. I'll dig into this deeper to see if this is what's up, but any insight would be much appreciated! videos.zip
-
Hi, Did you ever figure this out? I'm not using Haxe, but I can't get it to work either. From what I found, this should theoretically turn my sprite white. Nothing happens, though. I am preloading the ColorMatrixFilter.js file and get no errors. var sprite = game.add.sprite(100, 100, 'ball');var colorMatrix = new PIXI.ColorMatrixFilter();colorMatrix.matrix = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1];sprite.filters = [colorMatrix];
-
Digging around in Body.js for something else I came across this: * @param {function} callback - The callback to fire on contact. Set to null to clear a previously set callback.So passing no function like I did is intended behavior. Lucky guess!
-
I fixed this by using body.removeFixture(levelScene.getFixture('square'))
- 2 replies
-
- box2d
- removeFixture
-
(and 1 more)
Tagged with:
-
Turns out the my motor speed setting of 3 wasn't enough to propel the wheel in this new environment even though the gravity, density and friction settings of everything seem to be the same. Will have to look into that. So this works, though I'm now creating the joint in R.U.B.E. instead. var joint = game.physics.box2d.revoluteJoint(wheel, gear, 0, 0, 0, 0, -300, 1000, true);Other code that may be helpful to others: // set motor speedjoint.SetMotorSpeed(100);// start motorjoint.EnableMotor(true);// stop motorjoint.EnableMotor(false);