The above video goes away if you are a member and logged in, so log in now!

 Would you like to get all the newest Gaming News fromQJ.NET in your email each day? Want to learn more about the team who brings you the QJ news?

## Help? Best way to create and redraw ingame world map

This is a discussion on Help? Best way to create and redraw ingame world map within the PSP Development Forum forums, part of the PSP Development, Hacks, and Homebrew category; Ya, I've done that, but the End's are too high when I move. Like, the further I move right, then ...

 Tweet
1. Ya, I've done that, but the End's are too high when I move.
Like, the further I move right, then high it goes out of bounds.

I'm thinking of just subtracting i from it, but I dont think it'll turn out right...

2. do the CaXLimit thing and just stop pushing it over when you hit the limit.

3. Originally Posted by chrisp6825
You can index a 1D array like a 2D array, thats why I changed it, it seemed you thought it was better to, since your example used a 1D array.

mapLayout[y*mapwidth+x]

edit: you, as in slicer, sorry.

sry had to go to work, anyways i quickly whipped it up, and went with 1D simple because i was creating a square tileset, anywho, to ensure that it stays withing bounds, simple change the update bounds function to:

Code:
```tileStartX = math.floor(CaX/w) --don't need to add 1, the array can start at 0
tileStartY = math.floor(CaY/h)
tileEndX = tileStartX + math.ceil(480/w)-1 --this however you do need to subtract 1
tileEndY = tileStartY + math.ceil(272/h)-1
if(tileStartX < 0) tileStartX = 0;
if(tileStartX > w-1) tileStartX = w-1;
--repeat for tileStartY, and tileEndXY```
now you shouldn't go outside your boundry's

4. actually, it cant start at 0. It'll give an error...
but I've figured it out.. it may be a little messy..
Code:
```function updateTileLimits()
CaX = map.x;
CaY = map.y;
CaXLimit = 30*w-240
CaYLimit = 30*h-144
if CaX > CaXLimit then map.x = CaXLimit; map.xDes = map.x end
if CaY > CaYLimit then map.y = CaYLimit; map.yDes = map.y end
if CaX < -224 then map.x = -224; map.xDes = map.x end
if CaY < -128 then map.y = -128; map.yDes = map.y end

tileStartX = math.floor(CaX/w)+1
if tileStartX < 1 then tileStartX = 1 end;
tileStartY = math.floor(CaY/h)+1
if tileStartY < 1 then tileStartY = 1 end;
tileEndX = math.floor(CaX/w)+1 + math.ceil(490/w)-1
if tileEndX > table.getn(mapLayout[1]) then tileEndX = table.getn(mapLayout[1]) end;
tileEndY = math.floor(CaY/h)+1 + math.ceil(282/h)-1
if tileEndY > table.getn(mapLayout) then tileEndY = table.getn(mapLayout) end;
end

function drawMap()

CaX = map.x;
CaY = map.y;
CaXLimit = 30*w-480
CaYLimit = 30*h-272

if map.x ~= map.oldXDes or map.y ~= map.oldYDes then updateTileLimits() end; -- if map has moved, or is moving

for i = tileStartX, tileEndX do
for j = tileStartY, tileEndY do
screen:blit((i-1)*w-CaX, (j-1)*h-CaY, img[mapLayout[j][i]]);
end
end

end;```

The only problems now is the speed issues of printing and reprinting of luaplayer. I've fixed the bounds problem.
I'm thinking about switching it to PGE soon, when I'm done with my engine, but my internet right now is pretty shardy. So, it may have to wait, since I can't look things up as fast as I'll need to.

-=Double Post Merge =-

So, I'm using a tile map editor called Mappy or MappyWin...
I was wondering if you know of a better map editor, or if you prefer making you own..?

So far, Mappy is pretty good, and I can custom export in plain text pretty nicely.. But now I'm looking for one that can make separate maps, and combine them easily.

If anyone recommends any map editors, please let me know.

By the way, I got my map engine working pretty good now without any real problems. Thanks a ton. You guys helped me learn a lot more about arrays and indexing them more efficiently, and tile maps. The only thing holding me back now is luaplayer, which I'm likely to dump anytime now.

