Assigning states to a desktopx object according to mouse position or movement
Wednesday, June 25, 2008 by superman | Discussion: DesktopX Tutorials
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..............
Reply #2 Sunday, June 29, 2008 1:22 PM
Any great coder there!
Please write few lines dear!
And let me have my bear!
Reply #5 Sunday, June 29, 2008 5:42 PM
1. normal
2. left
3. right
4. top
5. bottom
Use this code
- 'Called on mouse over object
- Sub Object_OnMouseEnter
- Object.Sleep 500 ' Pause for half a second to allow mouse to move
- Call CursorPos
- End Sub
- 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
- ' Check to see if cursor is to the left and below the top of the object
- If posX objY And posY objX2 And posY>objY And posY objY2 Then Object.State="bottom"
- ' Check to see if cursor is directly over the object.
- If posX>=objX And posX =objY And posY<=objY2 Then Object.State="normal"
- End Sub
Reply #6 Sunday, June 29, 2008 5:45 PM
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.
Reply #7 Sunday, June 29, 2008 5:56 PM
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 Sunday, June 29, 2008 6:04 PM
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 Monday, June 30, 2008 4:24 AM
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
Thank you very much......
Reply #10 Monday, June 30, 2008 5:46 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..
Reply #11 Monday, June 30, 2008 5:58 AM
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 #13 Monday, June 30, 2008 7:24 AM
Thanks for the script dear, but,
Timer may stop my animation in middle. Also, it won't give a control to the user.
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 Monday, June 30, 2008 7:32 AM
Then use the condition, like...
if curx> originx and cury< originy then
If object.state= "q1" then
'do nothing
else object.state= "q1"
Mouse over on your object with that script from different directions and you will see different animations.
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 Monday, June 30, 2008 8:35 AM
I had done that..
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 Monday, June 30, 2008 12:43 PM
Let's see if the complete script posts this time!
- ' States:
- ' normal
- ' left
- ' right
- ' top
- ' bottom
- 'Called on mouse over object
- Sub Object_OnMouseEnter
- Call CursorPos
- End Sub
- 'Called when mouse leaves object
- Sub Object_OnMouseLeave
- Object.Sleep 500 ' Pause for half a second to allow mouse to move
- Call CursorPos
- End Sub
- 'Called while object's state is changing
- ' Object.SetPicture fileName, frames, interval, flags
- ' Frames Is the number of frames In the picture.
- ' Interval Is the number of milliseconds between Each frame.
- ' Flags Is a combination of the following flags:
- ' &H00000001 – Loop
- ' &H00000002 – Reverse
- ' &H00000004 – Alternate
- ' &H00000008 – Interruptable
- ' &H00000010 – Static
- Sub Object_OnStateChange(state)
- Select Case state
- Case "normal"
- Object.States("normal").SetPicture "sonic.png",12,75,&H00000004
- Case "left"
- Object.States("left").SetPicture "sonic.png",41,75,&H00000004
- Case "right"
- Object.States("right").SetPicture "sonic.png",35,75,&H00000004
- Case "top"
- Object.States("top").SetPicture "sonic.png",29,75,&H00000004
- Case "bottom"
- Object.States("bottom").SetPicture "sonic.png",33,75,&H00000004
- End Select
- End Sub
- 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
- ' Check to see if cursor is to the left and below the top of the object
- If posX objY And posY objX2 And posY>objY And posY objY2 Then Object.State="bottom"
- ' Check to see if cursor is directly over the object.
- If posX>=objX And posX =objY And posY<=objY2 Then Object.State="normal"
- End Sub
- 'Called when the script is terminated
- Sub Object_OnScriptExit
- End Sub
Reply #17 Tuesday, July 1, 2008 10:45 AM
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 Tuesday, July 1, 2008 1:45 PM
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
If posX>=objX And posX<=objX2 And posY>=objY And posY<=objY2 Then Object.State="normal"
End Sub
Reply #19 Wednesday, July 2, 2008 12:15 PM
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!








Reply #1 Saturday, June 28, 2008 10:06 AM