Scrolling breaks at 0,0 origin!
BlitzMax Forums/BlitzMax Programming/Scrolling breaks at 0,0 origin!
| ||
Move to 330,316, at that point the upperleft corner of the screen is arround 0,0. What happens is that you can move 64px arround the 0,0 instead of 32. Just keep an eye on the red X Y counters, and move up from 330,316. You will see it allows you to move 64px without moving the grid!!. it should have moved!! It has todo with some math in the RENDER LAYER function and a division by 0 so i guess, i have no clue really and totaly lost it after a long day of debugging... its driving me crazy by now. Everything else works so dont bother checking other functions. |
| ||
See the problem is related to the fact that we work below 0. Look, if you do a division above 0, your value goes down. 6/3 = 2 (from 6 to 2) a decrease If you do a division below zero, your value goes up. -6/3 = -2 (from -6 to -2 ) an increase I need it to go down! (maintain the decrease) A solution could be to check if its a negative value, and if so, substract an extra 32px. But it doesnt feel right... -EDIT- doesnt work. see where in a 0 zero tile. you can check if 0 is lower then 0. |
| ||
abs?* *Disclaimer: I haven't read the code, so don't actually know if this will solve the problem, I'm just guessing. |
| ||
nope. abs is not relative to this issue. It has todo with truncating towards 0, something i need to reverse when i, below 0. Im gonne play a bit more with the floor function. |
| ||
ugh.. didnt work. anyone? -EDIT- playing arround with this made some changes, but still not fixed. If oX>0 tX:-1 If oY>0 tY:-1 |
| ||
. |
| ||
heck, i will just throw an offset in the whole application of 144000 px to prevent me from running below zero. :S i spend over 12 hours, im really pissed. stupid negative values. |
| ||
I couldn't find any obvious way around it. The problem is, a negative less than 32 will give 0 when divided by 32 and so does a positive division. one way to do it's, lets say, it is moving in the positive direction, and the previous position was less than 0 and the new position is greater than 0 than add 32 to the direction being affected. the same principal applies when going the oposite direction. anyway that is the only solution I can think of. [edited] not quite what I thought but close. see below. |
| ||
|
| ||
I see your point. I tried this as well but on the render_layer level. I succeed, however, it is still a manipulation, when i applied it to the game, it wouldnt work out... yes, the grid worked, but everything else wouldn't as if it noticed the grid was manipulated. What i did is, on top of the renderlayer() local oldx:int=x local oldy:int=y if oldx>0 then x:+32 if oldy>0 then y:+32 then just before drawing i had to reset it if oldx>0 then x:-32 if oldy>0 then y:-32 See the result, works perfect, but not in the game :S |
| ||
Hah, heck, after 16 hours i got it. We noticed the problem had todo with division. The only place in the render function where a division was preformed was here: Local tX:Int = vX + (oX / 32) Local tY:Int = vY + (oY / 32) I just hacked that to force a division above 0. Local tX:Int = vX + ((oX + 32000000) / 32) - 1000000 Local tY:Int = vY + ((oY + 32000000) / 32) - 1000000 This way i dont manipulate the grid. w00t! and it works without issues. |
| ||
ok. if i push it higher then 320000000 the game freezes. Why is that? does it have todo with a memory range? |
| ||
I invented 2 new functions, basicly its a Floor and Ceil function, but you can specify the size, and it works with ints as well.Function SuperFloor:Int(val:Int, size:Int) While (val Mod size) <> 0 val:-1 Wend Return val End Function Function SuperCeil:Int(val:Int, size:Int) While (val Mod size) <> 0 val:+1 Wend Return val End Function This code did some miracles in my RPG. |
| ||
Ok, i now even removed this codeLocal tX:Int = vX + ((oX + 32000000) / 32) - 1000000 Local tY:Int = vY + ((oY + 32000000) / 32) - 1000000 And with my new SuperFloor() function, its all solved. Amazing. All the problems are solved and i could safely remove any hacks i placed. |
| ||
Hello. Isn't there a potential speed issue with repeated use of your Floor and Ceiling functions? I was under the impression that you took quite a hit using MOD? Goodbye. |
| ||
no? maybe 1 or 2 fps :S i dunno. |
| ||
Actualy, bypassing the mod function (just stripping it out) realy LOSES me FPS. when i add the floor and mod functions the FPS increases! |
| ||
HMm... altough, you are right. See, when i modified the functions to this: I gained 4 FPS in preformance:'SuperFloor Function SuperFloor:Int(val:Int, size:Int) Return val - Abs(val Mod size) End Function 'SuperCeil Function SuperCeil:Int(val:Int, size:Int) Return val + Abs(val Mod size) End Function Here i only use the MOD function 1 time. |