5. Hey guys, I need a little tip or something...
When I'm drawing a small map (about 17 tiles x 12 tiles room) I can get around 60 frames a second.
But if I fill the screen up, I get way lower speeds ( 20 fps with 30 tiles x 15 tiles on the screen at a time)

I was wondering if you guys might know a way to speed it up a bit? Like, any tips? I've switched over to PGE and have gone over the code, cleaning it and trying to find shortcuts to speed it up.

Thanks.

6. make sure the images are swizzled, and have a clut with them(don't know if pge does this inheriantly, or if u have to define the images to build a clut and swizzle with them), anyway i'm not sure how'd u define that in pge, but that sounds like wat could be mostly the issue, if you also can control what image is binded i'd suggest having a check on making sure you don't re-mount the same image=-), but again using pge alot of the things i just said could be meaningless to you

7. Well, I can control the swizzling. But I don't know what clut is.
And I don't think I can check what image is activated, but I'm sure I can work on something for that.

Thanks a ton. I'll check it out.

edit:
Well, controlling the image activation helped quite a bit.. In some areas it jumped up from 20 to 30, which is pretty fine for now.
But I've figured out what really slows it down is the activating and drawing of my trees..

When it draws the trees, it draws them like this :
Code:
```19, 20, 19, 20, 19, 20, 19, 20
17, 18, 17, 18, 17, 18, 17, 18
15, 16, 15, 16, 15, 16, 15, 16```
The trees have 6 parts to them: top (19 & 20), middle (17 & 18), bottom (15 & 16), with left and right sides.
So, I'm thinking of either throwing these trees out, or finding a way to just go through the tiles that will be shown on screen and draw them...
Like, draw every 19, then draw every 18, and so on...
Does that sound like a good idea? Or do you think it'll just end up slowing it down more?

8. Originally Posted by chrisp6825
So, I'm using a tile map editor called Mappy or MappyWin...
I was wondering if you know of a better map editor, or if you prefer making you own..?

So far, Mappy is pretty good, and I can custom export in plain text pretty nicely.. But now I'm looking for one that can make separate maps, and combine them easily.

If anyone recommends any map editors, please let me know.
You want Tiled. It can export its maps to a lua script.

9. Hi guys. I'm back with a question..

I've been getting a bit of a slow-down when printing the outdoor map with the function you guys help me build. When printing tiles across the entire screen, I get about 20 fps. I found out that if I cut out 2 rows across the screen (drawing 480 tiles, opposed to 510) I got around a full 60 fps.

To clear some things up though, I'm taking the tile source and cutting each tile up into 16x16 pieces and storing them into an array. Then I index the map array and find the "tile number" and print the according tile.

img[mapLayout[j][i]]:draweasy((i-1)*w-CaX,(j-1)*h-CaY);

But some people suggested, and I thought, that it'd be better to just load the whole tile source and index the map array, then print a 16x16 part of the whole tile source.

Imgpallet:draw((i-1)*w-CaX,(j-1)*h-CaY,16,16,((mapLayout[j][i]%(Imgpallet:width()/16))*16)-16,(pge.math.ceil(mapLayo ut[j][i]/(Imgpallet:width()/16))*16)-16,16,16);

That's what I came up with for drawing the map using the second option. It works, but there are 2 problems.
One : any tiles that are located at the far right column of the tile source end up wrong when printed.
Two : It turns out slower than the original function (by ~3 to ~5 fps).

I know the reason for the first problem. It's because it works on remainders, but if the tile is at the end, then there is no remainder, so it returns 0 as the X position on the tile source sheet, and then minus 16 since the way I indexed them. So this isn't a Major problem.

The second problem is a Major problem. So far, I haven't been able to get over ~20 fps when printing 510 tiles on the screen. Is this a limitation of PGE, or Inefficient coding?

10. The problem is both all the math youre doing and the fact that youre doing 510 different draws per loop....

Page 2 of 2 First 1 2

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•

All times are GMT -8. The time now is 12:13 AM.

Use of this Web site constitutes acceptance of the TERMS & CONDITIONS and PRIVACY POLICY