Assigning states to a desktopx object according to mouse position or movement

Hi Usually there are four states for a desktopx object.... mouse up, down, over and away...
However I need a script for assigning different states to a object according to position or movement of mouse....

1..As for position, if the object is origin there will be four quadrants....
so one state for each quadrant......

Or
2..According to movement of mouse .....
If mouse goes to left, right, up & down of object then different states for each movement & if mouse remains static then other state likewise..

Or
3.. I need some distinct states controolable by mouse.. 4 or 5 will be enough....

Hope someone has some idea......

Thank you very much..............
58,534 views 19 replies
Reply #2 Top
I wonder!
Any great coder there!
Please write few lines dear!
And let me have my bear!
Reply #3 Top
Reply #5 Top
Create five states named below
1. normal
2. left
3. right
4. top
5. bottom

Use this code
Code: vbscript
  1. 'Called on mouse over object
  2. Sub Object_OnMouseEnter
  3. Object.Sleep 500 ' Pause for half a second to allow mouse to move
  4. Call CursorPos
  5. End Sub
  6. Sub CursorPos
  7. posX=System.CursorX ' Cursor Left
  8. posY=System.CursorY ' Cursor Top
  9. objX=Object.Left ' Object's Left Position
  10. objX2=Object.Right ' Object's Right Position
  11. objY=Object.Top ' Object's Top Position
  12. objY2=Object.Bottom ' Object's Bottom Position
  13. ' Check to see if cursor is to the left and below the top of the object
  14. If posX<objX And posY>objY And posY<objY2 Then Object.State="left"
  15. ' Check to see if cursor is to the right and below the top of the object
  16. If posX>objX2 And posY>objY And posY<objY2 Then Object.State="right"
  17. ' Check to see if cursor is above the top of the object
  18. If posY<objY Then Object.State="top"
  19. ' Check to see if cursor is below the bottom of the object
  20. If posY>objY2 Then Object.State="bottom"
  21. ' Check to see if cursor is directly over the object.
  22. If posX>=objX And posX<=objX2 And posY>=objY And posY<=objY2 Then Object.State="normal"
  23. End Sub
Reply #6 Top
There is no limit of how many states an object can have. Click on add state and you can write any desired name of the state. Write 1q-for first quadrant and so on.
Now start a timer, do a check of where system.cursorx and system.cursory is with respect to the centre of the object i.e. object.left+object.width/2. Now assign a different state to every case like
if system.cursorx>object.left+object.width/2 and system.cursory
Reply #7 Top
IMO a timer is overkill for this. Originally I did a timer but, you still need to pause then call another procedure to adjust the x,y positions and the timer runs for no reason.

Where a timer would be good is if you wanted to add keyboard control and monitor key presses. Eg. Mouse left down, Mouse left up, Mouse left over, etc.
Reply #8 Top
I think the question isnt clear. I thought he wants to get different animations of an object when mouse is at different quadrants while taking object as origin while mouse is away. Why I thought this cause I was dealing with something like this a few days before so when I read the thread it came in my mind b4 understanding the question.
If its about different mouse overs in different quadrants then there is no need of timers at all. Thanks SirS.

So its a case whether you want it animate while mouseover or mouseaway.
Reply #9 Top
Thanks SirSmiley and Haptork but I failed to use the script properly.
The only one animated state i could show is the normal state.

Here is what I did....
A... Inserted the script.
B... Assigned states as 'normal', 'left', 'right', 'top', 'bottom' and added respective animations as the appearance(under states)..
The animations had 12, 41, 35, 29 and 33 frames respectively...
C... Then I export the widget but wherever is my pointer or however it moves, it shows just one state 'normal'.


I don't know what should I do. Can You Please Help Me Once Again...

Here are the number of frames once again for a quick look....

1. normal...12
2. left.....41
3. right....35
4. top......29
5. bottom...33

My objective was to create an animated character for desktopx which entertains the user as
the position of pointer changes. In a way he could control the states by changing the position of pointer.

Hope u got my problem..and help me too :) like always

Thank you very much...... :)

Reply #10 Top
The script SirS worte was for mouseover from different directions.
SO For getting what you want you have to start a Timer as I saide earlier. Ok I am writing some rough script here..
Reply #11 Top
Sub Object_OnMouseEnter
Object.Settimer 1,15 'Timer to check mouse position wrt to object
End Sub

Sub Object_OnTimer1
originx=object.left+object.width/2
originy=Object.Top+object.height/2
curx=system.cursorx
cury=system.cursory
if curx> originx and cury< originy then
object.state= "q1"
elseif curx< originx and cury< originy then object.state= "q2"
elseif curx< originx and cury> originy then object.state= "q3"
else object.state="q4"
Endif
End sub
Reply #12 Top
Thanks Haptork, I will try to figure it out. :)
Reply #13 Top
SO For getting what you want you have to start a Timer as I saide earlier. Ok I am writing some rough script here..


Thanks for the script dear, but,
Timer may stop my animation in middle. Also, it won't give a control to the user.


The script SirS worte was for mouseover from different directions.


What i did wrong here.... Can you please point out...

