eockh
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2012
12:16 PM
calling Remove on a sprite
So I think I'm missing something here, but I'm calling remove on a sprite and then telling the compositor to draw but it appears that the sprite I just removed is still being drawn by the compositor. What are the standard steps for removing a sprite from the screen? Thanks!
17 REPLIES 17

RokuJoel
Binge Watcher
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2012
01:04 PM
Re: calling Remove on a sprite
I'm wondering, are you calling compositor.drawall() and calling swapbuffers() or finish() at the end of each iteration?
- Joel
- Joel
eockh
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2012
01:19 PM
Re: calling Remove on a sprite
Yes..so in pseudo code
sprite = compositor.newsprite
compositor.draw
screen.swapbuffers
sprite.remove
compositor.draw
screen.swapbuffers
I will still see what the original sprite drew.
sprite = compositor.newsprite
compositor.draw
screen.swapbuffers
sprite.remove
compositor.draw
screen.swapbuffers
I will still see what the original sprite drew.
eockh
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2012
01:21 PM
Re: calling Remove on a sprite
also to note, I have other sprites still in the compositor if that makes a difference.

RokuJoel
Binge Watcher
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2012
01:41 PM
Re: calling Remove on a sprite
try drawall() instead of draw() ?
- Joel
- Joel
MazeWizzard
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-21-2012
04:48 PM
Re: calling Remove on a sprite
Hmmm...no reply yet. So...
How about:
Are you regenerating the entire frame each time? You should either clear the screen and draw, or fill it with a background bitmap and then draw. The "old" sprite shouldn't be there. If it still is...maybe the remove failed?
How about:
Are you regenerating the entire frame each time? You should either clear the screen and draw, or fill it with a background bitmap and then draw. The "old" sprite shouldn't be there. If it still is...maybe the remove failed?

RokuJoel
Binge Watcher
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-21-2012
05:37 PM
Re: calling Remove on a sprite
Here's a little example of removing a sprite. Mind you, I'm not invalidating the underlying region and bitmap here, which you might need to do if you run out of video memory, but I don't think that is an issue with the way I'm doing this:
https://www.box.com/shared/jbetbkjcus4iyw25uejb
https://www.box.com/shared/jbetbkjcus4iyw25uejb
sub main()
l=listdir("pkg:/images")
regarray=[]
for each item in l
bmp=createobject("robitmap","pkg:/images/"+item)
reg=createobject("roregion",bmp,0,0,bmp.getwidth(),bmp.getheight())
regarray.push(reg)
end for
screen=createobject("roscreen",true)
compositor=createobject("rocompositor")
compositor.setdrawto(screen,&h000000FF)
timer=createobject("rotimespan")
timer.mark()
i=0
spr=compositor.newsprite(100+rnd(300),100+rnd(300),regarray[0])
while true
screen.clear(&h000000FF)
if timer.totalseconds() > 5 then
i=i+1
if i > regarray.count()-1 then i=0
spr.remove()
spr=compositor.newsprite(100+rnd(300),100+rnd(300),regarray[i])
timer.mark()
end if
compositor.drawall()
screen.swapbuffers()
end while
end sub
eockh
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-24-2012
06:59 AM
Re: calling Remove on a sprite
RokuJoel,
Thanks for the response. Turns out I was calling draw() on the compositor at the wrong time which was causing artifacts. Removing that and enforcing a drawall call made it work properly.
Thanks for the response. Turns out I was calling draw() on the compositor at the wrong time which was causing artifacts. Removing that and enforcing a drawall call made it work properly.
olarurazvan
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-20-2015
08:19 AM
Re: calling Remove on a sprite
Hi everyone,
I'm currently trying to create an app which has a vast list of items represented by sprites (about 1000). In order to avoid video memory depletion I keep only 6 sprites drawn on the screen at a time. When scrolling the list, the last item (from those 6 drawn) is deleted and the next item is drawn and so on. I delete the sprites using sprite.remove() method and then assigning the sprite an invalid value (and also invalidate the related region and bitmap) but it still seems that after scrolling about 400 items the memory gets depleted.
Here is how I invalidate the sprite and the related region and bitmap:
Could you please tell me why the memory still gets depleted?
I'm currently trying to create an app which has a vast list of items represented by sprites (about 1000). In order to avoid video memory depletion I keep only 6 sprites drawn on the screen at a time. When scrolling the list, the last item (from those 6 drawn) is deleted and the next item is drawn and so on. I delete the sprites using sprite.remove() method and then assigning the sprite an invalid value (and also invalidate the related region and bitmap) but it still seems that after scrolling about 400 items the memory gets depleted.
"RokuJoel" wrote:
Mind you, I'm not invalidating the underlying region and bitmap here, which you might need to do if you run out of video memory, but I don't think that is an issue with the way I'm doing this
Here is how I invalidate the sprite and the related region and bitmap:
purgeSprite: function(sprite as Object) as Void
if type(sprite) = "roSprite"
' Get the region and bitmap of the sprite
region = sprite.getRegion()
bitmap = region.getBitmap()
' Remove the sprite and invalidate it
sprite.remove()
sprite = invalid
' Invalidate the region and bitmap
region = invalid
bitmap = invalid
print "| Sprite purged!"
end if
' After exiting this method, the memory that the sprite used
' (altogether with the bitmap and region) should be removed.
end function
Could you please tell me why the memory still gets depleted?

NewManLiving
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-20-2015
11:49 AM
Re: calling Remove on a sprite
look at what your doing. Creating a local variable to reference other objects then setting the local variable back to invalid does not remove the original bitmap.
l_b = createobject("roBitmap", ...)
l_a = l_b
Two references
L_a = invalid
One reference
Has no effect on l_b. It still exists
l_b = createobject("roBitmap", ...)
l_a = l_b
Two references
L_a = invalid
One reference
Has no effect on l_b. It still exists
My Channels: 2D API Framework Presentation: https://owner.roku.com/add/2M9LCVC
Updated: 11-11-2015 - Completed Keyboard interface
The Joel Channel ( Final Beta )
Updated: 11-11-2015 - Completed Keyboard interface
The Joel Channel ( Final Beta )