Bottle 2D - Lua API 1.0.0
All you need to create games using bottle2D.
|
A screen represent a part of your game where differenent physic and drawable object will evolve. More...
#include <header.hpp>
Public Member Functions | |
EventHandlerBase | RegisterButtonEvent (luaObject luaFunction, string keyName, bool pressed) |
Create a new button event. | |
EventHandlerBase | RegisterButtonInZoneEvent (luaObject luaFunction, MouseZoneEvent zoneEvt, string keyName, bool pressed) |
Create a new button in zone event. | |
EventHandlerBase | RegisterMouseMoveEvent (luaObject luaFunction) |
Create a new mouse move event. | |
Timer | RegisterTimer (luaObject luaFunction, number numbererval, bool isRunning=true) |
Create a new Timer. | |
Chronometer | RegisterChronometer (luaObject luaFunction, number totalTime, bool isRunning=true) |
Create a new chronometer. | |
MouseZoneEvent | RegisterMouseZoneEvent (luaObject luaFunction, PhysicObject zone) |
Create a new mouse in zone event. | |
EventHandlerBase | RegisterFrameEvent (luaObject luaFunction) |
Create a new Frame Event. | |
nil | PlaySound (Sound sound) |
Play a the sound. | |
nil | SetMouseRelative (bool relative) |
Turn on / off the mouse relative mode (cf: Screen::RegisterMouseMoveEvent) | |
bool | IsMouseRelative () |
Tels if the mouse is in a relative or absolute mode. | |
nil | ShowCursor (bool show) |
Show / hide the mouse cursor. | |
bool | IsCursorVisible () |
Tels if the mouse cursor is shown. | |
number | GetEventCount () |
Get the number of event and pseudo event registered in this screen. | |
nil | SetTimeSpeed (number timeSpeed) |
Set time speed. | |
number | GetTimeSpeed () |
Get time speed. | |
nil | AddPhysicGroup (number phGroupId1, number phGroupId2) |
Add a physic grpoup. | |
Color | GetBackgroundColor () |
Get the screen background color (also used for strip colors) | |
nil | SetBackgroundColor (Color color) |
Set the screen background color (also used for strip colors) | |
ScreenConfig | GetScreenConfig () |
Get the screen configuration. | |
nil | SetScreenConfig (ScreenConfig screenConfig) |
Set the screen configuration. | |
Public Attributes | |
float | timeSpeed |
Show the FPS (for optimisation) | |
Color | backgroundColor |
Access the screen background color (also used for strip colors) | |
ScreenConfig | screenConfig |
Access the screen configuration. |
A screen represent a part of your game where differenent physic and drawable object will evolve.
You can also attach event to your screen.
A bottle 2D app will always need a screen to run, but it is recomanded to use more than one. For example, you can create a menu screen and a game screen.
Then, when you can switch to the game / menu by calling ChangeScreen(). When a screen is not running, it is freezed : no sound, physic and events are proceeded.
Screens are created using the global function CreateScreen().
nil Screen::AddPhysicGroup | ( | number | phGroupId1, |
number | phGroupId2 | ||
) |
Add a physic grpoup.
To use physic intersecion events, you have to add some "physic group".
Each physic object has a group id which is attributed at creation. The engine will only test collisions between somme registered groups. So if you want to receive event when object of group 1 intersect object from group 3, you have to call AddPhysicGroup(1, 3) or AddPhysicGroup(3, 1).
Note: AddPhysicGroup(2, 2) is legal.
Color Screen::GetBackgroundColor | ( | ) |
Get the screen background color (also used for strip colors)
number Screen::GetEventCount | ( | ) |
Get the number of event and pseudo event registered in this screen.
ScreenConfig Screen::GetScreenConfig | ( | ) |
Get the screen configuration.
number Screen::GetTimeSpeed | ( | ) |
Get time speed.
bool Screen::IsCursorVisible | ( | ) |
Tels if the mouse cursor is shown.
bool Screen::IsMouseRelative | ( | ) |
Tels if the mouse is in a relative or absolute mode.
nil Screen::PlaySound | ( | Sound | sound | ) |
Play a the sound.
A sound is linked to a screen. If you change screen, the sound will be paused and will resume when you select back the screen.
EventHandlerBase Screen::RegisterButtonEvent | ( | luaObject | luaFunction, |
string | keyName, | ||
bool | pressed | ||
) |
Create a new button event.
The lua function luaFunction will be called each time the button keyName is pressed (if pressed = true) or released (if pressed = false).
Prototype of the called lua function : function luaFunction(keyName : string, pressedStatus : bool, thisEvent : EventHandlerBase).
Note: if keyName is empty (keyName = ""), then the lua function will be called each time a button is pressed / released.
Note2: The buttons could be mouse buttons, keyboard buttons and even joystick buttons.
See List of key names for the list of keys.
EventHandlerBase Screen::RegisterButtonInZoneEvent | ( | luaObject | luaFunction, |
MouseZoneEvent | zoneEvt, | ||
string | keyName, | ||
bool | pressed | ||
) |
Create a new button in zone event.
The lua function luaFunction will be called each time the button keyName is pressed (if pressed = true) or released (if pressed = false) and the mouse is in the zone corresponding to the zoneEvt.
Parameters of the called lua function : the key name (string), the pressed status (bool), the MouseZoneEvent which corresponds to the zone and the EventHandlerBase.
Note: if keyName is empty (keyName = ""), then the lua function will be called each time a button is pressed / released.
Note2: The buttons could be mouse buttons, keyboard buttons and even joystick buttons.
See List of key names for the list of keys.
Chronometer Screen::RegisterChronometer | ( | luaObject | luaFunction, |
number | totalTime, | ||
bool | isRunning = true |
||
) |
Create a new chronometer.
The lua function luaFunction will be called at each frame during totalTime. It is very useful to create mouvement.
Parameters of the called lua function : the elapsed time ratio (float) and this Chronometer.
Note: The engine ensure that the function receive a ratio of 1 at the end of the chronometer.
EventHandlerBase Screen::RegisterFrameEvent | ( | luaObject | luaFunction | ) |
Create a new Frame Event.
The lua function luaFunction will be called at each frame with the frame time (time between the last frame) and this eventHandler as a parameter
EventHandlerBase Screen::RegisterMouseMoveEvent | ( | luaObject | luaFunction | ) |
Create a new mouse move event.
The lua function luaFunction will be called each time the mouse is moved.
Parameters of the called lua function : the mouse position (Vector2D) and this EventHandlerBase.
Note: if the mouse is configured as relative (cf: SetMouseRelative), then the position argument is the relative mouse mouvement.
MouseZoneEvent Screen::RegisterMouseZoneEvent | ( | luaObject | luaFunction, |
PhysicObject | zone | ||
) |
Create a new mouse in zone event.
The lua function luaFunction will be called each time the mouse enter or leave the PhysicObject zone.
Parameters of the called lua function : this MouseZoneEvent.
Note : Use MouseZoneEvent::IsInside() to see if the mouse is currently inside
Timer Screen::RegisterTimer | ( | luaObject | luaFunction, |
number | numbererval, | ||
bool | isRunning = true |
||
) |
nil Screen::SetBackgroundColor | ( | Color | color | ) |
Set the screen background color (also used for strip colors)
nil Screen::SetMouseRelative | ( | bool | relative | ) |
Turn on / off the mouse relative mode (cf: Screen::RegisterMouseMoveEvent)
nil Screen::SetScreenConfig | ( | ScreenConfig | screenConfig | ) |
Set the screen configuration.
nil Screen::SetTimeSpeed | ( | number | timeSpeed | ) |
Set time speed.
nil Screen::ShowCursor | ( | bool | show | ) |
Show / hide the mouse cursor.
Access the screen background color (also used for strip colors)
Access the screen configuration.
float Screen::timeSpeed |
Show the FPS (for optimisation)
Tels if FPS ate shown Access current time speed. Elapsed time = RealTime * timeSpeed