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

Wednesday, June 25, 2008 by superman | Discussion: DesktopX Tutorials

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..............
superman
Reply #1 Saturday, June 28, 2008 10:06 AM
Please please please help me
superman
Reply #2 Sunday, June 29, 2008 1:22 PM
I wonder!
Any great coder there!
Please write few lines dear!
And let me have my bear!
Bichur
Reply #3 Sunday, June 29, 2008 5:25 PM
RickJP
Reply #4 Sunday, June 29, 2008 5:28 PM
SirSmiley
Reply #5 Sunday, June 29, 2008 5:42 PM
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 posXobjY And posYobjX2 And posY>objY And posYobjY2 Then Object.State="bottom"
  15. ' Check to see if cursor is directly over the object.
  16. If posX>=objX And posX=objY And posY<=objY2 Then Object.State="normal"
  17. End Sub
HAPTORK
Reply #6 Sunday, June 29, 2008 5:45 PM
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
For movement start a timer and compare old mouse cordinates i.e. system.cursorx and y with new coordintes.

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

cant understand what it is. As I said add as many states as you want no restriction.

These are quicknotes its good if you can understand them and get what you want else ask Zubaz he will write a tut about this.
SirSmiley
Reply #7 Sunday, June 29, 2008 5:56 PM
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.
HAPTORK
Reply #8 Sunday, June 29, 2008 6:04 PM
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.
superman
Reply #9 Monday, June 30, 2008 4:24 AM
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......

HAPTORK
Reply #10 Monday, June 30, 2008 5:46 AM
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..
HAPTORK
Reply #11 Monday, June 30, 2008 5:58 AM
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
superman
Reply #12 Monday, June 30, 2008 6:58 AM
Thanks Haptork, I will try to figure it out.
superman
Reply #13 Monday, June 30, 2008 7:24 AM
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


HAPTORK
Reply #14 Monday, June 30, 2008 7:32 AM
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.
superman
Reply #15 Monday, June 30, 2008 8:35 AM
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.

SirSmiley
Reply #16 Monday, June 30, 2008 12:43 PM
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 posXobjY And posYobjX2 And posY>objY And posYobjY2 Then Object.State="bottom"
  49. ' Check to see if cursor is directly over the object.
  50. If posX>=objX And posX=objY And posY<=objY2 Then Object.State="normal"
  51. End Sub
  52. 'Called when the script is terminated
  53. Sub Object_OnScriptExit
  54. End Sub
superman
Reply #17 Tuesday, July 1, 2008 10:45 AM
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..

SirSmiley
Reply #18 Tuesday, July 1, 2008 1:45 PM
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 posXobjY And posYIf posX>objX2 And posY>objY And posYIf posYIf posY>objY2 Then Object.State="bottom"
If posX>=objX And posX<=objX2 And posY>=objY And posY<=objY2 Then Object.State="normal"
End Sub
superman
Reply #19 Wednesday, July 2, 2008 12:15 PM
Thank you SirSmiley, I'll try it and if i couldn't, I'll send that to you.
Thanks for helping me

Please login to comment and/or vote for this skin.

Welcome Guest! Please take the time to register with us.
There are many great features available to you once you register, including:

  • Richer content, access to many features that are disabled for guests like commenting on the forums and downloading skins.
  • Access to a great community, with a massive database of many, many areas of interest.
  • Access to contests & subscription offers like exclusive emails.
  • It's simple, and FREE!



web-wc01