Is Gosu capable of handling SpriteSheets, either via a plugin/library or natively? - django-supervisor

If SpriteSheets can be handled which library would be best to use and can it be done natively?

Yes, Gosu can natively handle spritesheets. Using
Gosu::Image.load_tiles(window, path, width, height, tileable?)
(where width and height is the size of single sprite (if you're not sure what is the size of single sprites, but know that spritesheet will be ex. 8x8 sprites, use negative values to divide)) will create an array (1d) of Images from given file. You can then access them in other methods, such as draw

Related

Extracting Sprites from Spritesheets in AS3

Recently I've been experimenting with spritesheets, particularly in AS3. I've managed to extract standard sprites and develop functional animations through sheets with equal sized squares. A lot of spritesheets on the internet aren't properly organized with equal sized squares though. Is there a way to manipulate pixels to obtain the location and dimensions of sprites from these sheets dynamically? Or must I modify the spritesheet itself to a 'square format'?. I want to avoid hard-coding as much as possible.
The point of spritesheets is often to reduce the overhead of data. Loading one image is much faster than loading hundreds of images. Because you can have variable sized images, most spritesheets generated will also come with a secondary file that defines where in the spritesheet you can find each image. Then, it's just a matter of referencing the x, y, width, and height values for that image.
TexturePacker will generate these, as I imagine most other apps do.
Typically if you have non-regular sized and/or spaced sprites, you'd also have an accompanying data file (XML or JSON probably) that defines the locations and sizes of the different sprites.

AS3: Using mask vs Cropped images

there are spritesheets of tiles for a new game I'm developing. I'm planning to use them with mask layers. I mean for example there is 30 different tiles on each spritesheets, to use each one I'm planning to change spritesheet's x and y, so mask will show only the wanted tile.
But the problem is, it may force cpu.
For example if there are 30 tiles on the screen and if each spritesheets has 30 different tiles, that makes 900 tiles if I use mask layer instead of cropping each tiles.
So the problem is , If I use mask layer, does it effect the cpu in a bad way, or does only the part under the mask is calculated on cpu?
I hope I could define the problem clearly.
Thank you
-Ozan
Starling is a whole new field, as it's using Stage3D. This means you have to rethink your development flow - everything must be as textures and so there are a lot of limitations - you cannot simply design a button in your Flash IDE, give it a name and use it. I'm not saying it's bad, no, I just say you have to you it wise and if you don't have any experience with it - it will take time to learn.
I think you are doing some calculations wrong. You say For example if there are 30 tiles on the screen and if each spritesheets has 30 different tiles, that makes 900 tiles, which means you have 30 spritesheets with 30 tiles on each. This is a lot of tiles for your game, are you sure? :)
Anyways, the common approach is to use each tile of the spritesheet as an individual one. That's why it's called spritesheet. And the meaning of this is very simple - the memory it will use. Imagine you have 100 tiles in one spritesheet (for easier calculations), and this spritesheet is 1mb. If you splice it in smaller chunks (100 of them), the size of it will be close to 1mb also. So if you do this and delete the original source, the RAM that will be taken because of those bitmaps will be close to the original.
Then you want to use a single tile (or let's say your map is just "water" and you use only one tile). You instantiate many instances of the very same class, and because you use only one kind, the memory that will be taken in order to be displayed is 1/100 of the original 1mb.
What I mean is that the worst case scenario would be to use the total 100 of them at the same time, and this will take 1mb of memory (I'm talking for the images only). Every time you use less, the memory will decrease.
The approach of having a mask is worse, because even if you use a single tile, it will put all of the original spritesheet into memory. Single tile - 1mb. And it will also draw a mask object (Sprite) and will also need to precalculate that mask and remove the outer part of the Bitmap. This is more memory, more CPU calculations, and more graphic rendering (as it will draw the cropped Bitmap every time you instantiate).
I think this will give you an idea why it's used that way! :) If you have some fancy regions and that's the reason you want to use masking instead, then use some spritesheet packager program. It will provide you with a data file describing the regions of the spritesheet that are used, and so with a single class (there are many for that) it will parse your initial Bitmap, create Bitmap children for each chunk and destroy the original. And the coordinates won't matter.
Cheers! :)

How to manipulate pixels of rendered screen or Display Object in Actionscript 3?

My game engine doesn't render into a BitmapData like Flixel/Flashpunk does.
Instead it uses the Display list of Flash player internally.
I need to do some post processing, like scan lines, and wobble, glitch etc on the final rendered screen (e.g- http://goo.gl/Enwae). I have done render-to-texture in OpenGL and used a pixel shader used to manipulate the final rendered scene.
How do I implement the equivalent of same in Actionscript 3? I saw the reference for Pixel Bender and Shader Filter classes. Can someone give a simple example or point me to relevant information to the context specified here?
I'm pretty sure you'll need to render the screen to BitmapData at some point if you want to manipulate the pixels in that way.
You could try using BitmapData.draw() to render the entire stage to BitmapData, but performance will most likely be miserable unless you're just using it on a fairly static screen (like a menu).
Otherwise you're probably better off with a game engine that blits to a bitmap canvas instead of using the display list.

How to create retained graphic using SurfaceImageSource?

I'd like to create a XAML application which progressively displays some graphic in a part of the screen. I can have a large number of elements, so I'd like to retain the elements already drawn and only draw the new ones as they come. But unfortunately, I can't get to the swap chain from the SurfaceImageSource (tell me if it is possible) so I can't just copy buffers with each draw call.
How can I draw new elements onto the SurfaceImageSource while preserving the old ones in a performant way?
I think a swap chain is something you would use with a screen rather than a surface like the one used with SurfaceImageSource, so I don't think it has a swap chain at all - it is just a single texture. I haven't tried but I would assume that if you don't clear it between render calls (with the ClearRenderTargetView method) - the contents should stay as they did. If you want to reuse only a part of the content - you should probably create a separate texture and a render target view that you would use to render to that texture and then copy the contents of that texture to the SurfaceImageSource one some way. I am not sure what the best way to do that would be - maybe memory mapping the textures and doing a memcpy between them or rendering one as a textured quad (two triangles) to the other one.

Is it possible to scale a canvas element

... and have all of its internal dimensions and interactions remain relative to each other?
For example, with Flash, you can create a movie and publish a .swf file. Then, when you put that .swf file in a page, you can have that movie scale up or down and still maintain all of its functionality with it being none the wiser.
Is something similar with Canvas? I was directed by someone else to the WHATWG description of the scale property, but it was not helpful. Does the scale property do what I want and does anyone have an example?
Thanks!
I once solved this by wrapping the Canvas API with functions that used proportional coordinates (ie. 0.3, mapped to 0-1, fixed ratio and other axis relative to this).
Depending on how much work you want to do, you might want to either implement something like this yourself or use some pre-existing solution.