Page 1 of 1

Moving Image within the card from right to left

Posted: Mon Jan 12, 2015 1:52 pm
by lourinho81
Hi,

Ive created a new challenge for myself. Im trying to move and Image from right to left within a card.
trying to create an effect of bouncing the image between the right and left edges of the card.

My code this far;

command preopencard
set location image "pinkwall" to 25,25
moveobjects
end preopencard


command moveobjects
// Move object down
--set the top of image "pinkwall" to the top of image "pinkwall" +1

//Reset object to top of page if moved of the page
--if the top of image "pinkwall" > the bottom of this card then
--set the bottom of image "pinkwall" to the top of this card
--end if

if the left of image "pinkwall" = the left of this card then
moveright
end if

if the right of image "pinkwall" = the right of this card then
moveleft
end if

send "moveobjects" to me in 50 milliseconds
end moveobjects

command moveright
set the right of image "pinkwall" to the right of image "pinkwall" +10
send "moveright" to me in 50 milliseconds
end moveright

command moveleft
set the left of image "pinkwall" to the left of image "pinkwall" -10
send "moveleft" to me in 50 milliseconds
end moveleft


regards
Lourinho81

Re: Moving Image within the card from right to left

Posted: Mon Jan 12, 2015 4:25 pm
by dunbarx
Hi.

Oftentimes the order of the actions in your code can greatly affect the operation of that code. I just glanced at your handlers, and noticed that there was no way for each of the "move" handlers to switch to the other direction. Read your script carefully and see why this is so. Anyway, try this. I just made two buttons, one of which I named "bb". In the other button script:

Code: Select all

on mouseUp
   set location btn "bb" to 25,225
    if the left of btn "bb" <= the left of this card then moveright
   else moveLeft
end mouseUp

command moveleft
   if the optionKey is down then exit to top
    set the left of btn "bb" to the left of btn "bb"  - 10
   if the left of btn"bb" <= the left of this card then  moveRight
   else send "moveleft" to me in 1
end moveleft

command moveRight
   if the optionKey is down then exit to top
   set the right of btn "bb" to the right of btn "bb" + 10
   if the right of btn"bb" >= the right of this card then moveLeft
   else send "moveRight" to me in 1
end moveRight
Why the "optionKey" thingie? Write back, please, with what you find out.

Craig Newman

Re: Moving Image within the card from right to left

Posted: Mon Jan 12, 2015 4:33 pm
by Klaus
Hi guys,

sloppiness might break your necks in future and less forgiving releases of LC :D
...
set THE loc OF image "pinkwall" to 25,25
...
set THE location OF btn "bb" to 25,225
...


Best

Klaus

Re: Moving Image within the card from right to left

Posted: Mon Jan 12, 2015 6:27 pm
by dunbarx
Not my fault. I never do that. Really. It was the other guy. Really,

Craig

Re: Moving Image within the card from right to left

Posted: Mon Jan 12, 2015 9:13 pm
by richmond62
Boing!
boing.livecode.zip
(12.82 KiB) Downloaded 250 times

Re: Moving Image within the card from right to left

Posted: Mon Jan 12, 2015 9:25 pm
by Klaus
dunbarx wrote:Not my fault. I never do that. Really. It was the other guy. Really,

Craig
I will investigate, Craig! :D

Re: Moving Image within the card from right to left

Posted: Tue Jan 13, 2015 11:46 am
by lourinho81
Hi Guys,

Many thanks for your help and advise. I have managed to resolve the challenge with your assistance.

Updated Code below.

command preopencard
set location of image "pinkwall" to 225,25
moveobjects
moveleft
end preopencard

command moveobjects
// Move object down
set the top of image "pinkwall" to the top of image "pinkwall" +1

//Reset object to top of page if moved of the page
if the top of image "pinkwall" > the bottom of this card then
set the bottom of image "pinkwall" to the top of this card
end if
send "moveobjects" to me in 10 millisecond
end moveobjects

command moveleft
//Move Object Left else Right
set the left of image "pinkwall" to the left of image "pinkwall" -1
if the left of image "pinkwall" <= the left of this card then moveright
else send "moveleft" to me in 10 millisecond
end moveleft

command moveright
//Move Object Right else Left
set the right of image "pinkwall" to the right of image "pinkwall" +1
if the right of image "pinkwall" >= the right of this card then moveleft
else send "moveright" to me in 10 millisecond
end moveright


regards
Lourinho81

Re: Moving Image within the card from right to left

Posted: Mon Jan 11, 2016 1:28 pm
by MWCoastMedia
*bump*

While I appreciate treefolk pasting the script in here that is provided in the Game Academy, this thread is almost 3 years old (as is Game Academy) and updateScreen still isn't in the native LiveCode vocabulary. Any idea of a roadmap on this feature?

Re: Moving Image within the card from right to left

Posted: Mon Jan 11, 2016 1:44 pm
by Klaus
Hi MWCoastMedia,

sorry, I really don't get it!?

"updatescreen" is just the name of a handler that is used in the "Game Academy" examples
which contains a lot of loc-setting and other game-relevant stuff.

BUT this is depending on the current situation resp. game and if you check the scripts of other games
you will see that every developer uses DIFFERENT commands in her/his "updatescreen" handler.

So what should a native "updatescreen" command do in Livecode in your opinion? 8)


Best

Klaus

Re: Moving Image within the card from right to left

Posted: Mon Jan 11, 2016 7:35 pm
by SparkOut
If I recall correctly, the Game Academy did include references to an updateScreen handler which took advantage of some of the "new" dynamic screen rendering features in the "then" update to LC. There was also mention of this updateScreen code being automagically included engine-side, the code provided was meant to be just because the dynamic screen handling stuff was too new to have been included in the engine at that point, but would be "soon".

It is easy to see there may be confusion with a "game loop" scenario here.

Re: Moving Image within the card from right to left

Posted: Mon Jan 11, 2016 7:43 pm
by Klaus
Oh, sorry, since I did not attend the "Game Academy" I did not know that! :oops:
I only saw some scripts posted here with that handler.