This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2011-07-21 12:55:57

rdstres
New Scratcher
Registered: 2011-07-21
Posts: 1

scrolling not working

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

 

#2 2011-07-21 13:06:02

EdnaC
Scratcher
Registered: 2007-08-28
Posts: 100+

Re: scrolling not working

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

 

#3 2011-07-21 16:42:36

silentslayer7
Scratcher
Registered: 2011-06-05
Posts: 100+

Re: scrolling not working

I have the same problem all the time. It's annoying, and sadly it's hard to fix


http://i51.tinypic.com/dzcwpe.gif Silentslayer7: Curator from Oct. 24 to Nov. 7

Offline

 

#4 2011-07-21 16:45:37

silentslayer7
Scratcher
Registered: 2011-06-05
Posts: 100+

Re: scrolling not working

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.


http://i51.tinypic.com/dzcwpe.gif Silentslayer7: Curator from Oct. 24 to Nov. 7

Offline

 

#5 2011-07-21 17:15:41

Harakou
Community Moderator
Registered: 2009-10-11
Posts: 1000+

Re: scrolling not working

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 (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.

Code:

if needed_x_pos = scroll x
    show
else
    hide

Of 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.


http://www.blocks.scratchr.org/API.php?action=random&return=image&link1=http://i.imgur.com/OZn2RD3.png&link2=http://i.imgur.com/duzaGTB.png&link3=http://i.imgur.com/CrDGvvZ.png&link4=http://i.imgur.com/POEpQyZ.png&link5=http://i.imgur.com/ZKJF8ac.png

Offline

 

#6 2011-07-21 17:18:50

silentslayer7
Scratcher
Registered: 2011-06-05
Posts: 100+

Re: scrolling not working

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 (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.

Code:

if needed_x_pos = scroll x
    show
else
    hide

Of 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.


http://i51.tinypic.com/dzcwpe.gif Silentslayer7: Curator from Oct. 24 to Nov. 7

Offline

 

#7 2011-07-22 07:46:59

EdnaC
Scratcher
Registered: 2007-08-28
Posts: 100+

Re: scrolling not working

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

 

#8 2011-07-22 17:40:57

treebark1313
Scratcher
Registered: 2011-05-23
Posts: 90

Re: scrolling not working

i always just use the black-boarder method  tongue

P.S. please help me get unbanned!


When life gives you 100 reasons to frown,
show life you have 1000 reasons to smile. - Unknown

Offline

 

#9 2011-07-22 19:48:04

juliabrookek
Scratcher
Registered: 2011-07-18
Posts: 100+

Re: scrolling not working

Something like that happened to me  sad
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.


smile http://dragcave.net/image/rgNE5.gif smile

Offline

 

Board footer