3D Rad - Free 3D game maker - Forum

This forum is now archived!

This forum is locked, and is a read-only version. A new community-ran forum can be found at classdev.net

News:

The 3DRad community can be found at classdev.net.

Pages: [1]

Author Topic: Mouse Script  (Read 444 times)

« on: October 16, 2013, 03:21:02 AM »
Hi.

I wrote an script for mouse over and click with EventOnInput Object. But I want know can make mouse over and click without EventInInput?

Thanks
My Game : Star Wars 1.0

http://behdadgame.com/index.php?topic=3.0

possible way, if we found will make a way.

BorekS

« Reply #1 on: October 16, 2013, 04:57:53 AM »
yes, lets say for a clickable Sprite object. it could look somehow like this:
"if the mouse cursor is over the sprite (OBJ_0) and you click the mouse button 0, start OBJ_22"

Code: [Select]
if ((iMouseButtonDown(0)) && (IN_3 > 0)) {iObjectStart(OBJ_22);}
« Reply #2 on: October 16, 2013, 07:06:02 AM »
Quote
"if the mouse cursor is over the sprite (OBJ_0) and you click the mouse button 0, start OBJ_22"

Code: [Select]
if ((iMouseButtonDown(0)) && (IN_3 > 0)) {iObjectStart(OBJ_22);}
Posted on: Today at 03:21:02 AM Posted by: behdadsoft

i think there's an error in the code above...  you're going to need to check IN_1 instead of IN_3 to flag the mouseover event if the Sprite is OBJ_0...

also...

the logic stated above is faulty... open ended...  there should be a switch to indicate whether or not the target object has started, or you can continuously start the object if the mouse button is continuously pressed and released...

the logic above
Quote
"if the mouse cursor is over the sprite (OBJ_0) and you click the mouse button 0, start OBJ_22"

should be

Quote
"if the mouse cursor is over the sprite (OBJ_0) and you click the mouse button 0 and isStarted is false,  then start OBJ_22" and  isStarted is true"

once the switch (isStarted) is set, the target object cannot be restarted inadvertently, thus insuring the desired behavior...  while in most cases this won't really matter, in cases where the target object starts an animation or a sound, neglecting to make sure the logic is solid can result in undesired outcomes...

some good advice to adhere to is the computer only does what you tell it to, but a user is likely to try do anything... make sure you code for only what you want to happen...

one last thing...

although the function is called iMouseButtonDown()... i think you'll find that the mouse button release is the event is what is actually being flagged in this function...
 

--Mike
« Last Edit: October 16, 2013, 07:29:52 AM by Mike Hense »
« Reply #3 on: October 16, 2013, 03:57:06 PM »
Thanks.

I have 2 Sprite files: (Sprite 1, Sprite 2). I want when Mouse over on Sprite 1, Show Sprite 2 and when mouse leave it show again sprite 1.
I use this code for show sprite 2 but when Mouse leave it, don't show sprite 1.
Code: [Select]
      if (IN_1 > 0)
      {
         iObjectHide (OBJ_0);
         iObjectShow (OBJ_22);
      }

for for solve it I used this code but don't work.
Code: [Select]
   
  if (IN_1 <= 0)
      {
         iObjectHide (OBJ_22);
         iObjectShow (OBJ_0);
      }
Thanks
My Game : Star Wars 1.0

http://behdadgame.com/index.php?topic=3.0

possible way, if we found will make a way.
« Reply #4 on: October 16, 2013, 04:09:48 PM »
hahahaha.... sorry, but i just had to laugh (not at you B, but at what you managed to do)  ;D ;D

ok... normally i'd give the speech about you' having to learn how to figure these things out yourself... but this one is just not so obvious... 

and, it just got me laughing so hard :)

look the logic you just implemented... you're asking the program to hide the sprite when the mouse is over it... and it is doing exactly that...

but when it does exactly what you've told it to do, the logic is no longer valid, since the mouse over event can't be triggered if the sprite is not visible...

soooo... it's gonna return 0, and immediately show itself again...  sorta like a logic catch 22 :)


but after looking at your code, this isn't what's happening at all... you're logic is hiding the 2nd sprite if the mouseover event is trigger by the first sprite... which really isn't doing anything to the first one...

which is not what you say you want to do...


first of all get the logic striaght... you want the mouseover event for sprite 1 to hide sprite 2, and vice versa...

also...

try just changing the opacity of the sprite to something real low, instead of hiding it... this way,  it can't be seen, but the mouse over can still be detected...

try this code...

Code: [Select]
void Main()
{
      if (IN_23 > 0)        // if mouseover sprite 1 then lower opacity of sprite1 and raise opacity of sprite2
      {
         OUT_22=0.002;
         OUT_0=1;   
      }
      else                   // else do just the opposite...
      {
         OUT_22=1; 
         OUT_0=0.002; 
      }
}

--Mike
« Last Edit: October 16, 2013, 04:32:46 PM by Mike Hense »
« Reply #5 on: October 17, 2013, 01:38:04 AM »
Thanks Mike.
Yes, Right. I forgot for make a button with over and release must change opacity. I do it most in autoplay. ;D

I have a question: sprite object can decrease fps ? if answer is yes, how?

Thanks
« Last Edit: October 17, 2013, 02:21:59 AM by behdadsoft »
My Game : Star Wars 1.0

http://behdadgame.com/index.php?topic=3.0

possible way, if we found will make a way.
« Reply #6 on: October 17, 2013, 06:16:09 AM »
good that you got it working...

Quote
I have a question: sprite object can decrease fps ? if answer is yes, how?

sorry, but that i cannot answer... i really don't know...

i have notice performance slowdowns when i use transparencies...  lots of trees and meshes with transparent or semi transparent textures...  i think it may have something to do with the engine having to determine z ordering... or something like that...

but that's just a guess... you'll have to wait for someone more knowledgeable on the subject to answer this one...

--Mike
« Reply #7 on: October 17, 2013, 07:58:11 AM »
Quote
you'll have to wait for someone more knowledgeable on the subject to answer this one...
OK, Thanks Mike for your help. :D
My Game : Star Wars 1.0

http://behdadgame.com/index.php?topic=3.0

possible way, if we found will make a way.
« Reply #8 on: October 18, 2013, 09:58:49 AM »
I would also say to get into the habit of using transparency for sprites you want to be able to click, and show/hide for sprites that do nothing like dialog boxes.  And remember to check the Priority setting in the sprite object properties.  The one you want to click should have a higher priority.   As for buttons, you can put all the buttons on the background image, and just put the mouseover and click versions on top and change their transparency as Mike said.
« Reply #9 on: October 18, 2013, 10:01:42 AM »
Quote
Insert Quote
I would also say to get into the habit of using transparency for sprites you want to be able to click, and show/hide for sprites that do nothing like dialog boxes.  And remember to check the Priority setting in the sprite object properties.  The one you want to click should have a higher priority.   As for buttons, you can put all the buttons on the background image, and just put the mouseover and click versions on top and change their transparency as Mike said.

Thanks
My Game : Star Wars 1.0

http://behdadgame.com/index.php?topic=3.0

possible way, if we found will make a way.
Pages: [1]