Jump to content
IGNORED

Scroll Left to right issue


Recommended Posts

Hey,

 

I have another scroll problem :)

 

The game scrolls ok while going in one direction, but I find that when I turn to scroll the other way... things get cut off.

 

Here is a video of what I mean, you will see the word Jail change to Jal and then ail.

 

https://youtu.be/Dtu90gr6yuU

 

Any ideas what could be going on here?

 

 

Link to comment
Share on other sites

Without seeing the code, I can only tell you I ran into the same problem when I first started using scrolling.  I most recently performed left-right scrolling in the I/O Tape Viewer screen in Little Man Computer, so I can show you my snippet of code if it would help.

 

It has to do with when you shift everything from one card to the next.  With a little trial-and-error, you should be able to get everything moved over correctly.

Link to comment
Share on other sites

3 minutes ago, Zendocon said:

Without seeing the code, I can only tell you I ran into the same problem when I first started using scrolling.  I most recently performed left-right scrolling in the I/O Tape Viewer screen in Little Man Computer, so I can show you my snippet of code if it would help.

 

It has to do with when you shift everything from one card to the next.  With a little trial-and-error, you should be able to get everything moved over correctly.

Here is the code I am using to draw the street:

 

draw_street: procedure

if dir = 2 then   
  IF offset_x + SPEED >= 8 THEN
 offset_d = 1:offset_x = -1 + SPEED
ELSE
 offset_x = offset_x + SPEED
end if
gosub bum
gosub people_moving
SCROLL offset_x, offset_y, offset_d
offset_d = 0

IF offset_x = 1 THEN
#muv = #muv - 1

item_pos = item_pos - 1
    item_loc = item_loc + 1 

   if item_pos <= 1 then 
    item_pos = 20
    left_screen_at = 2 
    new_item = 0
   end if

if #muv <= 1 then #muv = 19
if street = 0 then SCREEN screen_0, #muv, 0, 1, BACKGROUND_ROWS, #LANDSCAPE_WIDTH
if street = 1 then SCREEN screen_1, #muv, 0, 1, BACKGROUND_ROWS, #LANDSCAPE_WIDTH
if street = 2 then SCREEN screen_2, #muv, 0, 1, BACKGROUND_ROWS, #LANDSCAPE_WIDTH
if street = 3 then SCREEN screen_3, #muv, 0, 1, BACKGROUND_ROWS, #LANDSCAPE_WIDTH
 
end if

end if

  if dir = 1 then 
   IF offset_t = 0 THEN
 offset_u = 2:offset_t = 8 - SPEED
ELSE
 offset_t = offset_t - SPEED
END IF
gosub bum
gosub people_moving
SCROLL offset_t, offset_y, offset_u
'WAIT
offset_u = 0

IF offset_t = 8 - SPEED THEN
#muv = #muv + 1

item_pos = item_pos + 1
   item_loc = item_loc - 1

if item_pos >= 22 then 
   item_pos = 2
   left_screen_at = 1
   new_item = 0
  end if

  if #muv >= 260 then #muv = 241 'increase x 20
if street = 0 then SCREEN screen_0, #muv+19, 19, 1, BACKGROUND_ROWS, #LANDSCAPE_WIDTH
if street = 1 then SCREEN screen_1, #muv+19, 19, 1, BACKGROUND_ROWS, #LANDSCAPE_WIDTH
if street = 2 then SCREEN screen_2, #muv+19, 19, 1, BACKGROUND_ROWS, #LANDSCAPE_WIDTH
if street = 3 then SCREEN screen_3, #muv+19, 19, 1, BACKGROUND_ROWS, #LANDSCAPE_WIDTH

 end if
end if

end

Link to comment
Share on other sites

I don't know if you had resolved this yet, but typically when I am doing scrolling in games, I have my SCROLL command run, a WAIT statement after this (at some point in the loop), and then update the SCREEN.

 

When you use SCROLL to shift the screen, the shift does not occur immediately, but will after the WAIT.

 

 

 

Link to comment
Share on other sites

Off topic, but you can further simplify your code and avoid all the redundant conditional statements for drawing the screen for the various streets by using a table containing offsets for the starting point of each area.  This can be very beneficial if your game grows larger.

 

