scrolling background with gaps

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
star0629
Posts: 22
Joined: Thu Nov 28, 2013 9:04 pm

scrolling background with gaps

Post by star0629 » Thu Dec 05, 2013 5:45 pm

I want to delete this post
Last edited by star0629 on Sat Jan 11, 2014 4:11 pm, edited 1 time in total.

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

Re: scrolling background with gaps

Post by Klaus » Thu Dec 05, 2013 6:07 pm

Hi star0629,

hmm, maybe a "lock screen" might help?
And do not use THE when addressing objects:
BAD: left of THE image...
GOOD; left of image...

Try this:

Code: Select all

on moveBg
  lock screen
  
  ## use a repeat loop to save some typing :-)
  repeat with i = 1 to 3
    set the left of img ("bg" & i) to the left of img ("bg" & i) - 4
    
    if the right of img ("bg" & i) < 0 then
      set the left of img ("bg" & i) to 818
    end if
  end repeat
  
  ## DONE, lift curtain :-)
  unlock screen
  
  updateScore
end moveBg
Best

Klaus

star0629
Posts: 22
Joined: Thu Nov 28, 2013 9:04 pm

Re: scrolling background with gaps

Post by star0629 » Sat Dec 07, 2013 4:29 pm

nope that didn't work and the images continue to overlap each other :@ ...once they go the card they start again to the beginning position overlapped :/

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

Re: scrolling background with gaps

Post by dunbarx » Sat Dec 07, 2013 6:01 pm

Hi,

Where do the images start? Are their locs initialized?

I see no problems with your script, in that the three images move in lock-step as you ordered, reappearing at the right when they disappear off screen to the left. What "overlap" are you seeing? The images are, as I said, in lock-step.

Craig Newman

star0629
Posts: 22
Joined: Thu Nov 28, 2013 9:04 pm

Re: scrolling background with gaps

Post by star0629 » Tue Dec 10, 2013 12:34 am

The images are positioned at the front in the middle of the card e.g

"Image1" "Image2"

I dont code anything for the images to be in that certain location, i just happen to put them there and then lock the position when on edit mode. What i mean by over lap is when the game is running the images are scrolling along the card, once "image1" goes off the card (left side) it reappears from the right side of the card (here is when is begins to overlap) whilst "image1" is scrolling along as expected, "image2" has gone of the card (left side) and where there is supose to be a gap between the two images is filled up and the "image2" appears closer to "image1" as if "image2" is moving at a faster rate than "image1" this continues until "image2" has gone in front of "image1" somehow.

Could it possibly be becuase of the size of the image i am using? Do they all have to be same in length and height and stuff?

Thanks

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

Re: scrolling background with gaps

Post by dunbarx » Tue Dec 10, 2013 12:41 am

Have you locked the size of the images? This can cause problems, and has no bearing on their manipulation under script control.

Craig

star0629
Posts: 22
Joined: Thu Nov 28, 2013 9:04 pm

Re: scrolling background with gaps

Post by star0629 » Tue Dec 10, 2013 12:43 am

Yeah the lock size and position box is ticked on all the images

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: scrolling background with gaps

Post by Simon » Tue Dec 10, 2013 2:06 am

Hi star0629,
From your block of code:

if the right of the image "bg1" < 0 then
set the left of the image "bg1" to "822" - 4
end if

Would it be more accurate to say

if the right of image "bg1" < 0 then
set the left of image "bg1" to the (right of image "bg3" - 4)
end if

That way it doesn't matter the size of your images and you don't have to rely on that 822.

Simon
Edit: dropped "the"
Last edited by Simon on Tue Dec 10, 2013 5:56 am, edited 1 time in total.
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

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

Re: scrolling background with gaps

Post by dunbarx » Tue Dec 10, 2013 2:46 am

Simon,

Have not looked at your idea. But I stuck an arbitrary hard value in the test stack I made, and all was in lock-step.

Craig

star0629
Posts: 22
Joined: Thu Nov 28, 2013 9:04 pm

Re: scrolling background with gaps

Post by star0629 » Tue Dec 10, 2013 6:58 pm

Im so lost and confused what to do..also the fact it must have gaps in between the images and that is the main problem..it wont display they gaps and overlaps each other instead :/

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: scrolling background with gaps

Post by Simon » Tue Dec 10, 2013 10:33 pm

it wont display they gaps and overlaps each other instead :/
That is why I suggested using the right and left of the images... can't overlap.

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

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

Re: scrolling background with gaps

Post by dunbarx » Wed Dec 11, 2013 12:59 am

Simon.
once "image1" goes off the card (left side) it reappears from the right side of the card (here is when is begins to overlap) whilst "image1" is scrolling along as expected, "image2" has gone of the card (left side) and where there is supose to be a gap between the two images is filled up and the "image2" appears closer to "image1" as if "image2" is moving at a faster rate than "image1" this continues until "image2" has gone in front of "image1" somehow.
But he is saying that the one image continually advances over another at each pass. You have fixed the overlap, but there is something else going on that I do not see. I have lock-step. He has changing relative horizontal motion.

Craig

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: scrolling background with gaps

Post by Simon » Wed Dec 11, 2013 1:48 am

Hi Craig,
Yes, sorry, the move rates are different, now I get it.
I messed up on what the "set the left of the image "bg1" to the left of the image "bg1" - 4" was for.

And for my sins I attach a stack that proves essentially star0629 code works (with fixes mentioned by Klaus and Craig).
So there is something else in the code setting positions of the images.

Unless I got it all wrong again :oops:

Simon
Attachments
marchOn.zip
LC 6.5
(828 Bytes) Downloaded 268 times
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

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

Re: scrolling background with gaps

Post by dunbarx » Wed Dec 11, 2013 4:35 am

Simon.

I think the mystery lies with Mr. Star.

Mr Star?

Craig

star0629
Posts: 22
Joined: Thu Nov 28, 2013 9:04 pm

Re: scrolling background with gaps

Post by star0629 » Fri Dec 13, 2013 9:40 pm

Thanks everyone for your help somehow got it to work..not exactly as i hoped, but it works.

Post Reply