PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

Creating sprites offscreen

Creating sprites offscreen now makes them automatically not visible with the new release.

I created some bullets and initialized their position offscreen. I used to just move them onscreen and they would appear. Now, I have to call ShowSprite to make them appear after I move them. I don't think the last version had a problem like this.
Hm, I'm not running into that here either.

My first guess would be the sprite options. Here's what I'm using to draw an offscreen sprite:

Code:
tempsprite$ = NewSprite(null);
SetSpriteSurface(tempsprite$, tiles$, tileamnt$, 0);
SetSpriteIndex(tempsprite$, tiletype$ - 1);
movesprite(tempsprite$, y$ * 16, x$ * 16);
SetSpriteFriction(tempsprite$, 100);
SetSpriteID(tempsprite$, "WORLD");
SetSpriteCollide(tempsprite$, "MARIO, BADDIE, WORLD");
SetSpriteLayer(tempsprite$, 2);
AddSpriteOption(tempsprite$, SO_PROCESSONLYVIEW | SO_COLLIDE);
SetSpriteProc(tempsprite$, &Breakable;);


The sprite process just check if it's been hit from the bottom.
I create a sprite at x= -20 and y= -20.
Visisble is by default ON.
before last update, when I needed the sprite, i simply changes the x and y coodinates and presto, it was instantly visible, all was fine.

Now I run the same program code with the latest build and the sprites are nowhere to be seen. I even added a line of code to make it visible at sprite creation. however it still didn't work. Then, once I move the sprite onscreen, THEN I use ShowSprite, and it appears and the program continues as normal.

Again, my code was not changed before I installed the latest build.
Fixed!
I was wrong, it won't be fixed. You will need to show the item once on screen. You will need to do a:

Code:
ProcessSprites(true, false);


To trigger the sprite sort internal procedure. PPL only displays the sprites on screen. The sort procedure is only triggered when origins are changed or the ProcessSprites() function is called.
If I make a sprite onscreen, then it moves off screen then back on again, will it turn invisible and stop being processed?
Not really. The sprite state won't change, the sprite won't be drawn that's it. G_RENDERSCENE, only draw sprites that are in view but the calculation to know if the sprite is in view or not is done only when the origins changes.

I will try to come up with some way of preventing this behavior without having to call ProcessSprites() and keep the speed.
I found a way to fix this without losing speed. I will implement it and try it out. I'll get back to you.