axxion Posted July 16, 2014 Share Posted July 16, 2014 Hi i want track mouse moves with this code but not showing good in localhost, jsfiddle web site showing good but localhost not, why? http://jsfiddle.net/axxion/FEXea/ Link to comment Share on other sites More sharing options...
lewster32 Posted July 16, 2014 Share Posted July 16, 2014 If it's working in jsfiddle but not locally, the problem will probably be with the HTML file you're including it in. Can you put that into the fiddle in the HTML bit as well please? Link to comment Share on other sites More sharing options...
axxion Posted July 16, 2014 Author Share Posted July 16, 2014 and u see collide not work here, but localy working collide Link to comment Share on other sites More sharing options...
axxion Posted July 16, 2014 Author Share Posted July 16, 2014 i use this code but if mouse pointer stop object always chillsfunction update() {game.physics.arcade.collide(balls,platforms); if (game.input.mousePointer.isDown) { balls.forEach(game.physics.arcade.moveToPointer, game.physics.arcade, false, 900); } else { balls.setAll('body.velocity.x', 0); balls.setAll('body.velocity.y', 0); } }and if i use code this style, object gone in screen immediately<!doctype html> <html lang="en"> <head> <meta charset="UTF-8" /> <title> game</title> <script type="text/javascript" src="js/phaser.min.js"></script> <style type="text/css"> body { margin: 0; } </style></head><body><script type="text/javascript">var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create, update: update });function preload() { game.load.image('ball', 'assets/sprites/shinyball.png'); game.load.image('ground', 'assets/platform.png');}var balls;function create() {game.world.setBounds(0, 0, 2000, 2000); game.physics.startSystem(Phaser.Physics.ARCADE); game.stage.backgroundColor = '#0072bc'; balls = game.add.group(); balls.enableBody = true; var ball = balls.create(0, 0, 'ball'); platforms = game.add.group(); platforms.enableBody = true; var ledge = platforms.create(400, 400, 'ground'); ledge.body.immovable = true; }function update() {game.physics.arcade.collide(balls,platforms); if (game.input.mousePointer.isDown) { balls.x = game.input.mousePointer.x;balls.y = game.input.mousePointer.y; } else { balls.setAll('body.velocity.x', 0); balls.setAll('body.velocity.y', 0); } }</script></body></html> Link to comment Share on other sites More sharing options...
lewster32 Posted July 16, 2014 Share Posted July 16, 2014 I think whatever you do you're going to have problems with this. When moving a physics object via drag, you won't get consistent collisions (if at all) because collisions rely on velocity-based movement, not constant setting of x/y positions. Link to comment Share on other sites More sharing options...
axxion Posted July 16, 2014 Author Share Posted July 16, 2014 You are saying a object not have this two features same time: mouse track and collision, right? And thanks for replys, i want tutorial or document for this style issues, and maybe u have some suggestion for me physics in 2d games etc... i want mouse track with a object and this object collide other objects. thanks Link to comment Share on other sites More sharing options...
lewster32 Posted July 16, 2014 Share Posted July 16, 2014 Yeah basically, collisions rely on the object colliding having a velocity. If you're telling the object every frame what its x and y positions should be, then the object has no velocity to calculate, and collisions will not occur... or will occur but go crazy, depending how and when in the frame you do it. You need something more like the 'moveToPointer' code (which sets the velocity such that it moves to the pointer position) but only when the pointer is held down on the object, and somehow smooth out that weird vibrating/orbiting issue that happens when it reaches the pointer. Link to comment Share on other sites More sharing options...
axxion Posted July 16, 2014 Author Share Posted July 16, 2014 now i think i not need physics for start, only need collision style object behavior, any example for this or helpfull doc. i want mouse track with a object and this object collision style object behavior other objects. Link to comment Share on other sites More sharing options...
lewster32 Posted July 16, 2014 Share Posted July 16, 2014 Unfortunately collision is part of the physics package. I don't really know what to suggest in your case, it seems a simple problem but I suspect it's deceptive. Link to comment Share on other sites More sharing options...
InsaneHero Posted July 17, 2014 Share Posted July 17, 2014 The usual way to do this is to make the object that is tracking the mouse be connected to an invisible point with a joint.You move the invisible point to match the mouse pointer, then the joint makes the tracking object follow closely. The difference it makes to the physics is that you are no longer directly moving the collision entity, so the physics can stretch/break the joint if it needs to in order to stop impossible situations. (A simple "impossible situation" example: you move the mouse through a solid wall... the physics collisions say "that can't happen" but the object is attached to your mouse so it has to happen... result = broken physics). With the invisible point solution, the mouse moves through the wall, and the invisible (non-colliding point) moves through the wall too, but the joint stretches or breaks so the tracking object stops when it hits the wall. Link to comment Share on other sites More sharing options...
axxion Posted July 17, 2014 Author Share Posted July 17, 2014 thank you, im trying this method. Link to comment Share on other sites More sharing options...
Recommended Posts