Ha, finally i caught it! The code below show the shift bug with setContext. @Simeon could you please have a look at it? Took me quite a while to isolate, because it goes away when i change almost anything. Unless i have to change my glasses, that’s a bug. I have beta11 on ipad1 and ios5.1. This bug is really annoying because you never know when it will show up…
Just in case everything is ok on your side, this is what i get:
http://www.youtube.com/watch?v=5slGplXY4gw
[edit] i just noticed: all the sprite() of the draw() are not aligned with the text() along the vertical axis… The shift affects all the sprite() drawing no matter setContext or not. But do not affect text()…
--# Main
-- this file always show the image shift bug
function setup()
resetStyle()resetMatrix()
img1 = image(120,100) -- this is a simple red rectangle in blue background
setContext(img1)
background(0, 26, 255, 255)
fill(255, 0, 0, 255)
rect(5,5,30,30)
setContext()
img2 = image(120,100) -- this is a simple green background
setContext(img2)
background(0, 255, 20, 255)
setContext()
img3 = image(120,100) -- image3 is same as img2
setContext(img3)
background(0, 255, 20, 255)
setContext()
-- now we run the nasty function:
iCreateAshift() -- comment this line to see the expected behavior
-- iCreateAshift() -- surprisingly, calling twice solves the problem!!??
-- now when we use this simple function to copy the image to another it is shifted
setImage(img1,img3)
end
function draw()
background(40, 40, 50)
text("img1:",WIDTH/2, HEIGHT/8*7)
sprite(img1,WIDTH/2, HEIGHT/4*3)
text("img2:",WIDTH/2, HEIGHT/8*5)
sprite(img2,WIDTH/2, HEIGHT/2)
text("img3:",WIDTH/2, HEIGHT/8*3)
sprite(img3,WIDTH/2, HEIGHT/4)
fill(255, 255, 255, 255)
text("img3 should be like img1",WIDTH/2, HEIGHT/6)
end
function setImage(out,img)
resetStyle()resetMatrix()
setContext(img)
pushStyle()
spriteMode(CORNER)
sprite(out)
popStyle()
setContext()
end
function iCreateAshift()
resetStyle()resetMatrix()
local w,h = WIDTH*0.19,30
local img0 = image(w,h)
setContext(img0)
background(255, 255, 255, 255)
setContext()
local img = image(w,h)
local sMode = spriteMode()
setContext(img)
pushStyle() pushMatrix()
background(0, 0, 0, 255)
spriteMode(CENTER)
translate(w/2,h/2) -- this is the line source of the shift
sprite(img0,0,0) -- this line must be there too, the pb does not show up
popStyle() popMatrix()
spriteMode(sMode)
setContext()
resetStyle() resetMatrix() -- this does not reset the translation
end