Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers AppGameKit Corner / SetSpriteVisible/SetSpriteActive what is with the shape?

User Offline
Joined: 2nd Oct 2017
Posted: 28th Feb 2018 22:50
Now after my player controler is done for simple movement i would prepare my tilemap scrolling.
In the moment are all tiles draw and shaped before the main loop.
I could do this on the fly while scrolling but i heared that it is maybe better to deactivate all tile outside the view.

For that i have to deactivate/unvisible all tiles outside the view.
But what is deactivatet?
Is only the actual sprite in memory? And what is with the predefined shape?
User Offline
Joined: 9th Jan 2018
Posted: 2nd Mar 2018 00:24
SetSpriteActive means it can react to collisions , SetSpriteInvisible means it is not visible, but could still do collision (can be useful for invisible boundaries of a level actually).

As for shapes for sprites, this is a thing that is important when you're checking collisions or use the 2D physics engine. There are basic shapes like box, circle and polygon, each with their obvious characteristics in physics calculations.

If you want pixel-perfect collision, you probably want to use polygon shape. ( SetSpriteShape( iSpriteIndex, shape ) with iSpriteIndex being The ID of the sprite to modify. And shape = The shape to use for this sprite, 0=no shape, 1=circle, 2=box, 3=polygon.

Keep in mind for animated sprites that have a shape that is polygonal, that it is not automatically updating the shape to match your animations. It does 'move' 'flip' 'rotate' and 'scale' when you change your sprite in such ways, but it does not update to keep up with particular animations. I guess there are a few ways of dealing with that.

As for the memory thing; I think not drawing the sprite generally saves the most memory, aside from deleting the sprite entirely. However creating and loading sprites 'on the fly' might actually be a stronger hit on performance than simply having them set to invisible a bit depending on how big your game world is and how high the speeds are when scrolling to new areas to load.
User Offline
Joined: 2nd Oct 2017
Posted: 2nd Mar 2018 01:50
I only needs the shapes for raycasting with the world.
In one loop there are always the same number of tilesprites.
I write some days a tilemapscrolling and in this test i create on every loop the needed tiles with number i.e. 0-x(visible tiles+1)
The other way is to draw the full map and set all tiles invisible or inactive before the main loop and then inside the mainloop i set the tiles in view to visible/activ.
The question is, what happens with the inactiv sprites.Only more memory in ram, or other things.
The difference is create <-> activate.activate should be faster.but i´m not sure because on this way the complete tilemap is loaded in background.

I would be interested to what tilemap size it actually makes no big difference.

Login to post a reply

Server time is: 2018-09-20 10:10:20
Your offset time is: 2018-09-20 10:10:20