Jump to content

Puzz3l

Members
  • Content Count

    25
  • Joined

  • Last visited

Reputation Activity

  1. Like
    Puzz3l got a reaction from ylluminarious in How do you show the hitbox of a sprite?   
    So I'm playing around with hitbox bounds, but I want to actually be able to see the hitbox in-game. Is there a way to do that?
  2. Like
    Puzz3l reacted to george in Force sprite to rotate with P2 physics body   
    Sorry for the typo with 'body.rotate'. That tool is the right one but your solution is also nearly working.
    You have three possibilities:
    1. Set body to fixedRotation (body.fixedRotation = true). Now the rotation of the sprite is in your hands- but decoupled from the body- obviously not want you want.
    2. Update the rotation as you planned it. Simply do this:
    sprite.body.rotation = game.physics.arcade.angleToPointer(sprite) - Math.PI/2 -Math.PI/2 is -90deg end normalize the value from Math.atan2 so that 0deg is the top of the sprite. The rotation you set here will be synced with the body later in the body update automatically. With a physic engine, you have to let the engine do the work. So never touch the rotation property of the sprite itself. Downside of this method: If you want to apply any other force to the rotation you have to calculate it yourself. That brings us to the angularVelocity method via rotateLeft/Right.
     
    3. Rotate the sprite via a velocity value. The angular velocity. 
    Here you have to calculate a little more, as the angle jumps when the phase of the angle changes. You won't notice it in example 2, as there are no substeps.
     
    This is the method I tested for you.
    function update() { //1. angleToPointer makes no assumption over our current angle- th thinks it's always 0 //2. so include the current rotation of our sprite in the expression //3. subtract Math.PI/2 as the angle of atan2 (which is sued by angleToPointer) is rotated by 90deg (this is Math.PI/2) //Result: Now we have a delta value that if applied directly to rotation would yield //in a value so that the sprites top center points to the mouse. deltaMouseRad = sprite.rotation - game.physics.arcade.angleToPointer(sprite) - Math.PI/2; //don't be confused. I want the P of 'Phaser' to point to the mouse so rotate it again by -90deg deltaMouseRad = deltaMouseRad - Math.PI/2 mod = Math.PI * 2 //modulo on float, works in js, means: clamp value to [-Math.PI*2,Math.PI*2] deltaMouseRad = deltaMouseRad % mod; //lets call it phase shift, angle would jump, lets fix it if (deltaMouseRad != deltaMouseRad % (mod/2) ) { deltaMouseRad = (deltaMouseRad < 0) ? deltaMouseRad + mod : deltaMouseRad - mod; } //speed is some factor to get the object faster to the target rotation. //remember we are wotking with the angle velocity and let the engine //rotate the body speed = 150 sprite.body.rotateLeft(speed * deltaMouseRad);} Here a fiddle of it. You can change the update method from update: update to update: updateSimple to watch the simple method mentioned in 2)
    http://jsfiddle.net/wvaJ3/1/
     
    I only did this summary of this topic so I could verify what I thought. With a little more of endurance you should have found it yourself.
     
    Regards George
  3. Like
    Puzz3l reacted to jpdev in Space bar listener to trigger pause screen only firing twice   
    I think using dev directly is a gamble. (things might be improved, other things might be temporary broken.)
     
    It also depends on if you build the phaser.js (and phaser.min.js) from the content of the dev repository, or if you use the phaser.js that is in the dev repository.
     
    (For building you need nodejs and grunt - it's not hard to do, but takes at least some getting used to - i am sure there is a tutorial how to do it somewhere *g*)
     
    This is because more often then not (rich and other contributors) just updates the single source files and not always the complete phaser.js.
  4. Like
    Puzz3l reacted to jpdev in How do you show the hitbox of a sprite?   
    important note (for future users finding this question), as it's already working for you.
     
    This only works in canvas mode (so you might have to initialize your game with Phaser.CANVAS instead of Phaser.AUTO)
  5. Like
    Puzz3l reacted to jpdev in Space bar listener to trigger pause screen only firing twice   
    Is it possible that there is more going on in your code?
    Because i just pasted your 4 lines from the post directly into the create function of my game, and space paused and unpaused the game multiple times without problems.
     
    (disclaimer: the project I just checked this in is phaser 2.0 beta .. not the current 2.0.3)
×
×
  • Create New...