Object Over Hotspot

Started by Swamp Witch, Thu 13/10/2005 18:17:53

Previous topic - Next topic

Swamp Witch

Is there a way to script if an object is on a hotspot?

Ashen

#1
Not directly, AFAIK.
However, you could use the Object.X/Y properties and Hotspot.GetAtScreenXY(x, y) to work it out. Note, however, that Object.X/Y use room coordinates, and Hotspot.GetAtScreenXY(x, y) uses screen coords, so you'd need to do something like:

if (Hotspot.GetAtScreenXY (oMyobject.X - GetViewportX(), oMyobject.Y - GetViewportY()) == hMyhotspot) { // if MyObject is on MyHotspot
  DoSomething();
}
I know what you're thinking ... Don't think that.

Swamp Witch

Woohoo! That did the trick.Ã,  If you can help with one more thing, I can get this puzzle working.Ã,  This script is for a click and drag puzzle.Ã,  When clicking on an object, the cursor will carry it.Ã,  When it hits the correct hotspot, I then want the mouse to release the object.Ã,  This is where I am having trouble.Ã,  I can't get it to release the object and it pulls it away from the hotspot when I click somewhere else.

// room script file

int button_pressed=0, ob=-1;

#sectionstart room_aÃ,  // DO NOT EDIT OR REMOVE THIS LINE
function room_a() {
Ã,  // script for Room: Repeatedly execute
if (IsButtonDown(LEFT)) {
Ã,  Ã,  if (button_pressed==0) {
Ã,  Ã,  Ã,  button_pressed = 1;
Ã,  Ã,  Ã,  ob = GetObjectAt(mouse.x, mouse.y);
Ã,  Ã,  }
Ã,  } else {
Ã,  Ã,  button_pressed=0;
Ã,  Ã,  if (ob!=-1) {
Ã,  Ã,  Ã,  SetObjectBaseline(ob, 0);Ã,  Ã,  Ã, 
Ã,  Ã,  Ã,  ob=-1;
Ã,  Ã,  }
Ã,  }
Ã,  Ã, 

Ã,  if (ob != -1) {
Ã,  Ã,  int widthÃ,  = GetGameParameter(GP_SPRITEWIDTH, GetObjectGraphic(ob), 0, 0);
Ã,  Ã,  int height = GetGameParameter(GP_SPRITEHEIGHT, GetObjectGraphic(ob), 0, 0);
Ã,  Ã,  SetObjectBaseline(ob, game.room_height);
Ã,  Ã,  SetObjectPosition(ob, mouse.x-width/2, mouse.y+height/2);
}

if (Hotspot.GetAtScreenXY (oBlackball.X - GetViewportX(), oBlackball.Y - GetViewportY()) == hhotspot1) { // if MyObject is on MyHotspot
Ã,  Display ("This is a test");
}

Elliott Hird

#3
Here's a few threads:

http://www.adventuregamestudio.co.uk/yabb/index.php?topic=14984.0

http://www.adventuregamestudio.co.uk/yabb/index.php?topic=18626.0

http://www.adventuregamestudio.co.uk/yabb/index.php?topic=9963.0

Hope they help.


Edited by Ashen: There's no need to quote the whole post directly above you.
Reply by me: Sorry, forgot.

Swamp Witch

Thank you Elliott.Ã,  I have already looked at these posts.Ã,  It is the third post that is doing what I am looking for.Ã,  The problem is that there is a link for the dropping part of the object and the link no longer works.Ã,  I've tried numerous things from all these posts, but I can't get it to work.

Ashen

Try removing the 'anonymizer' part of the link, like this.
I know what you're thinking ... Don't think that.

SMF spam blocked by CleanTalk