[Solved] Set left-X and right-X bounderies for moving object

Started by arj0n, Sat 24/07/2010 08:01:20

Previous topic - Next topic

arj0n

Object should only be allowed to move when object.x is withing 20 and 530 [having the object horizontal size: 90].
Horizontal room size: 640.

This doesn't seem to work...:

function Block_AnyClick()
{
 Object* myobject = Object.GetAtScreenXY(mouse.x, mouse.y);
 if ((myobject.X <=530 && myobject.ClickedRightHalf())) myobject.Move(myobject.X+100, myobject.Y, 10, eBlock, eAnywhere);
 //move left
 else if (myobject.X >=20)  myobject.Move(myobject.X-100, myobject.Y, 100, eBlock, eAnywhere);
 //move right
}

GarageGothic

Your "else" runs even if only the <= part fails, so instead try:

Code: ags
function Block_AnyClick()
{
  Object* myobject = Object.GetAtScreenXY(mouse.x, mouse.y);
  if ((myobject.X <=530 && myobject.ClickedRightHalf())) myobject.Move(myobject.X+100, myobject.Y, 10, eBlock, eAnywhere);
  //move left
  else if (myobject.X >=20 && !myobject.ClickedRightHalf())  myobject.Move(myobject.X-100, myobject.Y, 100, eBlock, eAnywhere);
  //move right
}

arj0n

The object is still moving through its bounderies...

Edit: changed the <='number' and the >='number' , now it works.

SMF spam blocked by CleanTalk