I'm working on a 2D scrolling game, but everytime my character is supposed to move on to the next section, a small portion of the terrain keeps moving with him and overlaps over the next section. This keeps him stuck on it as it follows him no matter how far he goes. I've copied the scripts exactly from several forums and from the scratch example for how to do this, but none of them work for my game. Please help!!
Offline
Scratch won't let you position a sprite all of the way off the screen; This is to keep new Scratch programmers from "losing" their sprites. Some scrolling games use a black border sprite to cover up the terrain that refuses to go away.
I prefer to hide the terrain sprite.
In the script that moves the terrain, you can have a variable that stores the position that you want the sprite to go to, then compare that to the sprite's xposition, if they don't match, hide the sprite, else show it.
An alternate way to do this is to check the absolute value of the sprite's xposition, if this gets above some value, hide the sprite, else show it.
Offline
I have the same problem all the time. It's annoying, and sadly it's hard to fix
Offline
EdnaC wrote:
In the script that moves the terrain, you can have a variable that stores the position that you want the sprite to go to, then compare that to the sprite's xposition, if they don't match, hide the sprite, else show it.
What do you mean by "Stores the position" and "Compare that to the sprite's xposition"? Sorry if that's dumb I just don't know.
Offline
silentslayer7 wrote:
EdnaC wrote:
In the script that moves the terrain, you can have a variable that stores the position that you want the sprite to go to, then compare that to the sprite's xposition, if they don't match, hide the sprite, else show it.
What do you mean by "Stores the position" and "Compare that to the sprite's xposition"? Sorry if that's dumb I just don't know.
Storing the position would be storing the x position value needed in a variable.
set needed_x_pos to (whatever
Comparing it would use an if statement to see if the character's current x position is equal to the variable or not using an if statement.
if needed_x_pos = scroll x
show
else
hideOf course, this might not work so well. It would be better for it to check if scroll x is within a needed range of values rather than one specific position.
Offline
Harakou wrote:
silentslayer7 wrote:
EdnaC wrote:
In the script that moves the terrain, you can have a variable that stores the position that you want the sprite to go to, then compare that to the sprite's xposition, if they don't match, hide the sprite, else show it.
What do you mean by "Stores the position" and "Compare that to the sprite's xposition"? Sorry if that's dumb I just don't know.
Storing the position would be storing the x position value needed in a variable.
Code:
set needed_x_pos to (whateverComparing it would use an if statement to see if the character's current x position is equal to the variable or not using an if statement.
Code:
if needed_x_pos = scroll x show else hideOf course, this might not work so well. It would be better for it to check if scroll x is within a needed range of values rather than one specific position.
Ok thanks.
Offline
Harakou has the idea right. Checking to see if a sprite was able to go where you told it to go is a very reliable way to tell if it should still be considered "on screen".
Checking for a particular value isn't the best - how far a sprite can go is dependent on its size. The center of a small sprite can't go past the edge, but the center of a landscape sprite that is 480 pixels wide can go to nearly +/-480. You can find the limiting value by experimenting, but checking whether it was able to go where you sent it always works...
Offline
i always just use the black-boarder method
P.S. please help me get unbanned!
Offline
Something like that happened to me
I did scrolling and it worked fine, but then I made an enemy, and when my character
moved to the next terrain, the enemy stuck to the player.
Offline