ClanLib

Sprites Resources

Resource options

The sprite resource options is a plethora of possibilities to tweak a sprites looks and behaviours, but all of them have default values. In most cases you will only need to use the basic options.

Each sprite can have the following properties:

<sprite
	name="my_sprite"
	description="resource_containing_shared_description_data"
	pack_texture="[yes,no]"
	base_angle="angle"
	id="id">

	<!-- Frame image loading: -->
	
	<image file="filename" />

	<image file="filename">
		<grid
			pos="x,y"
			size="width,height"
			array="tiles_x,tiles_y"
			array_skipframes="skip_count"
			spacing="width,height" />
	</image>

	<image file="filename">
		<palette
			pos="x,y" />
	</image>

	<image file="image4.png">
		<alpha
			pos="x,y"
 			free="true"
			trans_limit="limit" />
	</image>
	
	<!-- Sprite render and animation states: -->

	<color
		red="red_component"
		green="green_component"
		blue="blue_component"
		alpha="alpha_component" />

	<animation
		speed="speed"
		loop="[yes,no]"
		pingpong="[yes,no]"
		direction="[backward,forward]
		on_finish="[blank,last_frame,first_frame]" />

	<scale x="scale_x" y="scale_y" />
	
	<translation
		origin="[top_left, top_center, top_right,
		         center_left, center, center_right,
		         bottom_left, bottom_center, bottom_right]"
		x="offset_x"
		y="offset_y" />
	
	<rotation
		origin="[top_left, top_center, top_right,
		         center_left, center, center_right,
		         bottom_left, bottom_center, bottom_right]"
		x="offset_x"
		y="offset_y" />
		
	<frame
		nr="frame_number"
		speed="frame_delay"
		x="offset_x"
		y="offset_y" />

</sprite>

Only the name attribute of <sprite> and at least one <image> element is required to construct a sprite. The remaining elements and attributes are optional.

Using the <image> element

The first step in setting up a sprite is telling the resource loader where it should get the images for all the frames. This is done specifying one or more <image> elements. Each <image> element specify an image from where one or several frames should be extracted:

If you have many sprites that are using the same frames for its animation, you can use the description attribute on the <sprite> element to use the frames from an other sprite resource.

Setting up render and animation

The remaining elements <color>, <animation>, <scale>, <translation> and <rotation> alter the default values of the CL_Sprite render and animation properties.

<frame> sets up properties for a specific frame.

Sprite resource options reference

<sprite>

<image>

<grid>

<palette>

<alpha>

<color>

<animation>

<scale>

<translation>

<rotation>

<frame>

Questions or comments, write to the ClanLib mailing list.