Log In  

Cart #29982 | 2016-10-04 | Code ▽ | Embed ▽ | License: CC4-BY-NC-SA

As some of you new to PICO might be asking. How can I make a smooth-scrolling map ?

The solution ? To use PICO's own MSET() to plot tiles into your map space and MAP() to draw it all out.

Check the code carefully though ! PICO apparently cannot by default smoothly scroll a map one pixel at a time so I am plotting the map using a modulos of 8 steps to count as one tile for pixel-perfect movement.

Hit the (Z) key to change from the 1st room to the 2nd.

A center digit will tell you which page you are on.

When you get to the end, before you hit a key to return to the prompt, hit CTRL-R right there to run it again.

P#29983 2016-10-04 13:37 ( Edited 2016-10-04 19:50)

You can scroll however you want to. All functions that draw are automatically clipped to the screen, so you can map(tilex,tiley, -1,0, 17,17) to draw the map shifted one pixel to the left.

edit: and scrolling a map larger than the screen is one of the times you probably want to use camera(). As usual, I suggest digging into Jelpi to see how it handles things.

P#29986 2016-10-04 13:56 ( Edited 2016-10-04 18:02)

Hi Tyroney.

I think I'm doing this already ?

  map(i/8,0,-3+7-(i%8),4,120,120)

But you bring up an interesting idea. What if ... ? I scroll BIG map that is well outside the screen, limited to CLIP() ?

map(0,0,-i+4,4,999,999)

That seems to work. That saves not doing a modulos - yet this method is REALLY bad coding. :D

I guess what I wanted was map(pixelmapx,pixelmapy,...)

So you would need to have pixelmapx at 8 in order to read ahead one tile. As it is, a single "1" jumps 8-pixels, and no, you can't use math 1/8 to extract the smooth pixel either; that is ignored.

P#29990 2016-10-04 14:03 ( Edited 2016-10-04 18:04)

The first two arguments to map() are tilex and tiley, since the map works in tiles. The next two are screenx and screeny, which are in pixels.

So you keep track of your offset (the same numbers you'd be sending to camera() ) and do a map call something like

camera(offsetx,offsety)
map(offsetx/8,offsety/8, 0-offsetx%8,0-offsety%8,17,17)

edit: no clip() needed, since all draw calls are automatically clipped. You can draw at (-500,49217840) if you want to. (and if you've used camera() to move the "view" over there, you'd even see something on the screen)

edit edit: I'll expound that map call in detail:

map(
    offsetx/8,
    offsety/8, --[[offset is in 
    pixels. here divided by 8 to 
    convert to tiles. if x is 8 to
    15 inclusive, i'll get the 
    proper 1 tile i need to move 
    the view of the map by.]]
    0-offsetx%8,
    0-offsety%8,--[[so if my x 
    offset is one pixel, the 
    remainder is 1 and the position
    of the map is shifted one 
    pixel left off of the screen]]
    17,17--[[just big enough since 
 there's always 1 to 8  pixels 
 spare pixels offscreen in  the 
 positive direction]]
)
P#29993 2016-10-04 14:18 ( Edited 2016-10-04 18:35)

I'm using CLIP() merely cause I hate even-numbered screens. Gotta have a natural center tile. :)

Tyroney, what would be a source code example of using camera() to duplicate the above effect ?

... ???

Wait. I think I just got it.

camera(i,0)
map(0,0,4,4,999,999)

Well now that is interesting ! Camera being able to scroll to any point on a MAP and no modulos needed !

This also works:

map(0,0,4-i,4,999,999)

I guess it's just a matter of preference.

P#29995 2016-10-04 14:22 ( Edited 2016-10-04 18:32)

Drawing offscreen is automatically clipped, but that doesn't make it free. (As far as I know)

I would suggest never drawing 999 tiles of map.

P#29996 2016-10-04 14:34 ( Edited 2016-10-04 18:35)

Likely good advice there. To handle Zelda-style scrolling, all I would really need is the space of 30x30 tiles. And if I wrote my own mapper routines, zero.

MAPPER space is something entirely new to me and no other game programming language I've worked with ever had it.

Question. Can you do MODE 7 with this mapper area ?

P#29997 2016-10-04 14:40 ( Edited 2016-10-04 18:40)

If you're talking about map(), it only draws a chunk of tiles to the screen at a position. No scaling, no rotating, no nothing. (I guess pal() is sort of a variation, but not much of one)

P#29998 2016-10-04 14:53 ( Edited 2016-10-04 18:53)

What would be the easiest way to create a MODE 7 effect from a map ?

Oh, and here is the MAPPER with 4-screens, scrolling around them.

Cart #30006 | 2016-10-04 | Code ▽ | Embed ▽ | No License

P#30000 2016-10-04 15:21 ( Edited 2016-10-04 19:28)

I have a minor correction to the comment near the end of your code. after line 36, insert:

035-- note that you can only
036-- 'scroll' in steps of 8,
[b]037-- [i](if you hard code your map()[/i]
038-- [i]call to screen pos [4,4] )[/i][/b]
P#30008 2016-10-04 15:40 ( Edited 2016-10-04 19:41)

Can make that adjust. That's fine. :)

P#30011 2016-10-04 15:50 ( Edited 2016-10-04 19:50)

[Please log in to post a comment]

Follow Lexaloffle:          
Generated 2024-03-29 13:56:51 | 0.014s | Q:28