Page 1 of 2

Making Buttons Solid

Posted: Wed Mar 21, 2012 10:05 pm
by d.m.holdawayGA2553
hello,

i have been researching " Intersect " and the use of layers in this but i am still drawing blanks.

i have a number of buttons on the screen which move about but they can move over each other, what i would to try and do is make them solid so you cant move them over each other.

does that make sense.

i would rather be told what to go and read and work it with out trial and error than someone post the answer.

Re: Making Buttons Solid

Posted: Wed Mar 21, 2012 11:45 pm
by dunbarx
Your buttons already move over each other, right? Did you mean "so you CAN'T move them over each other"?

If so, please write back. There are easy ways to do this. How do your button move now?

Craig Newman

Re: Making Buttons Solid

Posted: Wed Mar 21, 2012 11:47 pm
by d.m.holdawayGA2553
yes Craig thats what i ment, i am really sorry for getting that mixed up i have corrected the post.

Re: Making Buttons Solid

Posted: Wed Mar 21, 2012 11:53 pm
by d.m.holdawayGA2553
I move them with

on touchMove pId, pX, pY
if the cType of the target is "shape" and sMoving is true then
set the loc of the target to pX, pY
end if
end touchMove

Re: Making Buttons Solid

Posted: Thu Mar 22, 2012 12:12 am
by d.m.holdawayGA2553
i have just found a good example

http://revonline2.runrev.com/stack/281/ ... ic-Control

i will have a look at this.

Re: Making Buttons Solid

Posted: Thu Mar 22, 2012 2:35 am
by dunbarx
Thought so. Anyway, you don't make the movng objects "solid". Rather you control them; herd them like sheep. Make them do your bidding.

Try this: on a card place three buttons. Name one "starter". Name another "mover". Name the third "theTarget". Place the btn "mover" far to the left of btn "theTarget", but on the same horizontal line. Put this in the script of btn "starter":

Code: Select all

on mouseUp
   put the loc of btn "mover" into startLoc
   repeat until intersect(btn "mover",btn "tTarget") = "true"
      get the loc of btn "mover" 
      set the loc of btn "mover" to item 1 of it + 1 & "," & item 2 of it
      wait 2
   end repeat
      set the loc of btn "mover" to startLoc
end mouseUp
Please try to understand what each line does. This is homework. Experiment and play around. Can you change the speed in more than one way? The starting position? Does it matter where you place the button "starter"? Can it be between the other two?

The example above is just a bit verbose, for readability. Can you shorten it?.

Write back with the completed homework.

Craig Newman

Re: Making Buttons Solid

Posted: Thu Mar 22, 2012 3:56 am
by Dixie
Yes Sir, Mr Newman... Where should I put your apple ?... :D

Re: Making Buttons Solid

Posted: Thu Mar 22, 2012 5:48 am
by dunbarx
Dixie.

In The Marx Brothers movie "Horse Feathers", Harpo gives the professor a watermelon.

Soon after, that professor was thrown out of his own classroom.

Craig

Re: Making Buttons Solid

Posted: Thu Mar 22, 2012 10:44 am
by d.m.holdawayGA2553
ok.

well

Code: Select all

put the loc of btn "mover" into startLoc
takes the current location of the button "mover" and puts it into a variable

Code: Select all

repeat until intersect(btn "mover",btn "theTarget") = "true"
      get the loc of btn "mover" 
      set the loc of btn "mover" to item 1 of it + 1 & "," & item 2 of it
      wait 2
this code makes the button mover move until it hits the target, but i am unsure about this line

Code: Select all

 set the loc of btn "mover" to item 1 of it + 1 & "," & item 2 of it
its doing the moving part but i dont understand

Code: Select all

to item 1 of it + 1 & "," & item 2 of it

Code: Select all

wait 2 
is the time it takes for mover to hit theTarget

then upon hitting it, its breaks the loop and sets the mover button back to the location

Re: Making Buttons Solid

Posted: Thu Mar 22, 2012 11:34 am
by dave_probertGA6e24
Just for reference:
a 'loc' variable consists of two components - x and y position - eg. "100,200"

Using the 'get' command will get the value of a variable/function/whatever and put the result into a special variable named 'it' (see the dictionary for more info on this)

Using 'chunk' access notation ( 'item 1') the various parts of the loc (inside the 'it' variable) can be used - item 1 of it would return '100' from the loc example above - item 2 returns '200'!

To set the loc of something you need to provide both the x and y - comma separated text - "444,555".

So the line:
set the loc of btn "mover" to item 1 of it + 1 & "," & item 2 of it

basically creates a new 'loc' from the old loc by breaking it down into it's component parts, adding a value to the 'x' part (item 1) and reconstructing a new loc from those modified parts.

Wow, that is a long an laborious way of explaining this :) :) But I hope it helps someone.

Dave

Re: Making Buttons Solid

Posted: Thu Mar 22, 2012 11:45 am
by d.m.holdawayGA2553
no thats really good!

so if i was to say

Code: Select all

set the loc of btn "mover" to item 1 of it + 1 & "," & item 2 of it + 1 
it would move diagonal

that would make the loc 1,1

so if i wanted to move it quicker i could just change item 1 and item 2

Code: Select all

set the loc of btn "mover" to item 1 of it + 10 & "," & item 2 of it + 10 

Re: Making Buttons Solid

Posted: Thu Mar 22, 2012 5:47 pm
by dunbarx
YES! You are on your way. Congrats.

And yes, again, two ways of changing the rate are to modify the "wait" duration or to increase the offset of the loc parameters. There are even others.

I might have been more helpful with that one line if I wrote:

set the loc of btn "mover" to (item 1 of it + 1) & "," & (item 2 of it) --better readability

How about making the "mover" button bounce around the card at random til it hits the target? If you can do this you should have most of the mental tools you need for your game. A word of warning: be careful that you limit the playing field to the rect of the card or your button will disappear off an edge. You may want to make a button that manually relocates it if it gets lost. Do you know how to terminate a running script? (command-period)

Good luck, play all day, write back.

Craig Newman

Re: Making Buttons Solid

Posted: Fri Mar 23, 2012 12:17 am
by d.m.holdawayGA2553
cool i like this!

what if my buttons are in a group, how would i use intersect then?

thanks for the command-period heads up

that is most helpful!

thanks again for the advice and the tips

Re: Making Buttons Solid

Posted: Fri Mar 23, 2012 2:34 am
by dunbarx
Keep going.

Intersect will use the overall extent of the group, regardless of the locations of its component objects, and use that as the basis for returning a value. Try it. Make a group with two objects located diagonally. The group will be a rectangle.

Where is that random game? An exercise like this will advance your learning dramatically.

Craig Newman

Re: Making Buttons Solid

Posted: Fri Mar 23, 2012 4:34 pm
by d.m.holdawayGA2553
i have started on the random bouncing homework.

but could you explain
Intersect will use the overall extent of the group
i am not sure what you ment by that.