Tiling & spritesheets

For developers using the Construct 2 Javascript SDK

Post » Fri Jun 01, 2012 6:08 am

So I have this craptastic frankenstein pile of hacks plugin that combines sprite with the drawing code from tiledbg so that I can make a sprite with animation frames that tiles. It's super buggy (effects, moving, etc cause problems) so I won't publish it, but it worked fine for the its very narrow purpose of letting me easily change the game's background pattern on the fly.

The game code is supposed to be locked, but I couldn't resist the spritesheet feature so I rebuilt using the latest beta, and of course now it's tiling the entire spritesheet instead of just the animation frame I want.

Any tips? It would be super if there was just a toggle that says 'don't export as spritesheets for this plugin'. If the only way is to redo the plugin using the update sprite+tiledbg code I think I'll just have to revert my changes and ditch spritesheets since I wasn't really supposed to be touching the code in the first place.

P.s. what would be awesome-est is if sprites and tiledbg were simply combined into 1 so that you would have a 'tiling' setting you can toggle on/off, never really understood the reason for making them separate.wgfunstorm2012-06-01 06:08:42
B
22
S
9
G
5
Posts: 122
Reputation: 5,386

Post » Mon Jun 04, 2012 7:03 pm

Any thoughts?

- Can I disable the 'create spritesheets from animation frames on export' behavior for a plugin?

or

- How can I tile a spritesheet frame?

I the weekend trying to figure out a solution without success and after lots of hours am ready to give up now. If I can't solve it within a day or 2 I have to revert to a previous C2 release. wgfunstorm2012-06-04 22:31:22
B
22
S
9
G
5
Posts: 122
Reputation: 5,386

Post » Wed Jun 06, 2012 1:38 pm

Sorry for the late reply, I was off this weekend...

You can fix your plugin but it would be a little complicated. To tile a spritesheet frame you need to:
1) make a new canvas and get a 2D context
2) drawImage() the sprite's image on to it (you'll have to see the new code in Sprite's draw() which shows how to draw the part from the spritesheet)
3) make a new Image() and set its src to canvas.toDataURL() - now you have a standalone image of the section from the spritesheet
4) now you can make a pattern of that image and draw the section tiled

I can't immediately think of a way to get this working with WebGL, but you could just turn it off for now.

It's a good point why sprites can't be tiled and why Tiled Background exists at all. But Tiled Background has a slightly lower overhead than Sprite, and in future it may be possible to better optimise Tiled Background based on the fact it's simpler than sprite.
Scirra Founder
B
359
S
214
G
72
Posts: 22,946
Reputation: 178,468

Post » Sat Jun 09, 2012 6:33 am

Ok thanks for the reply. I tried your suggestion but that's just beyond my level of knowledge. Gonna stick with C91 for this game.
B
22
S
9
G
5
Posts: 122
Reputation: 5,386


Return to Javascript SDK

Who is online

Users browsing this forum: No registered users and 1 guest