Here is what I did....
A... Inserted the script.
B... Assigned states as 'normal', 'left', 'right', 'top', 'bottom' and added respective animations as the appearance(under states)..
The animations had 12, 41, 35, 29 and 33 frames respectively...
C... Then I export the widget but wherever is my pointer or however it moves, it shows just one state 'normal'.


How to show the other states.. Tell me the first step please, I'll do the rest.

Thanks Again


Reply #14 Top
Timer may stop my animation in middle


Then use the condition, like...
if curx> originx and cury< originy then
If object.state= "q1" then
'do nothing
else object.state= "q1"

What i did wrong here.... Can you please point out...

Mouse over on your object with that script from different directions and you will see different animations.
If posXobjY And posYobjX2 And posY>objY And posYobjY2


I think there are some ">" and "< " signs missing in that script. It happend with me too while posting that script. Maybe I'm getting it wrong on my opera browser.
Reply #15 Top
Mouse over on your object with that script from different directions and you will see different animations.

I had done that..


I think there are some ">" and "< " signs missing in that script. It happend with me too while posting that script.


May be the script not for animated states.
I tried to use the barney[dx widget] script but it needed perhaps more frames because my object was moving like being pulled... means sometimes it was seen and sometimes moving quickly..I had about half the frames for the state of barney I was trying to replace with my animation.


Leave the one in orange. No need to think there, I just said for reference...

And thanks once again for your help...I'll try... but I don't know much about it.

Reply #16 Top
Personally, I would script the animation. You need to use on state change either way.

Let's see if the complete script posts this time!
Code: vbscript
  1. ' States:
  2. ' normal
  3. ' left
  4. ' right
  5. ' top
  6. ' bottom
  7. 'Called on mouse over object
  8. Sub Object_OnMouseEnter
  9. Call CursorPos
  10. End Sub
  11. 'Called when mouse leaves object
  12. Sub Object_OnMouseLeave
  13. Object.Sleep 500 ' Pause for half a second to allow mouse to move
  14. Call CursorPos
  15. End Sub
  16. 'Called while object's state is changing
  17. ' Object.SetPicture fileName, frames, interval, flags
  18. ' Frames Is the number of frames In the picture.
  19. ' Interval Is the number of milliseconds between Each frame.
  20. ' Flags Is a combination of the following flags:
  21. ' &H00000001 – Loop
  22. ' &H00000002 – Reverse
  23. ' &H00000004 – Alternate
  24. ' &H00000008 – Interruptable
  25. ' &H00000010 – Static
  26. Sub Object_OnStateChange(state)
  27. Select Case state
  28. Case "normal"
  29. Object.States("normal").SetPicture "sonic.png",12,75,&H00000004
  30. Case "left"
  31. Object.States("left").SetPicture "sonic.png",41,75,&H00000004
  32. Case "right"
  33. Object.States("right").SetPicture "sonic.png",35,75,&H00000004
  34. Case "top"
  35. Object.States("top").SetPicture "sonic.png",29,75,&H00000004
  36. Case "bottom"
  37. Object.States("bottom").SetPicture "sonic.png",33,75,&H00000004
  38. End Select
  39. End Sub
  40. Sub CursorPos
  41. posX=System.CursorX ' Cursor Left
  42. posY=System.CursorY ' Cursor Top
  43. objX=Object.Left ' Object's Left Position
  44. objX2=Object.Right ' Object's Right Position
  45. objY=Object.Top ' Object's Top Position
  46. objY2=Object.Bottom ' Object's Bottom Position
  47. ' Check to see if cursor is to the left and below the top of the object
  48. If posX<objX And posY>objY And posY<objY2 Then Object.State="left"
  49. ' Check to see if cursor is to the right and below the top of the object
  50. If posX>objX2 And posY>objY And posY<objY2 Then Object.State="right"
  51. ' Check to see if cursor is above the top of the object
  52. If posY<objY Then Object.State="top"
  53. ' Check to see if cursor is below the bottom of the object
  54. If posY>objY2 Then Object.State="bottom"
  55. ' Check to see if cursor is directly over the object.
  56. If posX>=objX And posX<=objX2 And posY>=objY And posY<=objY2 Then Object.State="normal"
  57. End Sub
  58. 'Called when the script is terminated
  59. Sub Object_OnScriptExit
  60. End Sub
+1 Loading…
Reply #17 Top
Thank You SirSmiley but I know I am doing something wrong.
I put the script but still the only one animation I could see.
This is only my second scripted widget I am trying the first was Ripples..
This is what I did today...
A. Replaced the script with this one.
B. Still I could see only one animation of normal state...
C. Although there where six states, the sixth was command executed...
D. Next, I removed command executed state to leave it with only five.
E. In both cases C & D ie with or without command executed state being there, I could
see the only normal state animation.

If you please I can mail the widget to you.

Thanks for the help... I will try more..

:)
Reply #18 Top
This sub didn't post fully, try it.
If it doesn't work then send it to me.
Sub CursorPos
posX=System.CursorX ' Cursor Left
posY=System.CursorY ' Cursor Top
objX=Object.Left ' Object's Left Position
objX2=Object.Right ' Object's Right Position
objY=Object.Top ' Object's Top Position
objY2=Object.Bottom ' Object's Bottom Position
If posX
Reply #19 Top
Thank you SirSmiley, I'll try it and if i couldn't, I'll send that to you.
Thanks for helping me :)