Qbasic "like" compilers/interpreters => FB Discussion & Programming Help => Topic started by: Foolish__1 on June 02, 2005, 02:31:54 PM

Title: Panning...
Post by: Foolish__1 on June 02, 2005, 02:31:54 PM
Hey all,

I have a bit of what many of you would call a 'basic' question...  Sigh.  I'm tring to make an RPG (how unique, en?) and I want it to pan, none of the Zelda style walk to the edge of the screen and get pushed over.  So, any-hoo, the game is obviously made up of tiles.  Now, I've run some 'tests' (I.E. made a program that did exactly this)  and the way it worked is if you pused, say 'up' It would load the tiles that were one row above the area you were in and slowly slid the whole thing down.  Now this system works fine BUT when you push 'UP' there is a small delay (as it loads the tiles into memory and such).  This is only a problem when holding up to keep walking up.  It's a very jerky walk.

I've done this kinda of stuff in C and it was done using a massive virtual buffer that first loading the entire map/town/dungeon/whatever and, well, you guys know how that works.  Any way, how do I do that in FB?  What's the best way to do something like this in FB?

My second question, what do VIEW and WINDOW do and how do they work?  I just don't get them at all?  It there a good command reference somewhere?

Thanks all!


Title: Panning...
Post by: SotSvart on June 02, 2005, 03:02:19 PM
Try this link for a alphabetical list of FBs keywords:

Title: Panning...
Post by: Antoni Gual on June 02, 2005, 04:31:13 PM
I never saw RTFM written so politely!    :rotfl:

Foolish I, you can do the same things you did in C. Yo can use ALLOCATE, pointer indexing,...
You can do it gfxlib way, creating a big PUT buffer with IMAGECREATE, drawing all your tiles into it and PUT it to screen at differnt coords as your character moves...

Title: Panning...
Post by: Anonymous on June 02, 2005, 11:36:35 PM
 camerax% = char[0].x - (302 \ 2) - 1
  IF camerax% < 0 THEN camerax% = 0
  IF camerax% > ((map[0].room[char[0].currentroom].x) * map[0].tileset.x) - 320 THEN camerax% = ((map[0].room[char[0].currentroom].x) * map[0].tileset.x) - 320

  cameray% = char[0].y - (190 \ 2) - 1
  IF cameray% < 0 THEN cameray% = 0
  IF cameray% > ((map[0].room[char[0].currentroom].y) * map[0].tileset.y) - 200 THEN cameray% = ((map[0].room[char[0].currentroom].y) * map[0].tileset.y) - 200

  xtile% = camerax% \ map[0].tileset.x
  ytile% = cameray% \ map[0].tileset.y

  xoffset% = camerax% Mod map[0].tileset.x
  yoffset% = cameray% Mod map[0].tileset.y


  FOR tiley% = 0 TO 208 Step map[0].tileset.y
    FOR tilex% = 0 TO 320 Step map[0].tileset.x
      tiletoputx% = tilex% \ map[0].tileset.x + xtile%
      tiletoputy% = (tiley% \ map[0].tileset.y + ytile%) * (map[0].room[char[0].currentroom].x)
      tileindex% = tiletoputy% + tiletoputx%
     put (tilex% - xoffset%, tiley% - yoffset%), @map[0].tileset.image[(map[0].room[char[0].currentroom].layout[layertoput%][tileindex%] and 255) * map[0].tileset.arraysize], trans



look at this for a long time, and experiment until it makes a little bit of sense. if it never does, sorry. ill explain this stuff in detail, someday. theres other tuts out there about it. look for em

Title: Panning...
Post by: Foolish__1 on June 09, 2005, 04:40:11 PM

Thanks!...  But I still have some questions.  First, what does 'RTFM' mean?  Perhaps I'm a little slow, but?  SEcond, Okay, basically I wast to create a buffer larger than the screen.  Now, I've tried and tried to get this IMAGECREATE command to work, but I just can't.  I've read quite a few tuts on it an dbeen through command references, but It just won't work for me.  Does anyone have a sample of it doing just this?  Thanks again!


Title: Panning...
Post by: Anonymous on June 09, 2005, 05:17:47 PM
rtfm = read the f___ng manual xD

Title: Panning...
Post by: Torahteen on June 09, 2005, 05:19:22 PM
:rotfl: Oh! LMAO, now I get it :wink: .

