Mouse pointer Questions

Started by Kurdt78, Sat 04/09/2010 12:36:33

Previous topic - Next topic

Kurdt78

Hello,
I wanna make an adventure. I wanna walk through pics - From one to another...(Like 1->2  and 2<-1, but also 2->3 and 3->1)
I wanna use no character, just the mouse.
My Questions:
1. Can I remove some mouse pointers? I just need one. This one changes the picture. Or perhaps later one, which does something, but
    When pointer over hotspot and picnr of mouse= 2 + mouseclick then do something)
2. How can I change the mouse picture when it's over a hotspot?
    (I wanna show an arrow pointing to the left side(when it's over the hotspot on the left side of the picture...) or an loupe when it's over something to examine.)
A reason why I wanna change the mouse cursor is that I wanna show here is something you can click at and also show the user what he can do with the hotspot.
I hope you understand what I mean.
Thanks Kurdt.

Dualnames

You need the following:

Put this on game start
Code: ags

player.Clickable=false;
player.Transparency=100;
mouse.Mode=eModeInteract;


You will be using only one mode and that's mode interact.

//on_mouse_click
Code: ags

if (button==eMouseLeft) {
ProcessClick(mouse.x,mouse.y,eModeInteract);
}


You can use ChangeModeGraphic (unless I'm mistaken) when the mouse is over a hotspot and get mouse.x to determine if its on the left or right side.
Worked on Strangeland, Primordia, Hob's Barrow, The Cat Lady, Mage's Initiation, Until I Have You, Downfall, Hunie Pop, and every game in the Wadjet Eye Games catalogue (porting)

monkey0506

You unfortunately can't really properly remove all of the extraneous cursor modes, but you can entirely disable them which will prevent them from ever being used:

Code: ags
// game_start
int i = 0;
while (i < Game.MouseCursorCount) {
  if (i != eModeInteract) mouse.DisableMode(i);
  i++;
}


Then even if you explicitly try to set, for example:

Code: ags
mouse.Mode = eModeWalkto;


It actually won't change the cursor mode at all.

Khris

#3
To change the cursor's appearance over hotspots, use a custom property. Add a number property, default value 0 (= regular hotspot i.e. no exit), name "exit", description "whatever you want".
You can set this to being a hotspot only property if you want.

Once you've done this, every hotspot game-wide has this property. It can be set to a different number in the editor, not during the game though. (You could also use a property of type text and use "up" instead of a number for an exit that's supposed to show an arrow pointing up.)

Now we need to change the cursor's sprite (assuming there's only one mode used, like described above):

Code: ags
// global.asc, above repeatedly_execute

int old_e;

// global.asc, inside repeatedly_execute

  Hotspot*h = Hotspot.GetAtScreenXY(mouse.x, mouse.y);
  int e = h.ID;
  if (e != old_e) {   // mouse moved over hotspot or left one

    old_e = e;
    int i = h.GetProperty("exit");   // read entered number

    if (e == 0) mouse.ChangeModeGraphic(mouse.Mode, DEFAULT_SLOT);  // default cursor graphic

    else if (i == 0) mouse.ChangeModeGraphic(mouse.Mode, LOUPE_SPRITE_SLOT);  // mouse over hotspot but not exit

    else mouse.ChangeModeGraphic(mouse.Mode, FIRST_EXIT_ARROW_SLOT_MINUS_ONE + i);  // change to arrow
  }


The all caps stuff in the code above is supposed to be changed to the number of the sprite slot.
Say you've imported an arrow pointing left as sprite 33, then up, right, down as 34, 35, 36.
You'd change the line in the code to look as follows:
Code: ags
    else mouse.ChangeModeGraphic(mouse.Mode, 32 + i);


Now when you create a right exit, in the properties editor, enter 3 (left = 1, up = 2, down = 4).

EDIT: error in code corrected

Kurdt78

Thanks for all the answers.
I don' understand much of what you described. Is the Scripting language C#?
I only have some experience with Blitz Basic, which I've choosen, cause it's easier to understand.
I tried to add the code of dualnames, but AGS said always: unexpected if.
The code of monkey... worked and that helped me, yes.
The code of Khris is very complicated.
When I copy the code:
int i = h.GetTextProperty("exit");   // read entered number  - Type mismatch: Cannot convert string to int.
I would like to understand what it does:
// global.asc, above repeatedly_execute

