This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2012-09-04 19:29:16

Firedrake969
Scratcher
Registered: 2011-11-24
Posts: 1000+

Hmmm...

How do I make draggable windows?  I am making a "pong" app with an "X" button, so how do I make it draggable?


Click the sign.
https://s3.amazonaws.com/eterna/eterna2/logo2.png

Offline

 

#2 2012-09-04 19:43:49

amcerbu
Scratcher
Registered: 2009-07-21
Posts: 500+

Re: Hmmm...

First of all, if you have window contents that are supposed to move, you have to assign each one of them (every sprite) variables for their positions relative to the window.  I would use the window top right-hand corner as (0,0).  When you modify the window's position - by dragging it - the contents of the window adjust their actual x and y positions based on the position of the top-right corner (which is stored in a pair of variables) and their own relative positions.  Here's an example.

when gf clicked // for every window entity
forever
go to x: ((windowX) + (offsetX)) y: ((windowY) + (offsetY))
end

when gf clicked // in main control sprite
forever
adjust value of windowX and windowY based on mouse input.  
end
Instead of adjusting the values of a window entity's position directly, you modify its offsetX and offsetY values.  This corrects its position inside the window.

Last edited by amcerbu (2012-09-04 19:44:49)

Offline

 

#3 2012-09-04 19:45:18

Firedrake969
Scratcher
Registered: 2011-11-24
Posts: 1000+

Re: Hmmm...

amcerbu wrote:

First of all, if you have window contents that are supposed to move, you have to assign each one of them (every sprite) variables for their positions relative to the window.  I would use the window top right-hand corner as (0,0).  When you modify the window's position - by dragging it - the contents of the window adjust their actual x and y positions based on the position of the top-right corner (which is stored in a pair of variables) and their own relative positions.  Here's an example.

when gf clicked // for every window entity
forever
go to x: ((windowX) + (offsetX)) y: ((windowY) + (offsetY))
end

when gf clicked // in main control sprite
forever
adjust value of windowX and windowY based on mouse input.  
end
Instead of adjusting the values of a window entity's position directly, you modify its offsetX and offsetY values.  This corrects its position inside the window.

What do you mean by "adjust value of blah blah blah"?  Can you write out the script?


Click the sign.
https://s3.amazonaws.com/eterna/eterna2/logo2.png

Offline

 

#4 2012-09-04 20:16:25

amcerbu
Scratcher
Registered: 2009-07-21
Posts: 500+

Re: Hmmm...

This goes in the sprite that is the drag-able part of the window (i.e. the top part, or whatever you think should it should be). 

windowX and windowY are the coordinates on the screen of the top left-hand corner of the window (that should be the costume center of the drag-able sprite). 

forever
if<<<mouse down?> and <(mouseDownBefore) = [false]>> and <touching [mouse pointer v]?>>
set [mouseXOffset v] to ((windowX) - (mouse x))
set [mouseYOffset v] to ((windowY) - (mouse y))
set [mouseDownBefore v] to [true]
set [dragging? v] to [true]
end
if<<mouse down?> and <not<touching [mouse pointer v]?>>>
set [mouseDownBefore v] to [true]
end
if<(dragging?) = [true]>
set [windowX v] to ((mouseXOffset) + (mouse x))
set [windowY v] to ((mouseYOffset) + (mouse y))
end
if<not<mouse down?>>
set [mouseDownBefore v] to [false]
set [dragging? v] to [false]
end
end

Last edited by amcerbu (2012-09-04 20:18:35)

Offline

 

#5 2012-09-04 20:22:27

MoreGamesNow
Scratcher
Registered: 2009-10-12
Posts: 1000+

Re: Hmmm...

