Fla5h Posted September 27, 2013 Share Posted September 27, 2013 Im trying to create a mouse flowing effect using phaser but im not really sure how to go about doing it, mostly due to phasers lack of docs and tutorials ,and im used to doing it using jquery etc. can someone please help? I just need my sprite to follow the mouse when left clicking and remain still otherwise. here are some examples, im trying to replicate the second example but with mouse click.heres the effect using the dom: effect #1and heres the effect using proccesing: effect #2 Link to comment Share on other sites More sharing options...
rich Posted September 27, 2013 Share Posted September 27, 2013 Save this into the examples folder (maybe in input/follow.php) then select it from the examples menu:<?php $title = "Follow Mouse"; require('../head.php');?><script type="text/javascript">(function () { var game = new Phaser.Game(800, 600, Phaser.AUTO, '', { preload: preload, create: create, update: update }); function preload() { game.load.image('ball', 'assets/sprites/shinyball.png'); } var sprite; function create() { sprite = game.add.sprite(game.world.centerX, game.world.centerY, 'ball'); } function update() { // only move when you click if (game.input.mousePointer.isDown) { // 400 is the speed it will move towards the mouse game.physics.moveTowardsMouse(sprite, 400); // if it's overlapping the mouse, don't move any more if (Phaser.Rectangle.contains(sprite.body, game.input.x, game.input.y)) { sprite.body.velocity.setTo(0, 0); } } else { sprite.body.velocity.setTo(0, 0); } }})();</script><?php require('../foot.php');?> Fla5h 1 Link to comment Share on other sites More sharing options...
Fla5h Posted September 27, 2013 Author Share Posted September 27, 2013 Oh ok thanks. wow i was making it way harder than it really was, you should have seen my code. thanks again you've been alot of of help. so far the code style that phaser use seems to be pretty similar to unity3d's javascript so im gonna reread phasers source with that in mind, hopefully that will help me out with learning everything. Link to comment Share on other sites More sharing options...
rich Posted September 27, 2013 Share Posted September 27, 2013 The docs will be here next week, fear not Fla5h and mariogarranz 2 Link to comment Share on other sites More sharing options...
Fla5h Posted September 27, 2013 Author Share Posted September 27, 2013 cool Link to comment Share on other sites More sharing options...
Jester Posted October 8, 2013 Share Posted October 8, 2013 oh, this is really great! Link to comment Share on other sites More sharing options...
Recommended Posts