int old_e;
- defines old_ e = number

// global.asc, inside repeatedly_execute

  Hotspot*h = Hotspot.GetAtScreenXY(mouse.x, mouse.y);
- I don't know what hotspot*h is.
- Hotspot.GetAtScreenXY(mouse.x, mouse.y) - You create hotspot as part of getatscrean which gives us the xy coordinates of the mouse.
- hotspot*h would then be a new type defined as part of getatscreen?
  int e = h.ID;
- you write the hotspot-ID in a variable e, which you create at the same time.
  if (e != old_e) {   // mouse moved over hotspot or left one
- If, what's "!"?, e! is equal to old_e and I think old_ e= 0, cause we haven't give old_e a number.
    old_e = e;
- old_e get's the hotspot number
    int i = h.GetTextProperty("exit");   // read entered number
-  We create variable i and transform some text of the hotspot, i don't know which and try to write it into an int-variable?

    if (e == 0) mouse.ChangeModeGraphic(mouse.Mode, DEFAULT_SLOT);  // default cursor graphic
- If e = equal 0 then the mouse cursor stays standard

    else if (i == 0) mouse.ChangeModeGraphic(mouse.Mode, LOUPE_SPRITE_SLOT);  // mouse over hotspot but not exit
- when e is not 0 and if i = 0 then mouse.mode (which seems to change the picture and use of the cursor) use the new? variable LOUPE_SPRITE_SLOT?

    else mouse.ChangeModeGraphic(mouse.Mode, FIRST_EXIT_ARROW_SLOT_MINUS_ONE + i);  // change to arrow
- when e and i are not 0 then the mousegraphic (and use) will be changed to an arrow and the nr= i.
- where can I define the numbers of the arrows, or connect "FIRST_EXIT_ARROW_SLOT_MINUS_ONE" with a picture.
- Where can I find "i"?
Just a couple of questions to the script, but thanks.

  }

Khris

The scripting language is AGS's own, but very similar to C++.

   Hotspot*h = Hotspot.GetAtScreenXY(mouse.x, mouse.y);
This defines a pointer "h" of type hotspot. I don't create a hotspot, the hotspot under the mouse becomes the value of h (The "Get" part indicates that something is read and returned). Say the mouse is over the second hotspot, then h is now hotspot[2]. If there's no hotspot under the mouse, h is hotspot[0].

   if (e != old_e)
!= means "not equal to". If the mouse is now over a different hotspot than the previous split second, do stuff.

   int i = h.GetTextProperty("exit");   // read entered number
Like I described at the beginning of my last post, you have to create a Custom property. I typed this line wrong, it's supposed to say "GetProperty".

   else if (i == 0) mouse.ChangeModeGraphic(mouse.Mode, LOUPE_SPRITE_SLOT);
QuoteThe all caps stuff in the code above is supposed to be changed to the number of the sprite slot.
You have to erase "LOUPE_SPRITE_SLOT" and put a number there instead, in this case the slot number of the loupe sprite you want to use as cursor.

(It seems like you've only pasted my code and didn't read the other text in my post.)

Kurdt78

Thanks again.
I've read all and tried to understand.
i = True or False 0 or 1 is this correct?
I've tried this, but it  only worked on room 1. in room 2 it seems like it displays an arrow image less than 1 second.
I have to think why this happens. Perhaps you can help me, Thanks.
Perhaps, the exit4 value is set to 0 after 1 loop.
int old_e;
// put anything you want to happen every game cycle in here
function repeatedly_execute()
{
   Hotspot*h = Hotspot.GetAtScreenXY(mouse.x, mouse.y);
  int e = h.ID;
  if (e != old_e) {   // mouse moved over hotspot or left one

    old_e = e;
    int i = h.GetProperty("exit");   // read entered number
    int j = h.GetProperty("exit2"); // for the 2nd arrow
    int k = h.GetProperty("exit3");
    int l = h.GetProperty("exit4");

    if (e == 0) mouse.ChangeModeGraphic(mouse.Mode, 2);  // default cursor graphic

    else if (i == 0) mouse.ChangeModeGraphic(mouse.Mode, 2);  // mouse over hotspot but not exit

    else if (i == 1) mouse.ChangeModeGraphic(mouse.Mode, 4 + i);  // change to arrow
    else if (j == 1) mouse.ChangeModeGraphic(mouse.Mode, 5 + j);
    else if (k == 1) mouse.ChangeModeGraphic(mouse.Mode, 6 + k);
    else if (l == 1) mouse.ChangeModeGraphic(mouse.Mode, 7 + l);
   
  }
}

