• Content Count

  • Joined

  • Last visited

  • Days Won


Everything posted by valueerror

  1. it's space.. so you could stop using gravity and instead use forces.... you could use this function (give it your spaceship and the planet) to get the distance between 2 objects and then calculate the speed based on the returned distance function distanceBetween(spriteA,spriteB){ var dx = spriteA.body.x - spriteB.body.x; //distance ship X to planet X var dy = spriteA.body.y - spriteB.body.y; //distance ship Y to planet Y var dist = Math.sqrt(dx*dx + dy*dy); //pythagoras ^^ (get the distance to each other) return dist;}define speed (force) if (distanceBetween(ship,planet) < 300) { speed = 30;}else if (distanceBetween(ship,planet) < 600) { speed = 20;}else if (distanceBetween(ship,planet) < 900) { speed = 10;}and then call this function to create a force into the direction of the planet function accelerateToObject(obj1, obj2, speed) { if (typeof speed === 'undefined') { speed = 20; } var angle = Math.atan2(obj2.y - obj1.y, obj2.x - obj1.x); obj1.body.rotation = angle + game.math.degToRad(180); // correct angle if wanted obj1.body.force.x = Math.cos(angle) * speed; // accelerateToObject obj1.body.force.y = Math.sin(angle) * speed;}
  2. before i start fantasizing about possible solutions for your problem (because dot gravity is nothing p2 can do atm as far as i know) i need to ask more questions. will there be more than one planet attracting the spaceship at a time? should gravity lose it's effect with more distance to the planet? how many objects are usually affected by the planets gravity? only the spaceship?
  3. probably more like this:,myfunc,this, parameter);myfunc(parameter)be aware that if you would write it your way the function myfunc(2) would be triggered immediately because of the () brackets or if it's just a simlpe task that is going to be triggered, function(){ do this or that });
  4., myfunc);
  5. hey rich.. thank you very much for your answer.. so i can't tell my game to decode my "menu background loop" first and immediately play it. i could set some sounds (only needed later) to only decode on play to speed up the process though.. did i understand you correctly? (im using audacity with default ogg/vorbis settings to export my audiofiles btw. any tips for a good codec or export setting ?? thx again
  6. this is happening on mobile only i guess that my OGG file needs very long to be decoded.. i also tried with an MP3 and got the same result.. my music is not that long.. it's a 1.26 minute loop and i have the same problem with a 25sec loop.. (it seems to wait for every audiofile to be decoded before it starts playing.. could this be the problem? is there a way to fix that ? my preloadbar is long gone when the audio finally starts.. if i quickly select a level it even leads to another problem/bug where both audio files (the menu audio and the level audio) are played.. audio1 should be stopped before audio2 starts but since it is not playing at that specific moment (because it's probably still decoding) it is not stopped.. is this a bug?
  7. box2d looks great! but i started with arcade last year .. then switched to p2 because arcade is very limited and now im really good at it .. i'm just lazy and want to be able to rely on my knowledge a little bit longer than 6 months.. also i teach young children game development (while i'm still learning it myself ^^) and i don't want to tell them that they can now throw away what they learned about the framework and it's physics system and now need to pay 45.- to continue working with the framework. (because arcade just isn't enough for our needs) also i developed several p2 specific solutions for several problems (like my "one way platforms" or my "throw-able grappling hook", or my "top down view ramps" ) - therefore i'm just glad i just overlooked the p2 examples and rich is keeping it in the framework as first class citizen.. but box2d (i've looked into the examples) looks really clean and useful and some things seem to work better than with p2 - so i'm probably going to give it a serious try at some point.. but i'm quite sure i'm not going to use it in school because it's not free... i'm teaching foss only ;-)
  8. body.setZeroRotation() If this Body is dynamic then this will zero its angular velocity.
  9. @latestpost: this is probably the best answer to this.. thx! you know what i did until now?? here: fireball.body.onBeginContact.add(fireballCollision, fireball); //notice that instead of this i gave it the fireball as contextfunction fireballCollision(target){ thefireball = this; // here i grab the context (the fireball) and put it on "thefireball" if (target.sprite && == 'redtoad'){ killEnemy(target); thefireball.kill(); } }
  10. a tween would always lead to sort of the same outcome.. so its probably not the best solution for something like roulette for example. every rotating object in p2 has already a force that stops it.. its called angularDamping.. i would probably work with constraints. one little circle as axis body.static so it can not move and the wheel directly above it. body.dynamic of course.. connected by a distance constraint with 0 distance. myconstraint.collideConnected to false so they wont collide with each other.. thats your wheel.. the bigger problem will be the grab and rotate part. i submitted an example - its in the official repos - on how to grab a circle body and throw it away.. maybe we could alter it a little bit to fit in your usecase
  11. seems like the problem is just the debug body which isnt rendered correctly..
  12. it seems i cant even get an error message or a debug body.. it stays a rectangle.. trying with sprite.body.addCapsule(length,radius); thx for any tips!
  13. Awesome! thx rich.. i just searched in the list on the left nice makeover of the whole site and back to the topic.. great code editor.. i will definitely use it with my students.
  14. @rich: is there a reason why in the examples there is no extra p2 physics section anymore ? please don't say your letting p2 go in favor of box2d !
  15., myfunction); just use this line to create a timer.. should work!,myfunc); to repeat it every 100ms
  16. thx .. i'll have a look at "game.time.physicsElapsed" i tried this approach.. what do you think ? if ( > timeDelta1) { ufer.tilePosition.y += slidespeed; timeDelta1 = + 16;}
  17. i tried it with the game.time.loop it kinda works but it doesn't look smooth anymore..
  18. would you implement you own timer in some way to do this or should i just rely on phasers timer, moveittenpixels); ? thank you !
  19. now this issue became even more important to me.. i am moving some of my objects 10px every frame.. if the gamer has a 100hz display the game would probably run at 100fps .. and therfore close to twice as fast... i could bind the movement to a specific time frame but if there was a way to just say to phaser.. "don't you ever render more than 60fps" it would be nice. is there a way ???
  20. this is a bulky fix but if it works why not.. normally you would make sure that every frame in the spritesheet or every image of the same item in your atlas is the exact same size and that the rotation point is in the center of the image AND the character - that means in the middle of the chest in your case... arms or weapons not included because they can/should flip whereas the characterbody should rotate around its center (because thats where the anchor will be when you activate physics...)
  21. huggz is totally right.. this is a simple problem with the anchor.. your sprites are not in the same width.. it is not right aligned.. it has the anchor at 0.5 that's the default for every physics enabled sprite and it's good.. that way you can mirror the sprite along the y axis and it will not move.. in your case it would be better to set the anchor back to 0 mysprite.anchor.setTo(0,0.5);should do it.. to be exactly sure i would need a jsfiddle to demonstrate
  22. you will get the grip on the docs eventually.. they are easy to read if you already know phaser and how it is structured. for a beginner they are totally confusing.. at least in my opinion.. lets talk for example about something very common.. the physics body.. you probably know that you have to enable it for every sprite by calling game.physics.p2.enable(somesprite); then you can access it throug somesprite.body if you now want to find out what you can do with the body.. what the available methods and attributes are you go to the docs.. find the menu "physics" chose your system "p2 physics" and then "body" it will then tell you where you are on top of the page: Phaser.Physics.P2. Bodyeverything on the right side (the table) can be used directly on the body.. of course you do not write "Phaser.Physics.P2.Body.angle = 45;" but "mysprite.body.angle = 45;" another approach to the documentation is phaser chains: it automatically searches for .. for example "body" in the docs the moment you start to write "body" the one very nice thing for beginners is that on the right side (scroll down probably) it shows several use cases of the word body from real code examples from the official examples
  23. i'm curious for your solution so please post it when you are ready.... killing and resetting the object is an interesting approach.. i wonder how you will implement the striking animation
  24. hey... thank you both for your answers.. you're awesome.. this works (as nkholski said it is mirrored and the anchor is on the left side so i have to compensate for that...) ufer = game.add.tileSprite(worldwidth,0,worldwidth,worldheight,'ufer'); ufer.scale.x = -1;and westinghouse's approach also works ufer = game.add.tileSprite(0,0,worldwidth,worldheight,'ufer');ufer.tileScale.x=-1since both of your answers are correct i'm marking this one here (containing both solutions) as answer.. thx a lot!
  25. Well it depends .. The tutorial shows a way for your item to move exactly along the path.. Iguess collissions will not work either if you set x and y directly.. I used a completely different approach.. totally physics based... I placed several waypoints (small trafficcones from my tileset) on an object layer in tiled and gave them numbers.. In my code i used createfromobjects and created hidden numbered Sensor activated objects out oft them.. Then i used a custom acceleratetoobject function and everytime the object with the current target number is reached i advance the number counter by one and the Next object in line is the target.. it works and i can push the moving object away and it will try to reach its destination anyway.. oft course you will see an object running against a wall permanently if there is a wall in the way.. so its far from perfect.. but adding a litle bit more "intelligence" should be easy