Roku Developer Program

Join our online forum to talk to Roku developers and fellow channel creators. Ask questions, share tips with the community, and find helpful resources.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
MazeWizzard
Visitor

roSprites and Draw()

OK. compositor.DrawAll() clears the screen... or at least appears to....(Dang!) stopping pre-drawing a background image unless said image is a sprite. Even that would be OK, but the blit for the entire screen (with AlphaEnabled(true) since we are dealing with sprite drawing while using DrawAll() ) is expensive.

non-double-buffered screens flicker and are not an option. Double buffering requires redrawing the entire screen per the documentation (assume the back-buffer is in a garbage state... or at least it's in an obsolete state).

Draw() only draws dirty sprites, which is fine if I had a way to mark a sprite as dirty. So the question becomes:

"What is the fastest way to mark a sprite as dirty?"

Just move it back and forth 1?

Or has anyone figured out a way to use DrawAll() that doesn't wipe out the current target?
0 Kudos
7 REPLIES 7
RokuJoel
Binge Watcher

Re: roSprites and Draw()

Are you sure your sprites are transparent and not occluding the background you drew to the screen? Sometimes it is really tricky getting various layers and transparency working. I just did some testing, and I can't verify that drawall() erases the background. I could be wrong, but with some quick limited testing, I don't think that it does.

- Joel
0 Kudos
RokuMarkn
Visitor

Re: roSprites and Draw()

A fast way to mark a sprite dirty is sprite.MoveOffset(0,0).

--Mark
0 Kudos
MazeWizzard
Visitor

Re: roSprites and Draw()

"RokuMarkn" wrote:
A fast way to mark a sprite dirty is sprite.MoveOffset(0,0).

--Mark


I was hoping for something fast like that. Should have just tried it 1st before asking but maybe it will help others reading this too.
It worked.

Thanks.
0 Kudos
MazeWizzard
Visitor

Re: roSprites and Draw()

"RokuJoel" wrote:
Are you sure your sprites are transparent and not occluding the background you drew to the screen? Sometimes it is really tricky getting various layers and transparency working. I just did some testing, and I can't verify that drawall() erases the background. I could be wrong, but with some quick limited testing, I don't think that it does.

- Joel

Well..... maybe others can comment then. FYI... my draw loop is basically:


while <whatever>
scrn.SetAlphaEnable(false)
scrn.DrawObject(0,0, StationaryBackgroundBM)
scrn.SetAlphaEnable(true)
' comp.DrawAll() 'DrawAll() does a clear screen???
comp.Draw()
scrn.swapBuffers()

<more code stuffis>
end while


If I comment out comp.Draw() and uncomment comp.DrawAll() the background is not there. If I use Draw() it's there. Maybe I'm doing something stupid..... IDK. I'll do more testing and get back to you. This is on v 3.1 Roku 1.

EDIT: OK, created test. Try this: (you'll need to create a Background.jpg and a smallsprite.png file in /images. The background.jpg filled the screen, the smallsprite was 68x68 in my test). If it's not clearing the screen, why is the background not showing up for DrawAll()?... as you can see it prints a message to the debug console showing what method it is using at any moment.

With my test, the background blitted in drawObject (line noted in comment) is not showing (is black) for DrawAll() and there with Draw(). So... what am I doing that's incorrect?

If you're trying to duplicate it, remember to use a double-buffered screen, or just use code below.


Sub Main()
screen = CreateObject("roScreen", true, 640, 480)
screen.Clear(0)
screen.SetAlphaEnable(true)
sh = screen.GetHeight()
sw = screen.GetWidth()
backgroundBM = CreateObject("roBitmap", "pkg:/images/Background.jpg")
comp = CreateObject("roCompositor")
comp.SetDrawTo(screen, &H00FF)
sbitMap = CreateObject("roBitmap", "pkg:/images/smallsprite.png")
sregion = CreateObject("roRegion", sBitMap, 0, 0, sBitMap.GetWidth(), sBitMap.Getheight())

sprite = comp.NewSprite(100, 100, sregion, 1)
sprite.SetDrawableFlag(true)


while true
Counter = 0
while Counter < 400
screen.SetAlphaEnable(false)
screen.DrawObject(0,0, backgroundBM) ' <<--- Image blit
screen.SetAlphaEnable(true)
if Counter < 200 then
if Counter = 0 then Print "Using DrawAll()"
comp.DrawAll()
else
if Counter = 200 then Print "Using Draw()"
sprite.MoveOffset(0,0) ' Mark sprite dirty.
comp.Draw()
end if
screen.swapBuffers()
Counter = Counter + 1
end while
end while


End Sub
0 Kudos
RokuJoel
Binge Watcher

Re: roSprites and Draw()

According to two of our software engineers most familiar with roScreen:

"DrawAll clears to the background color only if the background color is nonzero. Background color is set with the setdrawto() function".

- Joel
0 Kudos
MazeWizzard
Visitor

Re: roSprites and Draw()

Undocumented feature confirmed. lol.

I'm surprised that it clears to anything since Draw() doesn't.... although I confess I had wondered what that parameter to compositor.SetDrawTo() was all about. If documented, it would have saved me some time. Suggest doc update.

Thanks for the info!
0 Kudos
RokuJoel
Binge Watcher

Re: roSprites and Draw()

I'll suggest that for our next documentation release.

- Joel
0 Kudos