Drag'n'Drop: drag'n'drop object goes through other objects and bounderies

Started by arj0n, Sun 15/08/2010 12:14:56

Previous topic - Next topic

arj0n

How can I change this code so that the object is only drag'n'Dropped left or right?

Code: ags

function room_RepExec()
{
  if (mouse.IsButtonDown(eMouseLeft)) {
    if (button_pressed==0) {
      button_pressed = 1;
      ob = Object.GetAtScreenXY(mouse.x, mouse.y);
    }
  } 
  else {
    button_pressed=0;
    if (ob!=null) {
      ob=null;
    }
  }
  if (ob != null) {
    int width  = Game.SpriteWidth[ob.Graphic];
    int height = Game.SpriteHeight[ob.Graphic];
    ob.SetPosition(mouse.x-width/2, mouse.y+height/2);  
}
}

tzachs

If I understand you correctly, replace the last line with:

Code: ags

ob.SetPosition(mouse.x-width/2, ob.Y);  


And you can then also remove the line before it (int height = ...)

arj0n


arj0n

To get a clear view of what I'm trying to explain, check the game-demo "Blockz".

This part of code checks, when dragging 'myobject' to the right, if an object called 'oBlockb' is at a certain coordinate [and therefor being in it's way].
If so, 'myobject' [the dragged object] shouldn't move.
It also should let the dragged object only move right when it's X <=360.

Problems:
* If I drag the object really quick it drags through oBlockb instead of being blocked by it.
* If I drag the object really quick it drags through the  <=360 boundary.
* If I drag the object slowly it stops because of "myobject.X+120==oBlockb.X", but then I also can't drag it to the left...

So, how to solve these problems...

And: is there maybe a better way to check if objects are blocking the to-be-dragged "myobject'?

Code: ags

Object* myobject = Object.GetAtScreenXY(mouse.x, mouse.y);
 if (mouse.IsButtonDown(eMouseLeft)) {
    if (button_pressed==0) {
      button_pressed = 1;
      ob = Object.GetAtScreenXY(mouse.x, mouse.y);
    }
  } 
  else {
    button_pressed=0;
    if (ob!=null) {
      //ob.Baseline = 0;   
      ob=null;
    }
  }
  if ((ob != null) && (Game.SpriteWidth[myobject.Graphic]==120) && 
  (myobject.X+120==oBlockb.X &&  myobject.Y-60==oBlockb.Y-60 && myobject.X <=360)){
    int width  = Game.SpriteWidth[ob.Graphic];
    int height = Game.SpriteHeight[ob.Graphic];
  ob.SetPosition(ob.X, ob.Y);}  
  
  else if  ((ob != null) && (Game.SpriteWidth[myobject.Graphic]==120) && 
  (myobject.X+120==oBlockb.X && myobject.Y-60==oBlockb.Y-120 && myobject.X <=360)) {
    int width  = Game.SpriteWidth[ob.Graphic];
    int height = Game.SpriteHeight[ob.Graphic];
  ob.SetPosition(ob.X, ob.Y);}  
    
  else if  (ob != null){
    int width  = Game.SpriteWidth[ob.Graphic];
    int height = Game.SpriteHeight[ob.Graphic];
    ob.SetPosition(mouse.x-width/2, ob.Y); 


Regards,
Arj0n.

SMF spam blocked by CleanTalk