Fla5h

mouse following

Recommended Posts

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 #1

and heres the effect using proccesing: effect #2

Share this post


Link to post
Share on other sites

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');?>

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

  • Recently Browsing   0 members

    No registered users viewing this page.