For example, if your all four street map data (screen_0, screen_1, screen_2, and screen_3) are made up of 40x12 tiles, you could have something like this:

 

stage_offset:

DATA 0 ' Street 0

DATA (40*12) ' Street 1

DATA (40*12) + (40*12) ' Street 2

DATA (40*12) + (40*12) + (40*12) ' Street 3

 

If the sizes are different, just make the changes accordingly, just keeping in mind to carry over the offset from the previous line.

 

Instead of having all the conditional statements, have a single SCREEN command like this:

SCREEN street_maps, stage_offset(street) + #muv+19, 19, 1, BACKGROUND_ROWS, #LANDSCAPE_WIDTH

 

 

Link to comment
Share on other sites

4 hours ago, skywaffle said:

I don't know if you had resolved this yet, but typically when I am doing scrolling in games, I have my SCROLL command run, a WAIT statement after this (at some point in the loop), and then update the SCREEN.

 

When you use SCROLL to shift the screen, the shift does not occur immediately, but will after the WAIT.

 

 

 

@skywaffle Zendocon sent me his code and I noticed that he was using the wait statement. I put it in my code and it looks like it might be solving the problem... however the people walking by are now all jittery. I have a script that has people walking, so I think there is an offset issue now. Essentially I have a counter (slow_people) that increases + 1 until 40 to move the person.

 

if slow_people = 40 then
if pep_dir = 2 then pep_walk_x = pep_walk_x - 3
if pep_dir = 1 then pep_walk_x = pep_walk_x + 3
slow_people = 0
end if 

Edited by Brian's Man Cave
  • Like 1
Link to comment
Share on other sites

On 11/17/2021 at 9:37 AM, skywaffle said:

I always update all sprites on screen after the SCROLL statement, and before the WAIT.   Whenever you shift the backtab, you will also need to offset your people by 8 pixels.

@skywaffle so I update the sprites after the scroll and after the screen draws the next line of tiles?

Link to comment
Share on other sites

In my projects, my flow is something like below:

 

START:

Update the scroll offset variable.  Check if the offset > 7 and if so, set a variable for screen shifting (IF OFFSET_X > 7 THEN OFFSET_X = OFFSET_X - 8: SCREEN_SHIFT = 1)

SCROLL OFFSET_X, 0, SCREEN_SHIFT

Update SPRITE positions

WAIT

Check sprite collisions

IF SCREEN_SHIFT <> 0 THEN SCREEN_SHIFT = 0: SCREEN etc

 

GOTO START

 

 

Link to comment
Share on other sites

@skywaffleHmm, I must be missing something. When you say update the sprite positions does that mean to draw them to the screen?

 

I put in the gosub bum and  gosub people to re draw the sprites... but they are still gittery.

 

if dir = 2 then   
  IF offset_x + SPEED >= 8 THEN
 offset_d = 1:offset_x = -1 + SPEED
ELSE
 offset_x = offset_x + SPEED
end if
 
SCROLL offset_x, offset_y, offset_d
gosub bum
gosub people 


wait
offset_d = 0

IF offset_x = 1 THEN
#muv = #muv - 1

item_pos = item_pos - 1
    item_loc = item_loc + 1 

   if item_pos <= 1 then 
    item_pos = 20
    left_screen_at = 2 
    new_item = 0
   end if

if #muv <= 1 then #muv = 19
if street = 0 then SCREEN screen_0, #muv, 0, 1, BACKGROUND_ROWS, #LANDSCAPE_WIDTH
if street = 1 then SCREEN screen_1, #muv, 0, 1, BACKGROUND_ROWS, #LANDSCAPE_WIDTH
if street = 2 then SCREEN screen_2, #muv, 0, 1, BACKGROUND_ROWS, #LANDSCAPE_WIDTH
if street = 3 then SCREEN screen_3, #muv, 0, 1, BACKGROUND_ROWS, #LANDSCAPE_WIDTH
 

end if

 

Edited by Brian's Man Cave
Link to comment
Share on other sites

46 minutes ago, skywaffle said:

