Module Sprite


module Sprite: sig  end
Sprites and collision

type 'a t 
A sprite.
type 'a set 
Type representing a set of sprites that represent the same type of objects in collision and in storing information.
type ('a, 'b) table 
Hashtbl from 'a to 'b sprites


Sprites


val create : ?set:'a set -> 'a -> Video.t -> ?width:int -> int * int -> 'a t
create ?set data frames ?width position Creates a sprite with frames from the given surface.
val move_to : 'a t -> int * int -> unit
move_to sprite (x, y) Sets the position of sprite to (x, y)
val move : 'a t -> int * int -> unit
move sprite (dx, dy) moves sprite spr by (dx, dy)
val get_pos : 'a t -> int * int
get_pos sprite
Returns the position of sprite
val set_data : 'a t -> 'a -> unit
set_data sprite data sets the data of sprite to data
val get_data : 'a t -> 'a
get_data sprite returns the data of sprite
val get_size : 'a t -> int * int
get_size sprite returns the size of sprite
val delete : 'a t -> unit
delete sprite removes sprite from all sets it belong to


Sprite sets


module Set: sig  end


Collision


val add_collision_fun : 'a set ->
'b set ->
?alpha_bias:int -> bool -> ('a t -> 'b t -> unit) -> unit
add_collison_fun set1 set2 per_pixel collision_fun adds collision_fun to the list of functions called when a sprite from set1 collides with any from set2
Raises Log.fatal when Sprite.Set.set_collision was not called for any of any of the given sets.

alpha_bias : see Sprite.collides_with
per_pixel : if set to true per_pixel collision will be checked
val check_collisions : 'a t -> unit
check_collisions sprite finds all objects that sprite collides with all sets that were registered for collision with the sets sprite belongs to. For every collision it calls the apropriate function registered by Sprite.add_collision_fun
val collides_with : 'a t -> ?alpha_bias:int -> bool -> 'b set -> 'b t list
collides_with spr per_pixel set returns the list of all sprites from set that collide with spr

alpha_bias : is an optional parameter, that for surfaces with alpha channel means what sum of alpha values hast to be overcomed for collision to be detected. The default is 255 (collision when sum is over 255), while maximum for any surface is 255. If per_pixel is true per pixel collision will be checked


World boundary


val in_bounds : 'a t -> bool
in_bounds sprite checks if the sprite is ouside of world in any of the sets it belongs to
val move_in_bounds : 'a t -> ?chk:('a t -> bool) -> int * int -> int * int
move_in_bounds sprites (dx, dy) moves sprite as far as possible so that it remains in bounds


Drawing


val draw : ?on:Video.t -> 'a t -> unit
draw cnt sprite draws sprite spr on context cnt. cnt is optional
val set_animation_frame : 'a t -> int -> unit
set_animation_frame sprite frame_num Sets the frame displayed by sprite to frame_num picture on the image. If wrong frame number is specified an error message is shown on the console.
val get_animation_frame : 'a t -> int
get_animation_frame sprite
Returns the number of frame currently displayed by sprite
val set_frames : 'a t -> ?width:int -> Video.t -> unit
val get_frames : 'a t -> Video.t
val mask_cut : 'a t -> 'b t -> int -> unit
mask_cut from_where cut_what alpha_bias cuts all pixel's from from_where where cut_what has alpha bigger than alpha_bias
module Table: sig  end