---
title: "Getting started with Gideros and PhysicsEditor"
description: "Full example with source code how to use PhysicsEditor with Gideros SDK"
canonical: "https://www.codeandweb.com/physicseditor/tutorials/physicseditor-gideros"
date: "2012-05-07T00:00:00.000Z"
modified: "2012-05-07T00:00:00.000Z"
source: "html"
---

# Getting started with Gideros and PhysicsEditor

Andreas Löw

[physicseditor](https://www.codeandweb.com/tags/physicseditor),  [gideros](https://www.codeandweb.com/tutorials/gideros.md),  [tutorial](https://www.codeandweb.com/tags/tutorial)

[GitHub](https://github.com/CodeAndWeb/PhysicsEditor-Gideros)

![Getting started with Gideros and PhysicsEditor](https://www.codeandweb.com/static/70cabc1aa478b355e76cee9018bd2a88/a6312/post-image.png)

A code snippet that shows how to use game physics with Gideros Mobile. Full source code to this example project is available on [GitHub](https://github.com/CodeAndWeb/PhysicsEditor-Gideros) .

```lua
--[[
--
-- Gideros
--
-- by GiderosMobile  (http://www.giderosmobile.com/)
--
--
]]

require "box2d"

-- set the MKS (meters-kilogram-second)
b2.setScale(20)

-- this table holds the dynamic bodies and their sprites
local actors = {}

-- create world
local world = b2.World.new(0, 9.8)


--we load the PhysicsData containing all PhysicsEditor's information for our bodies,
--obviously exported with "Gideros" exporter.

local scaleFactor = 1.0
local physics = (loadfile "PhysicsData.lua")().physicsData(scaleFactor)


-- create floor body
local floorBody = world:createBody{type = b2.STATIC_BODY}
floorBody.name = "floor"
floorBody:setPosition(0,960)
physics:addFixture(floorBody, "floor")
-- create floor sprite and add it to stage
local floor = Bitmap.new(Texture.new("floor.png"))
floor:setAnchorPoint(physics:getAnchorPoint("floor"))
floor:setY(960)
stage:addChild(floor)


-- we create a global table with all falling object's names within
local foodTable = { 'drink', 'hamburger', 'hotdog', 'icecream', 'icecream2', 'icecream3' ,'orange'}

local function createFallingObjects()

    -- we get a random item from the food table
    item = foodTable[math.random(#foodTable)]

	-- create the body at a random x position
	local body = world:createBody{type = b2.DYNAMIC_BODY, position = {x = math.random(640), y = 0}}
	body.name = item
	physics:addFixture(body, item)

	-- craete a related sprite
	local sprite = Bitmap.new(Texture.new(item..".png"))
	sprite:setAnchorPoint(physics:getAnchorPoint(item))
	sprite:setPosition(body:getPosition())
	stage:addChild(sprite)

	actors[body] = sprite
end

-- we give a first run to the above function
createFallingObjects()

-- create a timer with 20 repetitions
timer = Timer.new(1000,20)
timer:addEventListener(Event.TIMER, createFallingObjects)
timer:start()

-- step the world and then update the position and rotation of sprites
local function onEnterFrame()
	world:step(1/60, 8, 3)
	for body,sprite in pairs(actors) do
		sprite:setPosition(body:getPosition())
		sprite:setRotation(body:getAngle() * 180 / math.pi)
	end
end

stage:addEventListener(Event.ENTER_FRAME, onEnterFrame)
```

## Structured data

```json
{
  "@context": "https://schema.org",
  "@type": "TechArticle",
  "headline": "Getting started with Gideros and PhysicsEditor",
  "author": [
    {
      "@type": "Person",
      "name": "Andreas Löw"
    }
  ],
  "dateModified": "2012-05-07T00:00:00.000Z",
  "image": "/static/70cabc1aa478b355e76cee9018bd2a88/a6312/post-image.png"
}
```
