ID:262687
 
Code:
proc/Up(obj/Ball)
set background = 1
while(Ball.y<world.maxy)
Ball.pixel_y+=2
if(Ball.pixel_y>=32)
var/DoubleBuffer/DBMAIN = new()
DBMAIN.LoadBuffer(Ball)
DBMAIN.SwitchBuffer(Ball)
del(DBMAIN)
// Ball.pixel_y-=32
// Ball.loc=get_step(Ball,NORTH)
sleep(1)

// This is the Double Buffer Datum
DoubleBuffer
var
atom/movable/bb/back
New()
back = new(locate(1,1,1))
proc
LoadBuffer(atom/movable/OBJ)
back.icon = OBJ.icon
back.icon_state = OBJ.icon_state
back.pixel_x = OBJ.pixel_x
back.pixel_y = OBJ.pixel_y
back.x = OBJ.x
back.y = OBJ.y
back.z = OBJ.z // sets all object variables needed to back buffer object
var/i=1
while(i)
if(back.pixel_x>=32)
back.x++
back.pixel_x-=32
continue
if(back.pixel_x<=-32)
back.x--
back.pixel_x+=32
continue
if(back.pixel_y>=32)
back.y++
back.pixel_y-=32
continue
if(back.pixel_y<=-32)
back.y--
back.pixel_y+=32
continue
i=0

// ERROR takes place within this proc.
// At leas that is what I got from my debug messages.
SwitchBuffer(atom/movable/OBJ) // switches over back buffer to normal object
back.invisibility = 0
OBJ.invisibility = 101
OBJ.pixel_x = back.pixel_x
OBJ.pixel_y = back.pixel_y
OBJ.x = back.x
OBJ.y = back.y
OBJ.invisibility = 0
back.invisibility = 101


atom/movable/bb
invisibility = 101


Problem description:

Ok I was Programming a pixel based movement system. But when I got to the fallowing code.
if(O.pixel_y>=32)
O.pixel_y-=32
O.y++

It would move the object back for like a split second. Cause the two statments move the pixel_y and y but not at the same time. So there is a slight delay with graphics in between.

To fix this I made the DoubleBuffer object seen above. It would create a temporary back buffer object. Display it but with the y and pixel_y all ready changed. To do this I was using the invisibility variables as you can see in the SwitchBuffer() procedure. I would make the back buffer visible after it had its vairables set. Then I would make the orignal object invisble. Then set the original's object variables to the back buffer object. Then make the orginal object visible and the back buffer object invisible.

On to the problem. There is still a glitch with the graphics. It still looks like it goes back and then comes forward. Like it did before the back buffer.

The only thing I can figure is that there is a slight delay graphical wise is switching an object from visible to invisible. Is that true? And if so why? Also how much of a delay?(how could I fix it)

Thanks for your answer.
Mean Byond Graphics :*(

P.s. For some reason I cant get the World Profile to work. I click on it in the menu and nothing happens. I even have debug set. Is is because I am repeatly running a loop. Even so I set background = 1 so shouldn't it not hold any thing up?
Green Lime wrote:
I got the fallowing code.

That's my favorite code. Down with crop-mongering!
In response to PirateHead
???
In response to Green Lime
With regards to PirateHeads comment and Green Lime's ensuing confusion, when a field is 'fallow' it means that it has no crops growing in it. Pirate Head was making a comment about the typo. Not really helpful.