Page 1 of 2

set the loc of vs. move to

Posted: Wed Oct 31, 2012 9:13 am
by paulsr
Now, here's something strange. At least, I think it is. Maybe someone can explain what is happening here...

I decided I wanted to provide an on-screen tutorial for an app. So I placed an arrow next to a button, and supplied some narrative to explain what a button tap would do.

Then I thought, I'll make the arrow move briefly over the button, to simulate a button tap.

Here's the arrow...

Image

And the code I used...

Code: Select all

set the loc of img tAortn to tNX,tNY
wait 20 ticks with messages
set the loc of img tAortn to tX,tY


So, the arrow moves to its new location for 20 ticks...

Image

and then moves back. The effect is quite good. This is fine, so I don't have a problem that needs to be solved, but...

I figured the movement would look smoother if I used 'move' instead of 'set the loc of'. So I changed the above code to...

Code: Select all

move img tAortn to tNX,tNY
move img tAortn to tX,tY in 20 ticks
I was right about the smoothness, but look what happens with 'move'...

Image

The arrow seems to embed itself in the button image! It's what a real arrow would do, which is kind of cute, but not what I wanted!

The arrow is not below the button image, nor on top, but stuck halfway in.

Can anyone explain this? BTW: the arrow image is the top numbered layer, so it's not going behind another layer.

Strange huh?

--paul

Re: set the loc of vs. move to

Posted: Wed Oct 31, 2012 9:17 am
by shaosean
Is the rect of the arrow control still the same?

Re: set the loc of vs. move to

Posted: Wed Oct 31, 2012 9:43 am
by paulsr
shaosean wrote:Is the rect of the arrow control still the same?
Yes. I don't change the size, only the location of the arrow.

--paul

Re: set the loc of vs. move to

Posted: Wed Oct 31, 2012 10:16 am
by jmburnod
Selamat Datang Paul,

Can you post the stack in attachment ?

Best regards
Jean-Marc

Re: set the loc of vs. move to

Posted: Wed Oct 31, 2012 11:18 am
by paulsr
I'd rather not, Jean-Marc ... it's quite large.

As I mentioned, it doesn't bother me. I don't need a solution. I just find it really bizarre.

--paul

Re: set the loc of vs. move to

Posted: Wed Oct 31, 2012 11:44 am
by shaosean
paulsr wrote:
shaosean wrote:Is the rect of the arrow control still the same?
Yes. I don't change the size, only the location of the arrow.

--paul

You need to answer the question asked, not that question you thought was asked ;-)
After you do the move to command, is the rect still the same?

Re: set the loc of vs. move to

Posted: Wed Oct 31, 2012 12:16 pm
by paulsr
shaosean wrote:You need to answer the question asked, not that question you thought was asked ;-)
Slap on wrist. Must try harder.
shaosean wrote:After you do the move to command, is the rect still the same?
The rect before the move is 69,159,111,201 and after the first move is 53,159,95,210 because I moved the arrow 16px horizontally. After the second move, the arrow goes back to 69,159,111,201. HTH.

--paul

Re: set the loc of vs. move to

Posted: Wed Oct 31, 2012 5:33 pm
by jacque
I've never seen that before, it is kind of cute. It looks like a redraw problem to me. What happens if you lock and unlock the screen after the move to force a redraw?

move img tAortn to tX,tY in 20 ticks
lock screen
unlock screen

Re: set the loc of vs. move to

Posted: Thu Nov 01, 2012 6:33 am
by shaosean
paulsr wrote:Slap on wrist. Must try harder.
yes ;-)
shaosean wrote:The rect before the move is 69,159,111,201 and after the first move is 53,159,95,210 because I moved the arrow 16px horizontally. After the second move, the arrow goes back to 69,159,111,201. HTH.
k.. everything seems to be fine there, so it seems like a weird redraw issue as jacque mentioned..

Code: Select all

move command
lock screen
unlock screen

Re: set the loc of vs. move to

Posted: Thu Nov 01, 2012 7:36 am
by paulsr
jacque wrote:I've never seen that before, it is kind of cute. It looks like a redraw problem to me. What happens if you lock and unlock the screen after the move to force a redraw?

move img tAortn to tX,tY in 20 ticks
lock screen
unlock screen
Makes no difference Jacqueline.

Just to test, I tried moving the arrow to a different place on the card, where there are no underlying images except for the background. Now I can see better what is happening. If I move the arrow 16px to the left, the 16 left-most pixels of the image disappear ... and return, when I move the image back to its original position.

So the button image is a red herring. The arrow is not really embedding itself in the button :) it's just partly disappearing!

--paul

Re: set the loc of vs. move to

Posted: Thu Nov 01, 2012 9:24 am
by shaosean
What about using the relative form of the move command?

Re: set the loc of vs. move to

Posted: Thu Nov 01, 2012 10:51 am
by paulsr
Okay, mystery solved!

I've just realized that the arrow, which is 42x42 is inside a group which is 50x50. If part of the arrow "moves" outside the boundary of the group it becomes invisible. Whereas if I "set the location of" the arrow it doesn't seem to matter if part of the arrow is outside the group.

To which you will probably all say "We knew that!" :oops:

--paul

Re: set the loc of vs. move to

Posted: Thu Nov 01, 2012 1:08 pm
by shaosean
Had there been a mention of it being grouped, we would have said that ;-)

Re: set the loc of vs. move to

Posted: Thu Nov 01, 2012 7:12 pm
by jacque
Essential info. :) You can use the move command if you move the group instead of a single image. Or, set the lockloc of the group to false and move only the arrow. Without being locked, the group will expand automatically to show its entire content.

If your group is already unlocked then I'm at a loss why setting the location is different than moving. They should be the same. See "boundingRect" in the dictionary though, it may be that the group's boundingRect is not empty, which will prevent it from expanding.

Re: set the loc of vs. move to

Posted: Fri Nov 02, 2012 5:40 am
by paulsr
shaosean wrote:Had there been a mention of it being grouped, we would have said that ;-)
Yeah, I'm sorry about that. I had completely forgotten the arrow image was in a group.

--paul