Dual Display - Moving Objects
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
Dual Display - Moving Objects
Hello. I'm new to this stuff so bear with me because I just started playing with Rev a few days ago. I'm trying to write a little app to display a moving object around the screen. One stack controls the object on another stack. It works fine with one display but I'm having trouble when setting screenrects() for second monitor. I can get the correct screenRect of 2nd monitor just fine but when moving object based on screenRect of 2nd monitor my object disappears somewhere. Here's what I have so far:
on mouseUp
set fullscreen of stack "MovingObjectStack" to true
set syncrate to 1
if the hilitedbuttonname of grp "display" is "Single Display" then -- User selects single display via radio button on another stack
put the first line of screenRects() into MyScreenSize
put item 1 of MyScreenSize into lt -- left edge
put item 2 of MyScreenSize into tp -- top edge
put item 3 of MyScreenSize into rt -- right edge
put item 4 of MyScreenSize into bt -- bottom edge
End if
if the hilitedbuttonname of grp "display" is "Dual Display" then
put the last line of screenRects() into MyScreenSize
put item 1 of MyScreenSize into lt
put item 2 of MyScreenSize into tp
put item 3 of MyScreenSize into rt
put item 4 of MyScreenSize into bt
End if
-- Move graphic diagonally from top left corner to bottom right corner of screen
move graphic "ball" on stack "MovingObjectStack" from lt,tp to rt,bt in spd milliseconds
beep
move graphic "ball" on stack "MovingObjectStack" from rt,bt to lt,tp in spd milliseconds
beep
set fullscreen of stack "untitled 3" to false
set syncrate to 20
-- Re-Center the object on stack
put the width of stack "MovingObjectStack" into x
put the height of stack "MovingObjectStack" into y
set the loc of graphic "ball" on stack "MovingObjectStack" to x div 2,y div 2
end mouseUp
on mouseUp
set fullscreen of stack "MovingObjectStack" to true
set syncrate to 1
if the hilitedbuttonname of grp "display" is "Single Display" then -- User selects single display via radio button on another stack
put the first line of screenRects() into MyScreenSize
put item 1 of MyScreenSize into lt -- left edge
put item 2 of MyScreenSize into tp -- top edge
put item 3 of MyScreenSize into rt -- right edge
put item 4 of MyScreenSize into bt -- bottom edge
End if
if the hilitedbuttonname of grp "display" is "Dual Display" then
put the last line of screenRects() into MyScreenSize
put item 1 of MyScreenSize into lt
put item 2 of MyScreenSize into tp
put item 3 of MyScreenSize into rt
put item 4 of MyScreenSize into bt
End if
-- Move graphic diagonally from top left corner to bottom right corner of screen
move graphic "ball" on stack "MovingObjectStack" from lt,tp to rt,bt in spd milliseconds
beep
move graphic "ball" on stack "MovingObjectStack" from rt,bt to lt,tp in spd milliseconds
beep
set fullscreen of stack "untitled 3" to false
set syncrate to 20
-- Re-Center the object on stack
put the width of stack "MovingObjectStack" into x
put the height of stack "MovingObjectStack" into y
set the loc of graphic "ball" on stack "MovingObjectStack" to x div 2,y div 2
end mouseUp
Re: Dual Display - Moving Objects
Hello xfratboy,
welcome to the forum.
I don't have two monitors so this is just a guess:
you move the objects relative to the card coordinates, not the screen coordinates as you do. This seems to work in your one monitor setup since your stack and consequently your card actually has the same dimensions as the screen coordinates when you use the fullscreen, actually you should not convert to local coordinates.
When it comes to two monitors the coordinates of the second are way off for your move. You could use the localloc funtion to determine the coordinate relative to your stack on the second monitor.
You probably could make a function in the stack of the second stack on the second monitor to return the local coordinates of the screen rect of the second monitor.
I just cant test this.
regards
Bernd
welcome to the forum.
I don't have two monitors so this is just a guess:
you move the objects relative to the card coordinates, not the screen coordinates as you do. This seems to work in your one monitor setup since your stack and consequently your card actually has the same dimensions as the screen coordinates when you use the fullscreen, actually you should not convert to local coordinates.
When it comes to two monitors the coordinates of the second are way off for your move. You could use the localloc funtion to determine the coordinate relative to your stack on the second monitor.
You probably could make a function in the stack of the second stack on the second monitor to return the local coordinates of the screen rect of the second monitor.
I just cant test this.
regards
Bernd
Re: Dual Display - Moving Objects
I guess I'm confused because I thought I had written a function to obtain the screen rect of the second monitor by parsing "the last line of screenrects()" :
Really I'm just looking for a way to open fullscreen in any display I choose, then bounce an object from side-to-side or diagonally. I just assumed I'd first need to get the screenrects but I'm hearing you say there's a better way
Code: Select all
if the hilitedbuttonname of grp "display" is "Dual Display" then
put the last line of screenRects() into MyScreenSize
put item 1 of MyScreenSize into lt
put item 2 of MyScreenSize into tp
put item 3 of MyScreenSize into rt
put item 4 of MyScreenSize into bt
End if
-- Move graphic diagonally from top left corner to bottom right corner of screen
move graphic "ball" on stack "MovingObjectStack" from lt,tp to rt,bt in spd milliseconds
beep
move graphic "ball" on stack "MovingObjectStack" from rt,bt to lt,tp in spd milliseconds
beep
Re: Dual Display - Moving Objects
Hello xfratboy,
lets do a little experiment:
make two stacks, standard size, give them any name, the first one has one field and one button, the second one can be just the stack.
Place both of the stacks on your first monitor distinctly apart from each other.
The button of the first stack has this script:
note for the localloc function (you might want to look that up in the dictionary) you have to have a point, just like you passed as a parameter to the move command.
Move the second stack on the first monitor around to get a feeling for the coordinates.
now you can move the second stack to the second monitor. You have to try this with the screenrect of the second monitor. Try those values if you command your second stack to move the objects.
As I said, I can not test this, you are a bit on your own here, but that seems to me a way to do this. Maybe someone with two monitors can help.
regards
Bernd
lets do a little experiment:
make two stacks, standard size, give them any name, the first one has one field and one button, the second one can be just the stack.
Place both of the stacks on your first monitor distinctly apart from each other.
The button of the first stack has this script:
Code: Select all
on mouseUp
put the screenrect into myScreenRect
put item 1 of myScreenRect & "," & item 2 of myScreenRect into tmyTopLeftScreen
put tmyTopLeftScreen into field 1
-- get coordinate from current (first) stack
put localLoc (tmyTopLeftScreen) into tmyLocalTopLeftScreen
put return & tmyLocalTopLeftScreen after field 1
push card -- remember this card before going to the other stack
-- go to the other stack
go stack "giveGlobalLocalCoordinates" -- change to the name of your second stack
-- now the other stack is the current stack
-- and get the localLoc relative to the other stack
put localLoc (tmyTopLeftScreen) into tmyLocalTopLeftScreen
pop card -- go back to the remembered card
-- now we are back and can put our variable into field 1
put return & tmyLocalTopLeftScreen after field 1
end mouseUp
Move the second stack on the first monitor around to get a feeling for the coordinates.
now you can move the second stack to the second monitor. You have to try this with the screenrect of the second monitor. Try those values if you command your second stack to move the objects.
As I said, I can not test this, you are a bit on your own here, but that seems to me a way to do this. Maybe someone with two monitors can help.
regards
Bernd
Re: Dual Display - Moving Objects
Thanks bn, I'll try and assimilate this information. I think I understand what you're saying. Not being a programmer I have to chew on things for a while before I understand what is going on. Basically, what I think you're saying is that I don't base my coordinates on the physical coordinates of the display but instead on the coordinates of the stack (or cards) in relation to each other. Wish I would have paid closer attention in 8th grade to geometry.
Here's what I got to work. I can now get object to move correctly on either screen. Your post was the trick. Since it's working I guess this is one way to do what I'm trying to do:
Here's what I got to work. I can now get object to move correctly on either screen. Your post was the trick. Since it's working I guess this is one way to do what I'm trying to do:
Code: Select all
on mouseUp
push card -- remember this card before going to the other stack
-- go to the other stack
go stack "untitled 2" -- change to the name of your second stack
-- now the other stack is the current stack
-- and get the localLoc relative to the other stack
set the fullscreen of this stack to true
put the rect of this stack into myScreenRect
put item 1 of myScreenRect & "," & item 2 of myScreenRect into tmyTopLeftScreen
put item 3 of myScreenRect & "," & item 4 of myScreenRect into tmyBottomRightScreen
put item 1 of myScreenRect &"," & item 4 of myScreenRect into tmyBottomLeftScreen
put item 3 of myScreenRect &"," & item 2 of myScreenRect into tmyTopRightScreen
put height of this stack div 2 into myMidPoint
put item 1 of myScreenRect & "," & MyMidPoint into tmyMidLeftScreen
Put item 3 of myScreenRect & "," & MyMidPoint into tmyMidRightScreen
put localLoc (tmyTopLeftScreen) into tmyLocalTopLeftScreen
put localLoc(tmyBottomRightScreen) into tmyLocalBottomRightScreen
put localloc(tmyBottomLeftScreen) into tmyLocalBottomLeftScreen
put localloc(tmyTopRightScreen) into tmyLocalTopRightScreen
put localloc(tmyMidLeftScreen) into tmyLocalLeftMidScreen
put localloc(tmyMidRightScreen) into tmyLocalRightMidScreen
-- Now move the ball around to the points
move graphic oval from tmyLocalTopLeftScreen to tmyLocalBottomRightScreen in 1 seconds
move graphic oval from tmyLocalBottomRightScreen to tmyLocalTopLeftScreen in 1 seconds
move graphic oval from tmyLocalBottomLeftScreen to tmyLocalTopRightScreen in 1 seconds
move graphic oval from tmyLocalTopRightScreen to tmyLocalBottomLeftScreen in 1 seconds
move graphic oval from tmyLocalLeftMidScreen to tmyLocalRightMidScreen in 1 seconds
move graphic oval from tmyLocalRightMidScreen to tmyLocalLeftMidScreen in 1 seconds
-- Set Stack back to normal size and return
set the fullscreen of this stack to false
pop card -- go back to the remembered card
end mouseUp
Last edited by xfratboy on Sat Mar 06, 2010 8:50 pm, edited 1 time in total.
Re: Dual Display - Moving Objects
xfratboy,
it is not really geometry.
Your coordinates in a stack are all relative to the topleft of the stack window which is a card, this is 0,0. The first 0 being the horizontal zero and the second the vertical zero. The bottomright of the card window is the horizontal 0 + the width of the card, plust the top zero + the height of the card. This gives you the coordinates for a card of the width of 640 and the height of 480 a bottomright of 640,480
The rect of that card is 0,0,640,480. In a rect the first number is "left", the second "top", the third "right" and the fourth "bottom". (which you can actually get from rev, on object has these properties.
You think with your moves in local coordinates which are the card coordinates.
Usually around the stack is some more screen realestate, so that why you get the stack rect in absolute = screen coordinates. So if you set the loc of a stack you set it in absolute coordinates, that is where screenrects are needed. When you set the loc of an object on a card, you set that in the coordinates of the card.
What I would try in your place now, coming to think of it is, try to move the object on your second stack relative to the card. That means make another experiment and set the second stack to the fullscreen.
Then move something from 0,0 to the width of this card, the height of this card. It should move across the screen.
That should work, since the movements should be relative to the card and not to absolute coordinates.
I just can not try this.
regards
Bernd
it is not really geometry.
Your coordinates in a stack are all relative to the topleft of the stack window which is a card, this is 0,0. The first 0 being the horizontal zero and the second the vertical zero. The bottomright of the card window is the horizontal 0 + the width of the card, plust the top zero + the height of the card. This gives you the coordinates for a card of the width of 640 and the height of 480 a bottomright of 640,480
The rect of that card is 0,0,640,480. In a rect the first number is "left", the second "top", the third "right" and the fourth "bottom". (which you can actually get from rev, on object has these properties.
You think with your moves in local coordinates which are the card coordinates.
Usually around the stack is some more screen realestate, so that why you get the stack rect in absolute = screen coordinates. So if you set the loc of a stack you set it in absolute coordinates, that is where screenrects are needed. When you set the loc of an object on a card, you set that in the coordinates of the card.
What I would try in your place now, coming to think of it is, try to move the object on your second stack relative to the card. That means make another experiment and set the second stack to the fullscreen.
Then move something from 0,0 to the width of this card, the height of this card. It should move across the screen.
That should work, since the movements should be relative to the card and not to absolute coordinates.
I just can not try this.
regards
Bernd
Re: Dual Display - Moving Objects
Here's what I got to work. I can now get object to move correctly on either screen. Your post was the trick. Since it's working I guess this is one way to do what I'm trying to do:
Code: Select all
on mouseUp
push card -- remember this card before going to the other stack
-- go to the other stack
go stack "untitled 2" -- change to the name of your second stack
-- now the other stack is the current stack
-- and get the localLoc relative to the other stack
set the fullscreen of this stack to true
put the rect of this stack into myScreenRect
put item 1 of myScreenRect & "," & item 2 of myScreenRect into tmyTopLeftScreen
put item 3 of myScreenRect & "," & item 4 of myScreenRect into tmyBottomRightScreen
put item 1 of myScreenRect &"," & item 4 of myScreenRect into tmyBottomLeftScreen
put item 3 of myScreenRect &"," & item 2 of myScreenRect into tmyTopRightScreen
put height of this stack div 2 into myMidPoint
put item 1 of myScreenRect & "," & MyMidPoint into tmyMidLeftScreen
Put item 3 of myScreenRect & "," & MyMidPoint into tmyMidRightScreen
put localLoc (tmyTopLeftScreen) into tmyLocalTopLeftScreen
put localLoc(tmyBottomRightScreen) into tmyLocalBottomRightScreen
put localloc(tmyBottomLeftScreen) into tmyLocalBottomLeftScreen
put localloc(tmyTopRightScreen) into tmyLocalTopRightScreen
put localloc(tmyMidLeftScreen) into tmyLocalLeftMidScreen
put localloc(tmyMidRightScreen) into tmyLocalRightMidScreen
-- Now move the ball around to the points
move graphic oval from tmyLocalTopLeftScreen to tmyLocalBottomRightScreen in 1 seconds
move graphic oval from tmyLocalBottomRightScreen to tmyLocalTopLeftScreen in 1 seconds
move graphic oval from tmyLocalBottomLeftScreen to tmyLocalTopRightScreen in 1 seconds
move graphic oval from tmyLocalTopRightScreen to tmyLocalBottomLeftScreen in 1 seconds
move graphic oval from tmyLocalLeftMidScreen to tmyLocalRightMidScreen in 1 seconds
move graphic oval from tmyLocalRightMidScreen to tmyLocalLeftMidScreen in 1 seconds
-- Set Stack back to normal size and return
set the fullscreen of this stack to false
pop card -- go back to the remembered card
end mouseUp
Re: Dual Display - Moving Objects
xfratboy,
try this, it is in local coordinate relative to the card. If it works as before it is a lot easier to script.
I filled your variables a little differently, but they are just the same, everything should move along the same trajectories as before.
regards
Bernd
try this, it is in local coordinate relative to the card. If it works as before it is a lot easier to script.
I filled your variables a little differently, but they are just the same, everything should move along the same trajectories as before.
Code: Select all
on mouseUp
push card -- remember this card before going to the other stack
-- go to the other stack
go stack "untitled 2" -- change to the name of your second stack
-- now the other stack is the current stack
-- and get the localLoc relative to the other stack
set the fullscreen of this stack to true
-- Now move the ball around to the points
-- try this relative to the card
put the width of this card into tWidth
put the height of this card into tHeight
put tWidth / 2 into tHorizontalMiddle
put tHeight / 2 into tVerticalMiddle
put 0,0 into tmyLocalTopLeftScreen
put tWidth & "," & tHeight into tmyLocalBottomRightScreen
put tWidth & "," & 0 into tmyLocalTopRightScreen
put 0 & "," & tHeight into tmyLocalBottomLeftScreen
put 0 & "," & tVerticalMiddle into tmyLocalLeftMidScreen
put tWidth & "," & tVerticalMiddle into tmyLocalRightMidScreen
move graphic oval from tmyLocalTopLeftScreen to tmyLocalBottomRightScreen in 1 seconds
move graphic oval from tmyLocalBottomRightScreen to tmyLocalTopLeftScreen in 1 seconds
move graphic oval from tmyLocalBottomLeftScreen to tmyLocalTopRightScreen in 1 seconds
move graphic oval from tmyLocalTopRightScreen to tmyLocalBottomLeftScreen in 1 seconds
move graphic oval from tmyLocalLeftMidScreen to tmyLocalRightMidScreen in 1 seconds
move graphic oval from tmyLocalRightMidScreen to tmyLocalLeftMidScreen in 1 seconds
-- Set Stack back to normal size and return
set the fullscreen of this stack to false
pop card -- go back to the remembered card
end mouseUp
Bernd
Re: Dual Display - Moving Objects
Works great! Thanks for walking me through this. This has been a fun process of learning. Now if I can just find a way to play audio. My next task in this assignment is to make the right channel/speaker sound when ball hits right wall and left channel on Left wall. I've not been able to find anything in the dictionary that explicitly does this so I figure I have to make something. Probably best to start a new topic though. However, one idea is to load two files created with only left or right audio channels and that would probably work (just not as elegant).
Re: Dual Display - Moving Objects
xfratboy,
Glad you liked the 'walkthrough' though I have to admit that at first I made it more complicated then it is. I got thrown off by the idea that you wanted to move something off the card on a second monitor. Once I realized you were staying on the card it was a lot easier.
Anyway it is useful to know how Rev defines its boundaries.
regards
Bernd
I think this is as elegant as it gets. I don't know of any way to address the right/left speaker from within Rev.xfratboy wrote:However, one idea is to load two files created with only left or right audio channels and that would probably work (just not as elegant).
Glad you liked the 'walkthrough' though I have to admit that at first I made it more complicated then it is. I got thrown off by the idea that you wanted to move something off the card on a second monitor. Once I realized you were staying on the card it was a lot easier.
Anyway it is useful to know how Rev defines its boundaries.
regards
Bernd
Re: Dual Display - Moving Objects
One more thing I've run into is stopping the movement. I've added a control to set the number of cycles the ball bounces around the screen. I'm wondering how/where to program a stop command. So, for example when a user hits the escape key it causes everything to stop. I've been able to get the stack to respond to the escape key but the REPEAT doesn't stop
Tried this but it didn't work (gives me an error):
Code: Select all
Repeat gMyRepetitions times
move graphic oval from tmyLocalTopLeftScreen to tmyLocalBottomRightScreen in 1 seconds
move graphic oval from tmyLocalBottomRightScreen to tmyLocalTopLeftScreen in 1 seconds
move graphic oval from tmyLocalBottomLeftScreen to tmyLocalTopRightScreen in 1 seconds
move graphic oval from tmyLocalTopRightScreen to tmyLocalBottomLeftScreen in 1 seconds
move graphic oval from tmyLocalLeftMidScreen to tmyLocalRightMidScreen in 1 seconds
move graphic oval from tmyLocalRightMidScreen to tmyLocalLeftMidScreen in 1 seconds
End Repeat
Code: Select all
Repeat gMyRepetitions times
if escapeKey is down then
exit repeat
end If
move graphic oval from tmyLocalTopLeftScreen to tmyLocalBottomRightScreen in 1 seconds
move graphic oval from tmyLocalBottomRightScreen to tmyLocalTopLeftScreen in 1 seconds
move graphic oval from tmyLocalBottomLeftScreen to tmyLocalTopRightScreen in 1 seconds
move graphic oval from tmyLocalTopRightScreen to tmyLocalBottomLeftScreen in 1 seconds
move graphic oval from tmyLocalLeftMidScreen to tmyLocalRightMidScreen in 1 seconds
move graphic oval from tmyLocalRightMidScreen to tmyLocalLeftMidScreen in 1 seconds
End Repeat
Re: Dual Display - Moving Objects
Hi xfratboy,
a repeat loop is very tight and gives the engine not room enough to respond to other events. If you add a wait 2 milliseconds with messages at the end of the repeat loop it should work. This gives the engine room to breathe, it can respond to other events.you should be able to abort the script with comand period or escape key
tell us how it works
regards
Bernd
a repeat loop is very tight and gives the engine not room enough to respond to other events. If you add a wait 2 milliseconds with messages at the end of the repeat loop it should work. This gives the engine room to breathe, it can respond to other events.
Code: Select all
Repeat gMyRepetitions times
move graphic oval from tmyLocalTopLeftScreen to tmyLocalBottomRightScreen in 1 seconds
move graphic oval from tmyLocalBottomRightScreen to tmyLocalTopLeftScreen in 1 seconds
move graphic oval from tmyLocalBottomLeftScreen to tmyLocalTopRightScreen in 1 seconds
move graphic oval from tmyLocalTopRightScreen to tmyLocalBottomLeftScreen in 1 seconds
move graphic oval from tmyLocalLeftMidScreen to tmyLocalRightMidScreen in 1 seconds
move graphic oval from tmyLocalRightMidScreen to tmyLocalLeftMidScreen in 1 seconds
wait 2 milliseconds with messages
End Repeat
tell us how it works
regards
Bernd
Re: Dual Display - Moving Objects
I might mention the construction:
... I think this needs to be:
... or altKey (equiv. optionKey), controlKey or commandKey. I wonder if this is also a problem?
Regards,
Michael
Code: Select all
if escapeKey is down then
exit repeat
end If
Code: Select all
if the shiftKey is down then
exit repeat
end If
Regards,
Michael