Title: ............
Post by: Foolish__1 on June 18, 2005, 02:43:42 PM
Hey, it's me, again,

Okay, I've tried to get IMAGECREATE to work, but I can't.  Every example that I can find on the internet start like this:


Which gives me an error.  If I get rid of that command, none of the other commands work.  Next, I can't do it the way that your example lays out because the tiles have four layers, and are 27*27 at 640*480...  It's just too slow to draw a new row each time.  I have to do it in a similar way to IMAGECREATE.  Sigh.  Does anyone have an example of this actually working, in FB?  Or perhaps a tut on this topic, again for FB, unsing a large buffer like I'm asking...  Because I can't find one...  Please help!!!


Title: Panning...
Post by: TheBlueKeyboard on June 18, 2005, 03:37:08 PM
Sorry, Im a bit confused
are you trying to make a tile*tile or pixel*pixel scrolling engine?

Title: Panning...
Post by: Foolish__1 on June 19, 2005, 04:37:31 PM
Well, both.  When your character moves left, he moves one full tile (27 pixels), but it pans one (or two) pixels ata  time, to make a more smooth transition.

Title: Panning...
Post by: TheBlueKeyboard on June 19, 2005, 06:53:31 PM
You really dont have to load mapdata on-the-go anymore with FB.
It would be easier and probably work better if you just make one large map array at the start of your program
something like this:


DIM Map(499, 499) AS INTEGER 'That should be sufficient ^^

'then u can just load into Map(X, Y)
LoadMap bla.map


SUB LoadMap (temp.File$)
'appropriate map loading code here which loads

SUB DrawMap ()
'approprite tile placement code, just read Map(X, Y)

Title: Panning...
Post by: Foolish__1 on June 21, 2005, 08:45:58 PM
Umm, this is what I've tried, and becasue there are four drawn layers, per tile, it ends up being too slow.  When you push, say 'up', it then draws the row of tiles, all four layers, and then moves your character.  It's fine in principal, but in reality it doesn't work.  What happens is if the player hold the up key, the character takes very obvious, jerky steps (after each tile is crossed) and I would like to avoid this as much as possible.  It's a great idea, but in this case just not practical...

I really just need to know how to a make a 'put' array bigger than the screen that I can write directly too.

Title: Panning...
Post by: SotSvart on June 22, 2005, 12:37:26 AM
You can use IMAGECREATE to make a buffer larger then the screen, and acces it like this: Put Buffer, (x,y), ImgArray(0), PSET

Look up IMAGECREATE and IMAGEDESTROY, in gfxlib.txt. There should also be some examples on how to use a GET/PUT image as a Screen Buffer.

Title: Panning...
Post by: TheBlueKeyboard on June 22, 2005, 12:12:55 PM
Yes, but are you drawing the entire, say, 500*500 tiles each time, or do you take the little bit of the map that the screen represents and show that?

Assuming the tiles are 16*16:


SUB DrawMap ()
FOR Layer% = 0 TO 3
StartXTile& = Camera.X \ 16
StartYTile& = Camera.Y \ 16
StartXPixel& = Camera.X MOD 16
StartYPixel& = Camera.Y MOD 16
FOR YTile& = 0 TO 21
FOR XTile& = 0 TO 13
Tile% = Map(XTile& + StartXTile&, YTile& + StartYTile&, Layer%)
PUT (-StartXPixel& + XTile& * 16, -StartYPixel& + YTile& * 16), Tiles(Tile%)

Title: Panning...
Post by: Foolish__1 on June 22, 2005, 02:44:48 PM
Right now, it only draws the new strip of tiles that need to be.  What happens is the program starts, loads the map into memory, draws the screen.  Then, when you say, move up one tile, it draws that one strip of tiles at the top of the screen, and erases the one at the bottom of the screen.  It's too slow.  The second reason I want to be able to draw buffers larger than the screen is I  am hoping that I can place 'off the screen'...  So that half of the 'put' would be off the screen (hence invisable) and the other half on the screen.  Reason being, is on top of tiles, we want to have larger animation overlayed...  Say a waterfall, or waterwheel...  Perhaps a fire.
The trick is getting this all to work.  It seems it's more difficult than once thought.

