Wraparound scroller only goes one way
Blitz3D Forums/Blitz3D Programming/Wraparound scroller only goes one way
| ||
I have recently been trying to create a wraparound scroll system like Defender's and have downloaded some sample code that I have tried to convert. I have had a bit of success as it now wraps endlessly to the right. However, when I scroll to the right, turn round and go back to the left, the map stops at its origin, I assume because the render routine is only designed to go one way. Can anyone help or give me some advice on this? Here is the current render routine: Function RenderMap (map%, x_offset%, y_offset%) ty% = y_offset / TileHeight (map) sy% = -(y_offset Mod TileHeight (map)) While sy < SCREEN_HEIGHT ty% = ty Mod MapHeight (map) tx% = x_offset / TileWidth (map) ; tile x ? sx% = -(x_offset Mod TileWidth (map)) ; screen x ? While sx < SCREEN_WIDTH tile% = GetTile (map, tx Mod MapWidth (map), ty Mod MapHeight (map)) DrawTile map, sx, sy, tile ; tx = tx + 1 sx = sx + TileWidth (map) Wend ty = ty + 1 sy = sy + TileHeight (map) Wend End Function If you need more of the code I can post that too. Many thanx Bungee |
| ||
Pretty hard to see what's going on. Perosnally I'd rewrite it from scatch. Shouldn't be that hard. In this code I cannot determine what is the variable for the players position. I also have no idea what this GetTile(... should do. Basicly I see a lot of MOD commands. they usually wrap things in one direction only. If you want it in both directions, you need to do it manually, eg: x=(x+7) mod 100 ; x will always be between 0 and 100 the same without to use MOD: x=x+7 : if x>100 then x=x-100 to make this work in both directions (when you don't know if something was added to x, or of it was subtracted from it) you should do this: if x>100 then x=x-100 if x<0 then x=x+100 So it is now "wrapped" in both x directions. But I really don't know if a MOD command in your code is really the problem, and if so wich one. Btw: welcome on this forum! |
| ||
Thanks for your reply jfk, however, someone else has already helped me on another forum. His solution was similar to yours. I wish I knew more about this Mod command though. As far as I can make out it simply returns the remainder after a number has been divided by another the max amount of times. e.g. 100/33=3.03 so Mod gives .03 How is this used in scrolling? Thanks, Bungee |
| ||
100 mod 33 = 1 Remember the 3rd grade way of doing division? 3 --- 33/100 99 -- 1 <- Remainder So 100/33 is 99 with a remainder of 1 Now that's handy in scrolling because as the numberator increases in value, the remainder increases from 0 to denominator - 1 then wraps again to 0. So 0 mod 3 = 0 1 mod 3 = 1 2 mod 3 = 2 3 mod 3 = 0 4 mod 3 = 1 5 mod 3 = 2 6 mod 3 = 0 You see a pattern here? Now when scrolling a screen, suppose the playfield is 100 cells wide and the screen it's displayed on is 25 cells wide. If the left side of the screen is on cell 10, then the right side would be on cell 24. But if the left cell is on 90, then the right cell would be on 114, 15 cells further than what you have. But with Mod, that represents no problem. 114 Mod 100 = 14. The rightmost cell displays cell 14. You just wrapped around. |
| ||
Thanks TomToad that's a little bit clearer. :) I'll get it eventually. Bungee. |