Khris

#7
You completely misunderstood what my code does. You don't need additional lines for every exit, that was the whole point of using a custom property in the first place.

Here's the code again.

Code: ags
  Hotspot*h = Hotspot.GetAtScreenXY(mouse.x, mouse.y);
  int e = h.ID;
  if (e != old_e) {   // mouse moved over hotspot or left one

    old_e = e;
    int i = h.GetProperty("exit");   // read entered number

    if (e == 0) mouse.ChangeModeGraphic(mouse.Mode, DEFAULT_SLOT);  // default cursor graphic

    else if (i == 0) mouse.ChangeModeGraphic(mouse.Mode, LOUPE_SPRITE_SLOT);  // mouse over hotspot but not exit

    else mouse.ChangeModeGraphic(mouse.Mode, FIRST_EXIT_ARROW_SLOT_MINUS_ONE + i);  // change to arrow
  }


YOU ARE NOT SUPPOSED TO ADD LINES TO THIS, OK?

Let's go through the code with an example:
(Remember: When you create a right exit, in the properties editor, enter 3 (left = 1, up = 2, down = 4).)

Say you have drawn an exit at the right hand side of your room, hotspot 1.
Now you open the properties editor, and where it says "exit", you enter the number 3. This will tell AGS to display the arrow pointing to the right when the mouse is over the hotspot.

When you run the code and move the mouse over the exit, what happens is this:

e is set to 1.

Since old_e is 0 (= no hotspot), the rest of the code is run.

old_e is set to e, i.e. 1.

i is set to 3 (that's the three we have entered in the properties of the hotspot. 3 = right exit)

e is not 0, so don't set the cursor to the default graphic (e.g. walking, crosshairs, etc.).

i is not 0, so don't set it to the loupe sprite

instead, set it to the image of a right arrow. How?
When you import the images of the arrows in the sprite editor, import them in the order I've mentioned above: left, up, right, down
As an example, say the left arrow sprite got number 18, the up is 19, right is 20, down is 21
Thus, FIRST_EXIT_ARROW_SLOT_MINUS_ONE should obviously replaced by 17 (18 minus one).

So the line in code should read:
    else mouse.ChangeModeGraphic(mouse.Mode, 17 + i);  // change to arrow


So, right exit, i is 3, thus 17 + i is 20, the sprite slot number of the arrow pointing right.

Kurdt78

Thanks Khris.
I could only change the property nr to 0 or 1 cause it was boolean.
Now I changed the type to number and it works.
I had only to add a i > 0 instead of i ==1 and change the exit number for no exit hotspots to 0...
int old_e;
// put anything you want to happen every game cycle in here
function repeatedly_execute()
{
  Hotspot*h = Hotspot.GetAtScreenXY(mouse.x, mouse.y);
 int e = h.ID;
 if (e != old_e) {   // mouse moved over hotspot or left one

   old_e = e;
   int i = h.GetProperty("exit");   // read entered number
 

   if (e == 0) mouse.ChangeModeGraphic(mouse.Mode, 2);  // default cursor graphic

   else if (i == 0) mouse.ChangeModeGraphic(mouse.Mode, 2);  // mouse over hotspot but not exit

   else if (i > 0) mouse.ChangeModeGraphic(mouse.Mode, 4 + i);  // change to arrow

Thanks a lot.

Khris

Glad it finally works.
The "if (i > 0)" is redundant, "else" alone covers all other possibilities, and since we don't use negative values for i, we don't need to check if it's positive either. It doesn't matter though.

SMF spam blocked by CleanTalk