You could just click the "lock" by the sprite (or use the workaround) (see this wiki article

Edit: after, of course, as mentioned above, making all the sprites within the window's position relative to the window.

Last edited by MoreGamesNow (2012-09-04 20:22:57)


http://images2.layoutsparks.com/1/218929/rubiks-cube-animated-rotating.gif
"Cogito ergo sum" --  I think, therefore I am

Offline

 

#6 2012-09-04 22:38:17

amcerbu
Scratcher
Registered: 2009-07-21
Posts: 500+

Re: Hmmm...

^^ The problem with that is that when using the built-in drag feature in Scratch, positions don't update until after you've released the sprite.  So window contents would appear to jump from their original position to the new one.  What I posted is basically just a dragging workaround.

Offline

 

#7 2012-09-05 16:16:17

amcerbu
Scratcher
Registered: 2009-07-21
Posts: 500+

Re: Hmmm...

@Firedrake969, is that what you wanted?

Offline

 

#8 2012-09-05 16:19:01

MoreGamesNow
Scratcher
Registered: 2009-10-12
Posts: 1000+

Re: Hmmm...

amcerbu wrote:

^^ The problem with that is that when using the built-in drag feature in Scratch, positions don't update until after you've released the sprite.  So window contents would appear to jump from their original position to the new one.  What I posted is basically just a dragging workaround.

Ahhh, I didn't know that. I usually just use a workaround to give myself greater control.


http://images2.layoutsparks.com/1/218929/rubiks-cube-animated-rotating.gif
"Cogito ergo sum" --  I think, therefore I am

Offline

 

#9 2012-09-05 20:07:02

Firedrake969
Scratcher
Registered: 2011-11-24
Posts: 1000+

Re: Hmmm...

amcerbu wrote:

@Firedrake969, is that what you wanted?

Yep.

Last edited by Firedrake969 (2012-09-05 20:07:11)


Click the sign.
https://s3.amazonaws.com/eterna/eterna2/logo2.png

Offline

 

#10 2012-09-05 20:56:46

bertdog
Scratcher
Registered: 2012-06-12
Posts: 100+

Re: Hmmm...

you could just do this

when gf clicked
if <mouse down>
go to [mouse pointer]


"Losers quit when they are tired,Winners quit when they are done." smile http://blocks.scratchr.org/API.php?user=bertdog&amp;action=onlineStatus

Offline

 

#11 2012-09-05 21:12:33

jji7skyline
Scratcher
Registered: 2010-03-08
Posts: 1000+

Re: Hmmm...

That would centre the window on the mouse though.


I don't know why you say goodbye, I say hello!  big_smile

Offline

 

#12 2012-09-07 12:02:34

firedrake969_test
Scratcher
Registered: 2012-08-08
Posts: 500+

Re: Hmmm...

Firedrake969 wrote:

amcerbu wrote:

@Firedrake969, is that what you wanted?

Yep.

Just thinking though, I want to be able to have a couple windows open at a time.  Is that possible w/ this script?


Alt of Firedrake969.

Offline

 

#13 2012-09-07 16:21:56

amcerbu
Scratcher
Registered: 2009-07-21
Posts: 500+

Re: Hmmm...

The easiest way I could think of would be to create a bunch of lists instead of those variables for window position, etc.  Check out this Wikipedia article and I'll help you if you have other questions.

Offline

 

#14 2012-09-07 16:42:16

northmeister
Scratcher
Registered: 2011-07-12
Posts: 1000+

Re: Hmmm...

I used this:

when gf clicked
forever
set x to ((x pos of window v)+(offsety))
set y to ((y pos of window v)+(offsetx))
end
on the red cross and any sprites on the window, and on the window I just made the sprite draggable.

You can always look at my scripts on North OS too though  smile

Last edited by northmeister (2012-09-07 17:39:34)


http://i48.tinypic.com/5a25g5.png

Offline

 

#15 2012-09-15 10:26:57

Firedrake969
Scratcher
Registered: 2011-11-24
Posts: 1000+

Re: Hmmm...

amcerbu wrote:

A bunch of scratchblocks

Should I set the variables as anything prior to this script?


Click the sign.
https://s3.amazonaws.com/eterna/eterna2/logo2.png

Offline

 

#16 2012-09-15 15:37:35

amcerbu
Scratcher
Registered: 2009-07-21
Posts: 500+

Re: Hmmm...

Set dragging to false.
Set mouseDownBefore to false.
Set windowX and windowY to the coordinates of the top-left-hand corner of the window. 

That should do it.

Offline

 

#17 2012-09-15 15:50:45

Molybdenum
Scratcher
Registered: 2012-06-17
Posts: 1000+

Re: Hmmm...

bertdog wrote:

you could just do this

when gf clicked
if <mouse down>
go to [mouse pointer]

This is the most annoying thing I have seen in an OS.


"The Enrichment Center is required to remind you that you will be baked, and then there will be cake."
(|Balls and Platforms: Stay on!|) (|NaOS-H: An operating system... Or is it?|)

Offline

 

#18 2012-09-15 15:53:46

BirdByte
Scratcher
Registered: 2012-07-07
Posts: 1000+

Re: Hmmm...

amcerbu stole the script right outta my noggin. XP


http://i50.tinypic.com/312u714.jpg

Offline

 

#19 2012-09-15 15:56:38

northmeister
Scratcher
Registered: 2011-07-12
Posts: 1000+

Re: Hmmm...

Put this on the cross sprite.

northmeister wrote:

when gf clicked
forever
set x to ((x pos of window v)+(offsety))
set y to ((y pos of window v)+(offsetx))
end

And change the window sprite from undraggable to draggable. That works perfectly  smile


http://i48.tinypic.com/5a25g5.png

Offline

 

#20 2012-09-15 17:42:14

MoreGamesNow
Scratcher
Registered: 2009-10-12
Posts: 1000+

Re: Hmmm...

BirdByte wrote:

amcerbu stole the script right outta my noggin. XP

yikes  run for the tinfoil hats!!


http://images2.layoutsparks.com/1/218929/rubiks-cube-animated-rotating.gif
"Cogito ergo sum" --  I think, therefore I am

Offline

 

#21 2012-09-15 20:03:10

amcerbu
Scratcher
Registered: 2009-07-21
Posts: 500+

Re: Hmmm...

@BirdByte: Haha  big_smile

@northmeister: Yeah, but the window contents won't move in realtime.  When you drag a sprite using Scratch's built-in system, it only registers its position change after you've let go of the mouse.  Unless the entire window is one sprite (with multiple costumes, for example), it would appear to jump from one place to the next.  I assume that Firedrake969 wants to have multiple sprites take part in each window, since he mentioned a pong game earlier.

Last edited by amcerbu (2012-09-15 20:03:21)

Offline

 

#22 2012-09-15 22:01:51

AgentRoopAssistant
Scratcher
Registered: 2012-04-06
Posts: 5

Re: Hmmm...

wow u smart

Offline

 

#23 2012-09-20 19:46:09

Firedrake969
Scratcher
Registered: 2011-11-24
Posts: 1000+

Re: Hmmm...

This still won't work.


Click the sign.
https://s3.amazonaws.com/eterna/eterna2/logo2.png

Offline

 

#24 2012-09-20 19:58:41

amcerbu
Scratcher
Registered: 2009-07-21
Posts: 500+

Re: Hmmm...

What do you mean?  What's the problem you're having?

Offline

 

#25 2012-09-20 21:30:18

Firedrake969
Scratcher
Registered: 2011-11-24
Posts: 1000+

Re: Hmmm...

amcerbu wrote:

What do you mean?  What's the problem you're having?

I try to drag it and it disappears.  What I really want is just being draggable w/o the unlock.


Click the sign.
https://s3.amazonaws.com/eterna/eterna2/logo2.png

Offline

 

Board footer