Title: Panning...
Post by: DrV on June 22, 2005, 02:51:54 PM
Look at gfxlib.txt (http://cvs.sourceforge.net/viewcvs.py/fbc/FreeBASIC/docs/gfxlib.txt?view=markup) for the official documentation (information about and an example of IMAGECREATE is in there).

Title: maybe the best way is not always the easiest way....
Post by: thesanman112 on June 25, 2005, 09:55:36 PM
well i think i understand what the problem is....your wanting to draw a scroller but have player able to move to edge of screen.. like the original zelda.. if this is correct then it should be easy...
maybe the best way would be to use the opengl commands....

but forget that for a second... you want to scroll the screen, therefore you need screen to write...imagine the whole world you want to make...now imagine the field of view of player, or screen coverage on that world...say 5 tiles left,5 tiles right,5 tiles down,amd 5 tiles up...now every move that you make keeps track of the tiles....+5 and -5 so when player goes beyond the border or field of movement, then you calcualte 5- and 5+ around player..roll them onto the screen opposite of movement...I have done a 360 degree scroller, but the player stands in the middle all the time and the screen moves around you...and i use 640x480 bitmaps.. always drawing 9 at a time some partially on screen[/code]

Title: Panning...
Post by: Foolish__1 on June 27, 2005, 02:17:20 PM
Well, not quite.  I want a scroller where the character stays in the middle of the screen at all times.  Think Final Fantasy 4 (American 2).  That's what I want to do.  That's it, that's all.  See to be quite the challenge though....  Sigh.  I've looked into this IMAGECREATE command, and it appears to be what I need.  However, I can't get it to work.  I'm running FB 1.3 and I use the example in GFXLIB...  but it won't complie...  Why?!

Thanks again!

Title: Panning...
Post by: TheBlueKeyboard on June 28, 2005, 07:17:25 PM
You dont need to load mapdata ingame.
Just load it at the start into a big buffer, say, map(299, 299).
Then you wont have to read anything as its all in the buffer.

If I understand you correctly, what you want to do is make a huge bitmap with the map pre-rendered and simply pan it as you move the player?

Sorry if I misunderstand, Im still a bit confused :)

Title: Panning...
Post by: Foolish__1 on June 28, 2005, 09:10:18 PM
YES!!  That's what I want to do!  YES!!  But, think bigger...  Tiles are 27*27 pixels, and the largest area would be something like 2500 * 2500 tiles....

Title: Panning...
Post by: TheBlueKeyboard on June 29, 2005, 07:14:08 AM
But why dont you make a true pixel scrolling engine with the map already stored in a big buffer? Would be much faster...and easier.

Title: Panning...
Post by: Foolish__1 on June 29, 2005, 06:26:28 PM
Juh?  Let me see if I get you right...  Say I wanted to make an area that was 2500 X 2500 tiles, each tile being 27*27 pixels, I would make an arrya that was (2500  * 27 = 67500) 67500 X 67500, and just used that?  Then keep track of the location of the player in a 2500 X 2500 array?  Interesting idea.  Is that what you meant?

Title: Panning...
Post by: TheBlueKeyboard on June 29, 2005, 06:43:52 PM
Umm...I dunno if you have lots of time on your hands, but 2500*2500 = 6 250 000. Thats over six million tiles you'll have to map :).

But no, you only store the tile index number, not the actual tiledata.

Dim Map(2499, 2499) As Integer

And to keep track of the player:


TilePlayerIsOn = Map(int(PlayerX / 27), int(PlayerY / 27))

Title: Panning...
Post by: Foolish__1 on June 29, 2005, 08:51:55 PM
Well, the screen is 23 by 17 tiles, so that's about 100 screens by 100 screens.  It's big, but keep in mind that it has to store the world map in that buffer, so I think it's reasonable.  Now, if I don't store the actual tiles in a buffer, they are just too slow to draw, so I'm back at square one.  That said, can anyone get IMAGECREATE to work?

Title: Panning...
Post by: TheDarkJay on July 01, 2005, 02:06:03 PM
PLEASE NOTE: If this isn't what you want, sorry, just ignore this post.

So you want to load it tile by tile and the player stays in the middle? just use numbers to represent the tiles in the map array and out them in a CASE like

SELECT CASE tiletoput


PUT (x * 27, y * 17), tile1


PUT (x * 17, y * 17), tile2

'and so on.


You would need to have the screen x size a multiple of 27 and the screen y size a multiple of 17 (you could rely on FB clipping the tile though)

When i get to my pc at home i'll whip up an example.

Wouldn't this look terribly jumpy though?

Umm, and pixel by pixel isn't slow to draw?
FB is more than fast enough to handle this.

