Jump to content

merging images to new image / new sprite? Bulletholes?


lazee
 Share

Recommended Posts

Hey there,

 

i'm very new to phaser, before digging deeper i'd like to know if something like this is possible:

 

- merging sprites into the background-image, so they are not sprites anymore but just part of the background bitmap (infinite bulletholes without performance loss)

- merging two sprites into one sprite to get a new animation frame (bulletholes on animated characters)

- generally: manipulating the image data used as animation frames or sprites - i want to shoot bullets on an object and it gets bigger because the bullets add to its bitmap when colliding

 

I found very little by googling, can someone hint me in the right direction or tell me, if phaser covers such things?

 

many thanks in advance :)

Link to comment
Share on other sites

Game developers often stumble across this seemingly magical solution to reduce your sprite count by having the textures get modified directly, but in truth it's not really a very good solution because it's not the amount of sprites on the screen which is the real problem. It is possible to edit textures in Phaser by manipulating BitmapData or using RenderTextures but what you'll quickly realise is that if you have any other sprites or images using the same image resource, the bullet holes will appear on those too. Even if doing it just on a background, every time you add a bullet hole to the background you'll have to modify the texture and re-upload it; and it's probably much more efficient to just have a SpriteBatch of bullet holes in front of the background in this case.

 

Much of what you see going on in games is the result of a small amount of resources being duplicated ('instanced') and this is very very fast. The texture only has to be read once, and can then be repeated, tiled or drawn in lots of different places with very minimal performance cost (this is called 'batching'). If you were to have a separate texture for every sprite so you could apply bullet holes or other decals independently, you will quickly bring even desktop machines to their knees, because they're not optimised for this kind of rendering. Your memory usage will also shoot through the roof as you're now not storing one sprite image, but as many copies of that image as there are sprites with decals on them - and that's assuming you're being careful to only create new textures when needed!

 

That said, it is possible, and BitmapData and RenderTextures are the way to do this, but I'd seriously consider the alternative of just having extra images/sprites in the display list and using texture atlases, which cleverly works to the strengths of the batching routines by drawing just parts of the same texture on the screen.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...