I think that would accomplish something else, with setContext I’m retaining the paths that the balls take,- more or less like using the retained mode …
If you run my code you see that it leaves a “path taken” behind.
@escape75 I saw when I first ran this that the balls were leaving a trail. I guess without knowing what you’re doing, it hard to modify the code. The balls are just moving back and forth in the box, so I wasn’t sure the purpose of the trail. Anyways, I’m off to bed so I won’t be looking at the ipad for 8 or 9 hours.
Yep, no problem, and yeah the trails have a purpose, it will be a maze type game,
And the walls will be hidden, but in the example i wanted to show what was happening.
In any case, setContext has now a huge performance penalty, even with no screen changes,
So i’m considering this a bug as it’s not really usable the way it works right now.
Simpler example showing setContext performance …
Codea 1.5.5 didn’t have this issue.
function setup()
supportedOrientations(LANDSCAPE_LEFT)
displayMode(FULLSCREEN)
backingMode(STANDARD)
myImage = nil
myImage = image(WIDTH,HEIGHT)
setContext(myImage)
fill(42, 31, 106, 255)
rect(0,0,WIDTH,HEIGHT)
setContext()
frameCount=0
timeInterval=0
fps=0
end
function draw()
sprite(myImage, WIDTH/2, HEIGHT/2, WIDTH, HEIGHT)
--2 is 50 fps
--3 is 40 fps
--4 is 35 fps
--5 is 30 fps
for i = 0, 4 do
setContext(myImage)
setContext()
fill(171, 100, 23, 255)
text(fps, 200, 200)
end
frameCount = frameCount + 1
timeInterval = timeInterval + DeltaTime
if timeInterval>1 then
fps = frameCount/timeInterval
timeInterval=0
frameCount=0
end
end
@escape75 setContext now creates a depth attachment so you can render 3d properly into image. This might be impacting realtime rendering in setContext, perhaps we can make the depth attachment creation optional or find some other way to improve performance.
I would like an option to call the faster method. Options are good. Maybe just add the old function back and then use setContext3d
Yeah fore sure, if this is not a bug but a side effect of zLevel I say it should
be made optional as it will make a few 2d projects not work that call
setContext more than once every draw() frame … Optional please!
Like I’ve shown above, the 4 calls will give you 35 fps
On older Codeas you would get 60 fps I believe
Might slow it down is a bit of an understatement
@escape75 I have a similar problem mentioned in my other thread, my project has very heavy use of setContext, Codea 1.5.5 could handle this no problem whereas it crashes as soon as I try to draw to an image the size of the screen. Slow down is an understatement definitely.
Yes thanks for confirming!
@escape75 having setContext3d as an alternative sounds like a reasonable alternative.
@Luatee I’m not sure if the crashing it being caused by the changes to setContext but we will definitely try to track down whatever it is.
I’m using a setContext of image(WIDTH,HEIGHT) and it wasn’t crashing,
however I only tried 5 setContext(image) followed by setContext() in one draw()
I’m wondering if doing more would cause issues that Luatee described
I know that the FPS was unaffected in previous versions when doing that.
I agree with setContext3d as an alternative - please implement
@John I’ve given Simeon the project export, you might have it already. Thanks for the work!
Nice, any updates? Will the setContext3d make it to 2.0.1 ?
Would be nice to get the old speed back so I can submit my latest game to the app store
By the way even after optimizing my code and leaving only one setContext() pair in draw() I can still see a little bit of jerkiness in the movement on screen …
@escape75 - I think your solution is efficient programming, not changes to setContext.
You can create trails very simply and very fast by just drawing a thick line behind each circle, to get exactly the same effect. There is no need for setContext at all.
There is also no need for four separate loops through the balls table in draw. You only need one loop, and if you put the colours in a table, then you don’t need to test for body.info. Just loop through the balls from 1 to 4 and draw the trail and then the balls themselves.
You should find you are getting close to 60 FPS as a result.
So while maybe setContext does need a separate 3D mode for maximum speed, it is not the problem in your case.
Yes I’ve optimized my code to only use a single setContext but my point
was that there is still a tiny slowdown with just one whereas the old Codea
didn’t even have a slowdown with 4+
However the reason I have loops is because once I destroy a ball during a collision
I would sometimes but rarely get an error inside the loop as it was checking
an already destroyed object … I think … anyway there’s some reason to my madness
Draw a line behind each circle? Yeah it’s just that the setContext was a very easy solution that worked very well!
@escape75 - SetContext is expensive especially when it is full screen. It wasn’t designed to be used 60 times a second (apart from drawing new things 4 separate times within each draw cycle).
I suggest you try the line. It is simple and makes for a cleaner and much faster result - and you won’t need to wait for changes to Codea, so you can have it today.
Ok, but the line gets more complicated in my code because I have a randomly generated maze
that you discover and draw the followed paths, so I can’t refresh the screen
as I would have to keep a history of the paths followed to draw the lines … hmmm
just checking if the setContext was addressed.
@Thwapp being addressed in the next update in order to make the depth aspect optional