Jump to content

Dragging Sprite to Bounce off Walls on Release?


Philkin
 Share

Recommended Posts

'Allo!

 

So.... I have these cloud sprites. I would like it so that when dragged and released they bounce off walls. 

 

I can drag them just fine. And the bounce off of walls when they are moving under their own velocity. However, when I drag and release them they will just stick to the wall and not bounce. I have also, unsuccessfully, tried to limit the sprites maximum speed.

 

Here is where I create my cloud sprite:

 

		clouds[cloudIndex] = new Cloud(game, cloudXML.getElementsByTagName("type")[Zadi].childNodes[0].nodeValue, cloudXML.getElementsByTagName("text")[Zadi].childNodes[0].nodeValue, cloudIndex);		clouds[cloudIndex].animations.play('pop');		clouds[cloudIndex].events.onAnimationComplete.add(addText, {param: clouds[cloudIndex]});				clouds[cloudIndex].anchor.x = 0.5;		clouds[cloudIndex].anchor.y = 0.5;		//Set physics		game.physics.enable(clouds[cloudIndex], Phaser.Physics.ARCADE);		//Enable clicking		clouds[cloudIndex].inputEnabled = true;			clouds[cloudIndex].input.enableDrag();		clouds[cloudIndex].events.onDragStart.add(startDrag, {param: clouds[cloudIndex]});    	clouds[cloudIndex].events.onDragStop.add(stopDrag, {param: clouds[cloudIndex]});		//Make clouds bouncey		clouds[cloudIndex].body.collideWorldBounds = true;		clouds[cloudIndex].body.velocity.x = -200;		clouds[cloudIndex].body.bounce.setTo(1, 1);		clouds[cloudIndex].body.maxVelocity = -200;

And here are the subsequent startDrag and stopDrag functions:
 

function startDrag(cloud){	this.param.body.velocity.x = 0;	this.param.body.moves = false;}function stopDrag(cloud){	if(checkOverlap(this.param, cloudFunnel)){		checkFunnel(this.param);		this.param.body.velocity.x = 0;		this.param.body.moves = false;	}else{		this.param.body.moves = true;		this.param.body.velocity.x = -200;	}}

There is a check here to see if it is overlapping another sprite. If it is overlapping then it should stay in position.

Can anyone help please?

Thanks!

 

P

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...