Object horizontal scrolling ...

Started by DrewCCU, Thu 08/04/2010 06:01:19

Previous topic - Next topic

DrewCCU

Okay ... i need help. I've done everything i can to figure this out but nothing seems to be working.

I need to have objects that scroll horizontally in a straight line (from left to right).  Once the object reaches the right side i need it to reappear back on the left side and then scroll back to the right ... once it reaches the right side repeat ... over and over again. forever. think of it as obstacles in frogger if you will

I tried what i thought would be a simple process just doing something like:

Code: ags

  if (Object.GetAtScreenXY(645, 535) == oRock) {
  object[0].SetPosition(5, 535);
}
  else {
    object[0].Move(645, 535, 2, eNoBlock, eAnywhere);
  }


but it doesnt work - it's like the games not reading the "if" part. only the "else" part as the object moves across the screen but when it gets to the final coordinates (645,535) it doesn't return to the starting position (5, 535) like the script says to ... what's the issue? Btw, this code is put in my room code (after fade in)
"So much of what we do is ephemeral and quickly forgotten, even by ourselves, so it's gratifying to have something you have done linger in people's memories."
-John Williams

Matti

After_Fadein is called once. Put it in the rep-ex.

Gilbert

Yeah, put it in rep-exec[_always](). Also, you don't need to issue a Move() every game loop. Try this:
Code: ags

  if (oRock.X == 645) {
  oRock.SetPosition(5, 535);
}
  else if (oRock.x == 5){
    oRock.Move(645, 535, 2, eNoBlock, eAnywhere);
  }


Also, make sure that the object could indeed reach x-coordinate 645 considering the room's size and the game's res.

DrewCCU

#3
Quote from: Gilbet V7000a on Thu 08/04/2010 06:41:07
Yeah, put it in rep-exec[_always](). Also, you don't need to issue a Move() every game loop. Try this:
Code: ags

  if (oRock.X == 645) {
  oRock.SetPosition(5, 535);
}
  else if (oRock.x == 5){
    oRock.Move(645, 535, 2, eNoBlock, eAnywhere);
  }


Also, make sure that the object could indeed reach x-coordinate 645 considering the room's size and the game's res.

yes it can reach that coordiante - i'm using a 800x600 resolution. But i'm sorry to say that code did not work - and i put it in RepExec (i also corrected your second "x" to caps as it would crash with it lower case)
"So much of what we do is ephemeral and quickly forgotten, even by ourselves, so it's gratifying to have something you have done linger in people's memories."
-John Williams

Gilbert

#4
What happened? Please tell us how it "didn't work", otherwise it's hard for us to help you.
Also, is your game using hi-res coordinates? Otherwise if it's using low-res coordinates, the effective screen dimension is just 400x300.

Edit:
You may also use Display() etc. to track whether the if conditions are executed, and on second thought, instead you may just check whether the object is moving, which IMO produces cleaner codes and should still work in case the object cannot reach the desired coordinates for whatever reasons:
Code: ags

  if (!oRock.Moving) {
    oRock.SetPosition(5, 535);
    oRock.Move(645, 535, 2, eNoBlock, eAnywhere);
  }

DrewCCU

#5
like i said -I'm using 800x600 resolution and the object does move. what happens is (like i stated in the original post) the object moves but when it gets to the desired coordinates it does not take it back to the starting coordinates. It's like the code is reading the part where i tell the object to move but not the part where i say "when it gets here, take it back to where it started"

NOTE:

The code i posted originally is just how i thought it might could be coded ... but if theres another method of coding please let me know.  Again i'm going for i need objects to move from left to right continuously - in a looping manner, like on frogger.
"So much of what we do is ephemeral and quickly forgotten, even by ourselves, so it's gratifying to have something you have done linger in people's memories."
-John Williams

Crimson Wizard

#6
I honestly can't guess what may be wrong in your code... anyway, that is the code I used in my own game a while ago (and it worked perfectly):

Code: ags

oWave1.X = oWave1.X + 1;
if (oWave1.X == 0) oWave1.X = -76;


NOTE: initial position of oWave was -2.
So, it go from -2 to 0, then to -76 and from -76 to 0 and then repeated last move forever.

DrewCCU

Quote from: Crimson Wizard on Fri 09/04/2010 00:13:30
I honestly can't guess what may be wrong in your code... anyway, that is the code I used in my own game a while ago (and it worked perfectly):

Code: ags

oWave1.X = oWave1.X + 1;
if (oWave1.X == 0) oWave1.X = -76;


NOTE: initial position of oWave was -2.
So, it go from -2 to 0, then to -76 and from -76 to 0 and then repeated last move forever.

just to make sure ... this code will move the object from one location (say: left side of screen) to another location (say: right side) and when it gets to second location it goes back to starting locations and repeats this process over and over again?
"So much of what we do is ephemeral and quickly forgotten, even by ourselves, so it's gratifying to have something you have done linger in people's memories."
-John Williams

Crimson Wizard

Quote from: DrewCCU on Fri 09/04/2010 00:50:41
Quote from: Crimson Wizard on Fri 09/04/2010 00:13:30
I honestly can't guess what may be wrong in your code... anyway, that is the code I used in my own game a while ago (and it worked perfectly):

Code: ags

oWave1.X = oWave1.X + 1;
if (oWave1.X == 0) oWave1.X = -76;


NOTE: initial position of oWave was -2.
So, it go from -2 to 0, then to -76 and from -76 to 0 and then repeated last move forever.

just to make sure ... this code will move the object from one location (say: left side of screen) to another location (say: right side) and when it gets to second location it goes back to starting locations and repeats this process over and over again?

Yes, exactly.
I did this to simulate scrolling of the waves in the sea. I had 3 "wave" objects that were wider than screen, and made them move from left to right, and then instantly "teleport" back on older positions.

DrewCCU

lol thanks - i got it working ... which in a way sucks cus my buddy was helping me with this and he had to use probably like 50 lines of code that does the same thing ur 2 lines do. thanks man
"So much of what we do is ephemeral and quickly forgotten, even by ourselves, so it's gratifying to have something you have done linger in people's memories."
-John Williams

Gilbert

But did you ever try my suggestion to check whether the object is Moving? That should probably work too.

DrewCCU

Quote from: Gilbet V7000a on Fri 09/04/2010 01:56:52
But did you ever try my suggestion to check whether the object is Moving? That should probably work too.

u apparently havent been reading my posts thoroughly.  I've said (since the beginning of the thread) that the object does indeed move.  That was never the issue.
"So much of what we do is ephemeral and quickly forgotten, even by ourselves, so it's gratifying to have something you have done linger in people's memories."
-John Williams

SMF spam blocked by CleanTalk