Using x loc, y loc to position a graphic

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
bjb007
Posts: 313
Joined: Fri Dec 28, 2007 4:56 am

Using x loc, y loc to position a graphic

Post by bjb007 » Sun Jun 29, 2008 5:23 pm

I want to position a graphic relative to
another object and have tried to use the
x loc, y loc to do this. I've tried all the
permutations I can think of without success.

Any suggestions appreciated.
Life is just a bowl of cherries.

malte
Posts: 1098
Joined: Thu Feb 23, 2006 8:34 pm
Contact:

Post by malte » Sun Jun 29, 2008 9:05 pm

You get the location of an object in a comma seperated string. No way to set the xloc or y loc seperately I am aware of.

local tX,tY

put item 1 of control "myControl" into tX
put item 2 of control "myControl" into tY

set the loc of control "myOtherControl" to tX+10,tY+10

Hope that snippet gets you started,

Malte

bjb007
Posts: 313
Joined: Fri Dec 28, 2007 4:56 am

Using x loc, y loc to position a graphic

Post by bjb007 » Sun Jun 29, 2008 11:06 pm

Malte

Thanks for that.

Now I'm going to take advantage of
your expertise in all things graphical.

I want to move an image from, say 50, 50 to
100,100 but I want it to go only vertically and
horizontally rather than taking the direct route.
Well, it doesn't have to worry about mpg!

So it has to go to 50,100 then to 100,100.

Is there a neat way to do this?
Life is just a bowl of cherries.

gyroscope
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 404
Joined: Tue Jan 08, 2008 3:44 pm
Contact:

Post by gyroscope » Sun Jun 29, 2008 11:34 pm

Hi bjb007, one relatively straightforward way would be:

Code: Select all

on mouseUp pMouseBtnNo
    move image "XYZ" to 50,100 in 20 ticks
    wait 5 ticks
     move image "XYZ" to 100,100 in 20 ticks
end mouseUp
Hope that's the sort of thing you're after...

:)

PS I'm glad to see you're not grumpy anymore, bjb007!! :wink: :lol:

bjb007
Posts: 313
Joined: Fri Dec 28, 2007 4:56 am

Post by bjb007 » Sun Jun 29, 2008 11:51 pm

gyroscope

The locations will come from the script
and vary for a number of items so I really
need a programmable way to get the result
I want.

I haven't tried to programme it yet as I've spent
half the night trying to sort the array to get the
right graphic going to the right location - see my
post.

Expect after some zzzzz I'll feel able to figure it
out but I get confused by the negative movements.

Way back -- 1974 -- I had the interesting task of
calculating the centre of gravity of some walk-ways
on a North Sea oil production platform. No computers
then, just mechancial calculators.

So the thing which made it much easier was to
set the 0,0 not at the centre of the platform but
some way off out in the North Sea. That way all
distances were positive.

Edit:
So now I'm wondering if it would be possible
to put an object somewhere off-stack and use
relative positions so that they're all positive numbers.
Last edited by bjb007 on Mon Jun 30, 2008 2:46 am, edited 1 time in total.
Life is just a bowl of cherries.

gyroscope
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 404
Joined: Tue Jan 08, 2008 3:44 pm
Contact:

Post by gyroscope » Mon Jun 30, 2008 12:16 am

set up globals, put your positions in these, perhaps? i.e.

Code: Select all

global gLocA, gLocB, gLocC, gLocD

---these have values put into them from other handlers, perhaps
on mouseUp
  move image "XYZ" to gLocA,gLocB in 20 ticks 
    wait 5 ticks 
     move image "XYZ" to gLocC,gLocD in 20 ticks 
end mouseUp
I had the interesting task of
calculating the centre of gravity of some walk-ways
on a North Sea oil production platform.
Sheesh, I wouldn't know where to start there...!

:)

bjb007
Posts: 313
Joined: Fri Dec 28, 2007 4:56 am

Using x loc, y loc to position a graphic

Post by bjb007 » Mon Jun 30, 2008 2:12 am

Malte, gyroscope and all Revvers.

I've uploaded my test stack to RevOnline

User bjb007.

Stack: Finder v0.1
Life is just a bowl of cherries.

LESTROSO
Posts: 85
Joined: Wed Apr 04, 2007 6:14 pm
Contact:

Re: Using x loc, y loc to position a graphic

Post by LESTROSO » Sun Nov 07, 2010 6:24 am

Hy to Everybody, Lestroso Here,

I want just to share a trick that i have done with revolution, now Livecode...about to get the xloc and the yloc , in order to set a location of an object, so how to get the real position of an object in very few line of codes.

Here this example that really works....


Code: Select all

 
global tX,tY

on mouseUp
 
put the item 1 of the loc of button id 1006 into tX
put the item 2 of the loc of button id 1006 into tY
put tx &cr& ty into field "risultato"---put the risult into a field called "risultato" to see the numbers variables

end mouseUp


Cheers!!eheheh

Lestroso :D

http://www.fasasoftware.com

Dixie
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1336
Joined: Sun Jul 12, 2009 10:53 am

Re: Using x loc, y loc to position a graphic

Post by Dixie » Sun Nov 07, 2010 6:40 am

lestroso...

What would be wrong with just... ?

Code: Select all

on mouseUp
   put the loc of me
end mouseUp
be well

Dixie

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: Using x loc, y loc to position a graphic

Post by Mark » Sun Nov 07, 2010 11:26 am

Or... to get the same result as Lestroso:
on mouseUp
put replaceText(the loc of the target,comma,cr) into fld "Risultato"
end mouseUp
Best,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

Dixie
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1336
Joined: Sun Jul 12, 2009 10:53 am

Re: Using x loc, y loc to position a graphic

Post by Dixie » Sun Nov 07, 2010 2:51 pm

Mark,

even better... nice one :D

be well

Dixie

Post Reply