Jump to content


Photo

A map made of surfaces


  • Please log in to reply
5 replies to this topic

#1 ApplePiePod

ApplePiePod

    GMC Member

  • New Member
  • 406 posts

Posted 14 August 2010 - 10:44 PM

var l,r,t,b;

l = floor((view_xview[0]+0.01)/256)
r = ceil((view_xview[0]-0.01)/256)
t = floor((view_yview[0]+0.01)/256)
b = ceil((view_yview[0]-0.01)/256)

if surface_exists(ds_grid_get(grid,l,t)) {
    draw_surface(ds_grid_get(grid,l,t),l*256,t*256)
} else {
    draw_sprite_ext(s_warningchunk,0,l*256,t*256,2,2,0,c_white,0.5)
}

if surface_exists(ds_grid_get(grid,r,t)) {
    draw_surface(ds_grid_get(grid,r,t),r*256,t*256)
} else {
    draw_sprite_ext(s_warningchunk,0,r*256,t*256,2,2,0,c_white,0.5)
}

if surface_exists(ds_grid_get(grid,l,b)) {
    draw_surface(ds_grid_get(grid,l,b),l*256,b*256)
} else {
    draw_sprite_ext(s_warningchunk,0,l*256,b*256,2,2,0,c_white,0.5)
}

if surface_exists(ds_grid_get(grid,r,b)) {
    draw_surface(ds_grid_get(grid,r,b),r*256,b*256)
} else {
    draw_sprite_ext(s_warningchunk,0,r*256,b*256,2,2,0,c_white,0.5)
}

Okay, I have a grid built up of surfaces, which correlate together, making a map.
When you scroll around the map, I only want to draw the visible surfaces, instead of rendering the whole grid of surfaces.
My code causes the map to flicker when the scroller is looking directly at the boundary between surfaces.

Please, can anyone help fix this?

Thanks, Ruirize.

EDIT: The surface checking is there for older computers, where the surfaces aren't always created. I will fix this eventually, but tbh, I cba right now.

Edited by ApplePiePod, 14 August 2010 - 10:45 PM.

  • 0

#2 ragarnak

ragarnak

    GMC Member

  • Retired Staff
  • 19468 posts
  • Version:GM8

Posted 15 August 2010 - 07:59 AM

Please, can anyone help fix this?

Could you explain what those "l","r","t" and "b" variables are supposed to signify ?

The only thing I can make outof that is that you look, with a deviation of +/- 0.01 pixel, at which ds_grid cell corresponds with the top-left of the view.

Maybe a simple
cx = round(view_xview[0]/256)
cy = round(view_xview[0]/256)
would work better (and only draw once instead of four times) ?

Hope that helps.
  • 0

#3 ApplePiePod

ApplePiePod

    GMC Member

  • New Member
  • 406 posts

Posted 15 August 2010 - 10:02 AM

The surface sizes are smaller than the screen, and so, need to be drawn in all four directions.

l = left
t = top
r = right
b = bottom

The rest should be easy to work out.

EDIT: Wait why on earth was this moved? I provided code, as per the requirements for posting in the advanced section!

Edited by ApplePiePod, 15 August 2010 - 10:03 AM.

  • 0

#4 ragarnak

ragarnak

    GMC Member

  • Retired Staff
  • 19468 posts
  • Version:GM8

Posted 15 August 2010 - 02:00 PM

The surface sizes are smaller than the screen, and so, need to be drawn in all four directions.

l = left
t = top
r = right
b = bottom

In all four directions with the center (of those four tile) being the Views upper-left corner ? That would mean that three of those four would be drawn outside of the View, and thus invisible to you ....

But that isn't even what you are doing : for most of the time (when the Views origin is just a bit inside a 256x256 square) you draw the same image mutiple times, as the "l" and "r" as well as "t" and "b" will hold the same value.

The rest should be easy to work out.

Well, no.

Although I can see what the code does I have absolutily no idea what you where attempting to do, or, at this moment, why you think the "draw in four directions" is actually what it does .... As I allready mentioned I think you just draw the same Surface/Sprite multiple times at the same position.

So, I would invite you to explain/describe what you think your code is doing and how.

EDIT: Wait why on earth was this moved? I provided code, as per the requirements for posting in the advanced section!

Yes, you did provide code. But thats not the only requirement for being allowed to post in the Advanced subforum. This one is important too :

Explain what you have tried to solve the problem,

And yes, I did doubt for a moment if I should actually move your question. But as your code does something quite different from what you think it does it (and you not finding that out for yourself means that you did do little or even no testing/bug-hunting) chinched the knot for me.

But I must confess that your question is written better than some others I move to Novice/Intermediate. :)

P.s.
Change, as a test, all "view_?view[0]" entries into "view_?view[0]+128" and look at what happens. My "guess" is that you will mostly only see a single tile, and only when you are ontop of the boundary you will (maybe) see another tile flickering. To make the flickering effect become more pronounced change those "+0.01" and "-0.01" into something larger, like +8 and -8 .
  • 0

#5 ApplePiePod

ApplePiePod

    GMC Member

  • New Member
  • 406 posts

Posted 15 August 2010 - 04:39 PM

I fixed it myself, in the end.

Thanks anyways.
  • 0

#6 ragarnak

ragarnak

    GMC Member

  • Retired Staff
  • 19468 posts
  • Version:GM8

Posted 15 August 2010 - 04:45 PM

I fixed it myself, in the end.

I'm curious, what did you do/change ?

Thanks anyways.

:)
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users