Moving Image within the card from right to left

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
lourinho81
Posts: 9
Joined: Thu Dec 18, 2014 10:17 am

Moving Image within the card from right to left

Post by lourinho81 » Mon Jan 12, 2015 1:52 pm

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

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10331
Joined: Wed May 06, 2009 2:28 pm

Re: Moving Image within the card from right to left

Post by dunbarx » Mon Jan 12, 2015 4:25 pm

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

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Moving Image within the card from right to left

Post by Klaus » Mon Jan 12, 2015 4:33 pm

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

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10331
Joined: Wed May 06, 2009 2:28 pm

Re: Moving Image within the card from right to left

Post by dunbarx » Mon Jan 12, 2015 6:27 pm

Not my fault. I never do that. Really. It was the other guy. Really,

Craig

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10100
Joined: Fri Feb 19, 2010 10:17 am

Re: Moving Image within the card from right to left

Post by richmond62 » Mon Jan 12, 2015 9:13 pm

Boing!
boing.livecode.zip
(12.82 KiB) Downloaded 250 times

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Moving Image within the card from right to left

Post by Klaus » Mon Jan 12, 2015 9:25 pm

dunbarx wrote:Not my fault. I never do that. Really. It was the other guy. Really,

Craig
I will investigate, Craig! :D

lourinho81
Posts: 9
Joined: Thu Dec 18, 2014 10:17 am

Re: Moving Image within the card from right to left

Post by lourinho81 » Tue Jan 13, 2015 11:46 am

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

MWCoastMedia
Posts: 32
Joined: Fri Jan 16, 2015 5:31 pm

Re: Moving Image within the card from right to left

Post by MWCoastMedia » Mon Jan 11, 2016 1:28 pm

*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?

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Moving Image within the card from right to left

Post by Klaus » Mon Jan 11, 2016 1:44 pm

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

SparkOut
Posts: 2947
Joined: Sun Sep 23, 2007 4:58 pm

Re: Moving Image within the card from right to left

Post by SparkOut » Mon Jan 11, 2016 7:35 pm

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.

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Moving Image within the card from right to left

Post by Klaus » Mon Jan 11, 2016 7:43 pm

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.

Post Reply