I update the variables for any sprite positions and then redraw all sprites at that point.   Is the jitter occurring each frame, or only on the frame the backtab is shifted?

Its happening continuous as the screen is scrolling. I am assuming there is an offset that needs to happen? 

Link to comment
Share on other sites

6 hours ago, Brian's Man Cave said:

Its happening continuous as the screen is scrolling. I am assuming there is an offset that needs to happen? 

You need to subtract offset_x and offset_y from the sprite X and Y coordinates when using the SPRITE statement.

 

 

Link to comment
Share on other sites

5 hours ago, nanochess said:

You need to subtract offset_x and offset_y from the sprite X and Y coordinates when using the SPRITE statement.

 

 

@nanochess the problem I am having is that while the screen scrolls I have people continuously walking from either the right side or the left side… when they are walking in the same direction as the scroll, they fall behind off the screen. 

Link to comment
Share on other sites

9 hours ago, Brian's Man Cave said:

@nanochess the problem I am having is that while the screen scrolls I have people continuously walking from either the right side or the left side… when they are walking in the same direction as the scroll, they fall behind off the screen. 

I see. You should make sure these walk at the same speed as scroll. And when scrolling you should subtract the scroll displacement from the base X coordinate of the people (not the same as offset_x)

 

This means that if a person is walking to right, and you scroll to right, he/she would keep static at the same X coordinate because both movements nullify visually.

Link to comment
Share on other sites

2 hours ago, nanochess said:

I see. You should make sure these walk at the same speed as scroll. And when scrolling you should subtract the scroll displacement from the base X coordinate of the people (not the same as offset_x)

 

This means that if a person is walking to right, and you scroll to right, he/she would keep static at the same X coordinate because both movements nullify visually.

So what is the scroll displacement if it’s not offset_x? 

Link to comment
Share on other sites

3 hours ago, Brian's Man Cave said:

So what is the scroll displacement if it’s not offset_x? 

In pseudo-code:

 

Scrolling to right.

 

IF need-to-scroll THEN

    Enemy_x = enemy_x - 1    ' IF enemy is static it would disappear at left

    ' we suppose player moves with scrolling, so we don't change its position

    Offset_x = offset_x + 1

    If offset_x = 8 then offset_x = 0: offset_d = 2

END IF

 

SCROLL offset_x,offset_y,offset_d

 

SPRITE 0,$0308+player_x-offset_x,$0108+player_y-offset_y,$0806

SPRITE 1,$0308+enemy_x-offset_x,$0108+enemy_y-offset_y,$0806+1*8

WAIT

Offset_d = 0

 

Link to comment
Share on other sites

1 hour ago, nanochess said:

In pseudo-code:

 

Scrolling to right.

 

IF need-to-scroll THEN

    Enemy_x = enemy_x - 1    ' IF enemy is static it would disappear at left

    ' we suppose player moves with scrolling, so we don't change its position

    Offset_x = offset_x + 1

    If offset_x = 8 then offset_x = 0: offset_d = 2

END IF

 

SCROLL offset_x,offset_y,offset_d

 

SPRITE 0,$0308+player_x-offset_x,$0108+player_y-offset_y,$0806

SPRITE 1,$0308+enemy_x-offset_x,$0108+enemy_y-offset_y,$0806+1*8

WAIT

Offset_d = 0

 

Its almost working, do I need to adjust the enemy_x = enemy_x - 1 if there is speed involved?  Also my characters move by +3 increments.

 

also the people can either come from the right side or the left side regardless of what direction your character is going.

 

draw_street: procedure

if dir = 2 then
    offset_x = offset_x + speed
     
    IF offset_x >= 8 THEN
        offset_x = offset_x - 8
        scrollflag = 1
       'if pep_dir = 1 then pep_walk_x = pep_walk_x + 8
       pep_walk_x = pep_walk_x - 1
        
    end if
 
    SCROLL offset_x, offset_y, scrollflag
   
    gosub bum
    gosub people 

    wait
    IF scrollflag THEN
        #muv = #muv - 1

        item_pos = item_pos - 1
        item_loc = item_loc + 1 

        if item_pos <= 1 then 
            item_pos = 20
            left_screen_at = 2 
            new_item = 0
        end if

        if #muv <= 1 then #muv = 19
        if street = 0 then SCREEN screen_0, #muv, 0, 1, BACKGROUND_ROWS, #LANDSCAPE_WIDTH
        if street = 1 then SCREEN screen_1, #muv, 0, 1, BACKGROUND_ROWS, #LANDSCAPE_WIDTH
        if street = 2 then SCREEN screen_2, #muv, 0, 1, BACKGROUND_ROWS, #LANDSCAPE_WIDTH
        if street = 3 then SCREEN screen_3, #muv, 0, 1, BACKGROUND_ROWS, #LANDSCAPE_WIDTH
        scrollflag = 0
    end if
