Skip to content

Difference between Ocsfml and the original SFML

kyoDralliam edited this page May 31, 2012 · 2 revisions

Even though Ocsfml tries to remain the closer to SFML, it presents a few differences. Here is a non exhaustive list:

General

  • Each SFML module correspond to one ocaml module.

  • When inheriting from a SFML class, you must indicate it as well as the name of the methods you overload, as follow : inherit drawable ~overloaded:[`draw] (Drawable.inherit ())

  • Resource classes constructors takes a polymorphic variant, indicating the resource to be loaded (or `None). In case of failure, LoadFailure exception is thrown.

  • Properties of some classes (transformable, sprite, sound, ...) may be set in the constructors, using optional parameters.

  • Overloaded function and methods were renamed.

System

  • Vectors are tuples of ints or floats.
  • Time is a module, not a class.
  • Milliseconds are stored as an ocaml int which is, on 32-bits platform, 31 bits long (and not 32).
  • Operators are implemented as functions : add, sub, mul, mul_float, div and div_float

Window

  • Key enum is in not in Keyboard module, but in a KeyCode module
  • Joystick ids are represented by a special type, Joystick.id. It may be constructed using Joystick.id_from_int function, and casted into an int.
  • Mouse related event types are tuples. Coordinates are stored in a record, mouseCoord, which is last field.
  • Joystick related event types are as well tuples.
  • VideoMode is a module. It has a create function which may act as the VideoMode's constructor in SFML.
  • context_settings is a record. A mk_context_settings function is provided as well.
  • poll_event and get_event window methods don't take parameters and return an Event.t option
  • A pixel array are represented as a three dimensional bigarray : width x height x 4

Graphics

  • rect is a polymorphic record. Methods to manipulate int rect and float rect are provide in IntRect and FloatRect modules.
  • Color is a module. Two functions act as constructors : Color.rgb and Color.rgba
  • Operators are implemented as functions : Color.add and Color.modulate
  • class transform takes an optional matrix parameters (tuples of nine floats)
  • class transformable, sprite, rectangle_shape, circle_shape, convex_shape, text' properties (position, rotation, texture...) may be initialized using named optional parameters.