Running from local file ⚠️
It seems like you have opened this file by double-clicking on it. In order to test your build in a browser
you need to load this file from a web server. You can either upload this file and the rest of the files from a Defold HTML5 bundle to a web hosting service OR host them using a local web server on your home network.
Learn more about running a local web server in the Defold HTML5 manual. Setup
The setup consists of two game objects.
The invisible trigger. Contains:
Collision object component. The Type is set to
TRIGGER. A box
Shape is added to the components. bunny
The bunny. Contains:
Sprite component with the bunny image. A
Collision object component. It has Type set to
DYNAMIC. A sphere
Shape matching the sprite image is added to the components. A
Script component that animates the bunny’s position and reacts to physics messages when interacting with the trigger. Scripts
function init ( self )
local pos = go . get_position () -- <1>
go . animate ( "." , "position.x" , go . PLAYBACK_LOOP_PINGPONG , pos . x + 600 , go . EASING_INOUTSINE , 6 )
function on_message ( self , message_id , message , sender )
if message_id == hash ( "trigger_response" ) then -- <2>
if message . enter then -- <3>
msg . post ( "#sprite" , "disable" ) -- <4>
msg . post ( "#sprite" , "enable" ) -- <5>
1. Get the current position, then animate the position's x component
looping in a ping-pong manner against an offset of 600.
2. The physics engine has detected that this game object contains
collision object components that have collided with a trigger.
3. The `message` data table contains a field `enter` that is set
to `true` when the trigger event signals that the trigger shape
was entered. On exiting the trigger, this field is `false`.
4. Disable the sprite when the trigger is entered
5. Enable the sprite again on exit.
If you want to play with these examples, you can get the project on Github.
Do you want to see more examples? Why not write a few yourself and submit a pull request? We love contributions.