Why is TiledBackground seperate from Sprite object type?

Discussion and feedback on Construct 2

Post » Mon Mar 14, 2016 3:47 am

I have a dream that TiledBackground doesn't exist and instead 'Tiled' is a property that you can set on Sprite objects

That would be amazing, would solve so many headaches in my project,

1. I have many cases where I need to write basically the exact same code twice, once for sprites, once for tiledbackgrounds, simply because those objects cant be put in the same family together. And if you want to go one further and have a Family be applicable to Tiled Backgrounds and Sprites, you need to create and code the same family twice. For example some families in my project: PhysicsSprite, PhysicsTile, StructureSprite, StructureTile, ZoneSprite ZoneTile, things like that.

2. shader vtex coordinates work completely different for tiled and sprites, how come? viewtopic.php?f=184&t=169989&p=1022620#p1022620

3. animated tiled objects would be awesome

So anyone know what's up? Is there some incompatibility in design or code that i'm not aware of?
B
28
S
8
G
1
Posts: 469
Reputation: 4,683

Post » Mon Mar 14, 2016 4:05 am

The problem is canvas2D. Apparently, even the tiled aspect of TB's was hackish to get working in canvas2D. It's all perfectly doable in WebGL, just no one has done quite that.
B
103
S
38
G
19
Posts: 962
Reputation: 17,996

Post » Mon Mar 14, 2016 4:37 am

Actually both canvas2d and webgl have their quirks.

With canvas2d the tiledbg is a rectangle with an image pattern fill. Sprites are drawn with the drawimage function, which doesn't have repeat, and is faster than a pattern fill. But yeah, a repeat property could be used to easily switch between the two rendering methods.

With webgl the tiledbaground image needs to be power of two to be able to repeat. The runtime does the resizing for you when the object type is first created, and this may also be why things are different with effects. Other than the size issue, the difference between sprite and tiledbackground is mainly just a webgl texture setting as I recall. Webgl2 allows for non-power of two texture repeating but it's a long way off. Another possibility would be to write a shader to do the repeating but this wouldn't be as fast.
B
92
S
32
G
107
Posts: 5,274
Reputation: 69,959

Post » Mon Mar 14, 2016 12:02 pm

There are a couple of issues that prevent us easily putting a "tiled" property on Sprite:
- the collision masks work differently: you can put a custom collision mask on each frame of a Sprite, but not on a tiled background, because we don't support tiling collision masks. If you could tile a Sprite, either we would have to do a lot of work to implement tiling of collision masks (which could present some very difficult implementation problems), or collisions just suddenly revert to bounding-box in tiled mode, which is the kind of confusing trap that people get upset about ("why did my collisions suddenly stop working?!").
- the rendering works differently: each Tiled Background object uses a repeating texture, which is different to a non-tiling texture in OpenGL. Also due to the way OpenGL works it's most convenient to exclude these images from spritesheeting, so each tiled texture is always its own texture with no padding or other content (which makes the texture repeat modes easy to use). If Sprite has an option to enable this, it becomes quite complicated. If you can change it per instance or at runtime, you must duplicate the entire set of images (doubling the memory usage) to allow for the tiled mode. Only allowing it to be a global option for each type of sprite is easier, but even this is not so straightforward: if you have 500 animation frames, due to the fact they are not spritesheeted, this turns in to 500 separate images after export, and having too many images has been the source of problems before.

I think the easiest solution is a way to add animations to Tiled Background with some provision for spritesheeting, but this is complicated and doesn't even solve all the problems!
Scirra Founder
B
395
S
232
G
88
Posts: 24,371
Reputation: 193,762

Post » Mon Mar 14, 2016 5:43 pm

>revert to bounding-box in tiled mode
I think it's unusual for someone to want a tiled sprite without using bounding box collision mask, so if the 'tiled' option didn't affect collision masks at all, I think people would still manually set them to be bounding box.
If the 'tiled' option is clearly described as something that -only- affects rendering, then I think that confusing trap can be avoided, or at least it's no more confusing than how people could already accidentally have a collision mask that doesn't match their sprite image.

but either way.. i understand now that this is a big technical problem as well, so that seems fair enough that tiled sprites aren't a thing

thanks for the responses @C-7 @R0J0hound @Ashley
B
28
S
8
G
1
Posts: 469
Reputation: 4,683


Return to Construct 2 General

Who is online

Users browsing this forum: huZba, LaDestitute, lukewasthefish, thimas and 5 guests