private void writeObject(ObjectOutputStream out) throws IOException
	{
		out.writeInt(entitiesByDepth.size());
		Iterator<Integer> it=entitiesByDepth.keySet().iterator();
		while(it.hasNext())
		{
			int index=it.next();
			out.writeInt(index);
			ArrayList<Entity> entities=entitiesByDepth.get(index);
			out.writeInt(entities.size());
			for(Entity e:entities)
			{
				out.writeObject(e);
			}
		}
		
		out.writeInt(backgroundLayers.size());
		it=backgroundLayers.keySet().iterator();
		while(it.hasNext())
		{
			int index=it.next();
			out.writeInt(index);
			ByteArrayOutputStream buffer=new ByteArrayOutputStream();
			ImageIO.write(backgroundLayers.get(index),"png",buffer);
			out.writeInt(buffer.size());
			out.write(buffer.toByteArray());
		}
	}