end if

  if dir = 1 then
    offset_x = offset_x - speed
    IF offset_x >= 8 THEN
        offset_x = offset_x + 8
        scrollflag = 2
        'pep_walk_x = pep_walk_x - 8
        pep_walk_x = pep_walk_x + 1
        
    end if
 
    SCROLL offset_x, offset_y, scrollflag
    gosub bum
    gosub people 

    wait
    IF scrollflag THEN
        #muv = #muv + 1

        item_pos = item_pos + 1
   item_loc = item_loc - 1

if item_pos >= 22 then 
   item_pos = 2
   left_screen_at = 1
   new_item = 0
  end if

  if #muv >= 260 then #muv = 241 'increase x 20
if street = 0 then SCREEN screen_0, #muv+19, 19, 1, BACKGROUND_ROWS, #LANDSCAPE_WIDTH
if street = 1 then SCREEN screen_1, #muv+19, 19, 1, BACKGROUND_ROWS, #LANDSCAPE_WIDTH
if street = 2 then SCREEN screen_2, #muv+19, 19, 1, BACKGROUND_ROWS, #LANDSCAPE_WIDTH
if street = 3 then SCREEN screen_3, #muv+19, 19, 1, BACKGROUND_ROWS, #LANDSCAPE_WIDTH
        scrollflag = 0
    end if
end if

end

Edited by Brian's Man Cave
Link to comment
Share on other sites

4 hours ago, Brian's Man Cave said:

Its almost working, do I need to adjust the enemy_x = enemy_x - 1 if there is speed involved?  Also my characters move by +3 increments.

Yes, it should be by "speed" increments. I've corrected the two locations where pep_x is added/subtracted to be near offset_x. Remember the displacement is in pixels, not per card.

4 hours ago, Brian's Man Cave said:

 

draw_street: procedure

if dir = 2 then
    offset_x = offset_x + speed

    Pep_walk_x = pep_walk_x - speed
     
    IF offset_x >= 8 THEN
        offset_x = offset_x - 8
        scrollflag = 1
       'if pep_dir = 1 then pep_walk_x = pep_walk_x + 8
        
    end if
 
    SCROLL offset_x, offset_y, scrollflag
   
    gosub bum
    gosub people 

    wait
    IF scrollflag THEN
        #muv = #muv - 1

        item_pos = item_pos - 1
        item_loc = item_loc + 1 

        if item_pos <= 1 then 
            item_pos = 20
            left_screen_at = 2 
            new_item = 0
        end if

        if #muv <= 1 then #muv = 19
        if street = 0 then SCREEN screen_0, #muv, 0, 1, BACKGROUND_ROWS, #LANDSCAPE_WIDTH
        if street = 1 then SCREEN screen_1, #muv, 0, 1, BACKGROUND_ROWS, #LANDSCAPE_WIDTH
        if street = 2 then SCREEN screen_2, #muv, 0, 1, BACKGROUND_ROWS, #LANDSCAPE_WIDTH
        if street = 3 then SCREEN screen_3, #muv, 0, 1, BACKGROUND_ROWS, #LANDSCAPE_WIDTH
        scrollflag = 0
    end if
end if

  if dir = 1 then
    offset_x = offset_x - speed

    Pep_walk_x = pep_walk_x + speed
    IF offset_x >= 8 THEN
        offset_x = offset_x + 8
        scrollflag = 2
        'pep_walk_x = pep_walk_x - 8
        
    end if
 
    SCROLL offset_x, offset_y, scrollflag
    

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...