Title: Panning...
Post by: Foolish__1 on July 02, 2005, 08:46:46 PM
FB is faster than QB, but it's too slow for what I'm doing.  There are four gfx layers involved, per tile.  And in order to achieve smooth paning, it would all have to be pre-loaded.  I've tried what you've said, and it ain't gonna fly.  Thanks though.

So, still, no one know how to use IMAGECREATE?


Title: Panning...
Post by: TheBlueKeyboard on July 02, 2005, 09:21:09 PM
Ok, it seems like that you cant go beyond 8191*8191.

'Set screen mode
screen 18, 32,, 1

'Make the pointer that points to the buffer in memory.
Dim Buffer As Any Ptr

'Create the buffer and fill it with bright red color.
'8191*8191 was the biggest I could get to on my computer without crashing...
Buffer = ImageCreate(8191, 8191, rgb(255, 0, 0))

'Place down the buffer at (0, 0)
put (0, 0), Buffer, Pset


'Destroy buffer
ImageDestroy Buffer

So it seems like you're stuck with two options:

1. Split the screens into smaller 8191*8191 buffers.

2. Make a true pixel by pixel scrolling engine.
I'm 100% sure this can be done fast enough, I could even make a pixel*pixel scrolling engine with 4 layers for you. :)

Title: Panning...
Post by: Foolish__1 on July 03, 2005, 10:15:17 PM
Perhaps I'm stupid, but I got this far.  I have FB 1.3 and this is what I get when I compile that code:

buff.bas(9) : error 71: Array not dimensioned, befr: '('

Buffer - ImageCreate(8191, 8191, rgb(255, 0, 0))

This is why I can't get IMAGECREATE to work.  No matter what, this is what I get...  unless I...

change: Buffer = ImageCreate(8191, 8191, rgb(255, 0, 0))
 to: Buffer = ImageCreate(8191)

But, this, of cource, renders that line useless...  So back to square one...

Sigh.  Any ideas why?


So, a pixel scroller, how does that work?

Title: Panning...
Post by: TheBlueKeyboard on July 03, 2005, 10:55:30 PM
This is a shot in the dark, but I would try downloading 0.14 and see if that works...just to try.

A pixel scroller...well, first you would load the tiles, and just plot it down. I can make an example pixel*pixel scroller with multiple layers for you if you want.

Title: Panning...
Post by: Foolish__1 on July 05, 2005, 02:08:14 PM
I would love to see one that worked.  Here's what I'm working with.  There are different areas in the game.  dungeons, towns, world map, ect. that each have their own tileset.  So, for each place, there is a master tile file that hold all the tiles, and all the information reguarding the tiles.  If it's an animated tile, is it passable, not passable, ect, as well as the actual tile pixel layout.  Now, there are two basic types of tile in our game, underlay and overlay.  Underlay is the groupd, overlay is everything on the ground.    Now, say you wanted to have a burning candle stick.  You would first put down a floor tile, then an overlay tile of a candlestick, then a second overlay tile that was animated of a burning small flame over all of that.    Tiles are 27*27, screen is 640 X 480 with a bit loeft over on all four sides.  

Good luck and thanks!

Title: Panning...
Post by: Anonymous on July 05, 2005, 07:15:11 PM
lol, i wouldnt expect anyone to make one for you. wait until i finish LL, you'll have something to look at (ill release source, of course)

anyone whos seen it will tell ya its smooth as

Title: Panning...
Post by: Foolish__1 on July 05, 2005, 09:47:28 PM
ll?  What's that?  I'm not expecting someone to make it for me.  Just give mw the concept behind it.

Title: Panning...
Post by: Anonymous on July 06, 2005, 01:44:10 AM
the concept? arrange everything linearly, and then put it on screen the right way. fb is not slow. i do 4 layers, with event detection, enemy ai, etc. and i still get about 3 or 4 out of 8 cycles free, no joke

Title: Panning...
Post by: Foolish__1 on July 20, 2005, 10:24:05 PM
Sorry its been so long, but I was out of town, and didn't have a chance to get to this site.  Well, I guess I'm dense, but what do you mean by 'arrange them linearly'?  I get the tiles, but arrange them where?

See what I'm getting at?


Title: Panning...
Post by: dumbledore on July 21, 2005, 02:21:01 AM
there's an article about scrolling in qbe 12, try this link: http://www.petesqbsite.com/sections/express/issue12/index.html#platformer