Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
Rube and Gideros — Gideros Forum

Rube and Gideros

Tom2012Tom2012 Guru
edited December 2012 in General questions
Hello everyone

Just found the intriguing R.U.B.E and I think it will be good for my game.

I noticed it's listed on the 3rd party apps page for Gideros, but can't seem to find any info on how to use the two together.

Has anyone delved into this? Can you share any resources please?

I've checked this out:

http://www.giderosmobile.com/forum/discussion/144/proof-of-concept-conversion-of-3rd-party-box2d-editor-json-output-to-lua#Item_6

But I'm really interested in getting images to be read into Gideros too.

Thanks!

Tom

Likes: f_tm_n

+1 -1 (+1 / -0 )Share on Facebook

Comments

  • 1dot44mb1dot44mb Member
    edited December 2012
    Hi, before writing TiledAsAWorldEditor, i checked out RUBE too. First of all it is commercial, trial version does not let you save.

    It is a Box2D editor, i do not know any ways to tie the bodies to Gideros sprites, or even change their attributes runtime. But maybe there is a way but as i said 'i don't know'. When the animations come into place, things get more complicated.

    Other than that it is great, and as the name suggests, 'really useful' box2d editor.
  • Been researching into it and I see how it works now. I have to use json to convert the exported file to a lua table, then write me own code to covert to my game.

    A bit tricky for me but I like the Rube editor. I'll also have a look at the software you mentioned - thanks!
  • Tom2012Tom2012 Guru
    edited December 2012
    Here's a really rough go at getting image layouts and box2D bodies created in RUBE into Gideros...

    Might be a starting point for anyone else having a go with this tool...

    The attached image shows the images in RUBE and in the Gideros player are the same layout.
    -- Set up box2d
     
    require "box2d"
     
    local imageLayer = Sprite.new()
    stage:addChild(imageLayer)
    stage.imageLayer = imageLayer
     
    -- set up the physics on a new layer
     
    local physicsLayer = Sprite.new() -- create new sprite instance
    physicsLayer.world = b2.World.new(0, 10, true) -- add the physics on this layer
    stage:addChild(physicsLayer); -- add sprite to this scene
    stage.physicsLayer = physicsLayer; -- store in our table
     
    local debugDraw = b2.DebugDraw.new()
    physicsLayer.world:setDebugDraw(debugDraw)
    physicsLayer:addChild(debugDraw)
     
    stage:setBackgroundColor(0,0,0)
     
     
    -- Bring in atlas
    local Atlas2 = TexturePack.new("Atlases/Atlas 2.txt", "Atlases/Atlas 2.png", true)
     
    -- set scale
    -- 1 square on rube = x pixels
    local worldScale = 100
     
    -- Open json file
     
    file = io.open("001.json","r")
    text = file:read("*all")
    io.close(file)
    out = json.decode(text)
     
    -- get image
     
    for index,theImage in pairs(out.image) do
     
    	local data = explode("gfx/", theImage.file)
     
    	local image = Bitmap.new(Atlas2:getTextureRegion(data[2]))
     
    	-- Set the scale
     
    	-- get the size
    	local imageHeight = image:getHeight()
    	--print("imageHeight", imageHeight)
     
    	-- get scale
    	local scale = 100 / imageHeight
    	--print("scale", scale)
     
    	local xScale = (scale*theImage.scale)*1.030
    	local yScale = (scale*theImage.scale)*1.030
     
     
     
    	image:setScale(xScale,yScale)
     
     
    	-- get rotation
    	image:setAnchorPoint(.5,.5)
    	local angle = theImage.angle
    	image:setRotation(math.deg(angle)*-1)
     
     
    	-- set position
     
    	local x = theImage.center.x * worldScale
    	local y = (theImage.center.y * worldScale)*-1
     
     
     
    	image:setPosition(x,y)
     
     
    	-- add to scene
    	imageLayer:addChild(image)
     
    end
     
     
     
     
    -- Try to get the physics bodies
     
    for index,theBody in pairs(out.body) do
     
    -- if this is a box or a poly
     
    	if(theBody.fixture[1].polygon) then
     
    		--create box2d physical object
    		local body = physicsLayer.world:createBody{type = b2.STATIC_BODY}
     
     
    		local poly = b2.PolygonShape.new()
     
    		local coords = {}
    		local num = #theBody.fixture[1].polygon.vertices.x
     
     
     
    for i=1,#theBody.fixture[1].polygon.vertices.x do
     
    		local x = theBody.fixture[1].polygon.vertices.x[num] * 100
    		table.insert(coords,x)
     
    		local y = theBody.fixture[1].polygon.vertices.y[num] * 100 *-1
    		table.insert(coords,y)
     
    		num = num - 1
     
    end
     
     
     
    				poly:set(unpack(coords))
     
     
     
    		local fixture = body:createFixture{shape = poly, density = 1.0, 
    		friction = 0, restitution = 0}
     
    			-- Position
     
    		local x = (theBody.position.x * worldScale)
    		local y = ((theBody.position.y * worldScale)*-1)
     
    		body:setPosition(x,y)
     
    		local filterData = {categoryBits = 2, maskBits = 5}
    		fixture:setFilterData(filterData)
     
    		-- Angle
     
    		local angle = theBody.angle
     
     
    	end
     
    end
    screenshot_05.jpg
    1251 x 573 - 248K
  • Ah you'll also need this explode function...
    function explode(div,str) -- credit: <a href="http://richard.warburton.it" rel="nofollow">http://richard.warburton.it</a>
      if (div=='') then return false end
      local pos,arr = 0,{}
      -- for each divider found
      for st,sp in function() return string.find(str,div,pos,true) end do
        table.insert(arr,string.sub(str,pos,st-1)) -- Attach chars left of current divider
        pos = sp + 1 -- Jump past current divider
      end
      table.insert(arr,string.sub(str,pos)) -- Attach chars right of last divider
      return arr
    end
  • Hi Tom,

    Did you get any further with this?

    I'm about to start using R.U.B.E too.

    Thanks.

    BW
  • Tom2012Tom2012 Guru
    edited March 2014
    Sorry for the very late reply BigWinston!

    For yourself or anyone interested - I wrote a php program that takes .json files and reads them into lua tables for use in Gideros.

    http://firecroc.com/json-to-lua/

    The actual php program is below

    zip
    zip
    index.php.zip
    3K
  • Here is the class that I use to convert this output into the game
    lua
    lua
    Rube.lua
    20K
  • Tom2012Tom2012 Guru
    edited March 2014
    Here's how I work.

    1) Put the graphics together in rube
    2) Export the .json file
    3) Click on browse in my tool and choose the .json file
    4) Click 'Build'
    5) Copy the output
    6) Paste it into a new file in my game called say "level 9 data.lua"
    7) Then bring that into each level with
    --------------------------------------------------------------
    -- Rube Level Data
    --------------------------------------------------------------
     
    self.levelData = "Level Data/Level 9 Data.lua"
     
    local rube = Rube.new(self,self.levelData)
  • This might sound like a lot of effort but it allows me to create some pretty complex levels like the ones attached.

    Have a look at the online 'generator' I made, and the php script, and the rube class. I'm really basic when it comes to programming so I'm sure you'll be able to customize it to your needs.

    Let me know if I can help.
    screenshot_111.jpg
    1822 x 928 - 336K
    screenshot_112.jpg
    2148 x 1313 - 496K

    Likes: aditya

    +1 -1 (+1 / -0 )Share on Facebook
  • I'll also include one of my level files that shows how it fits together. This is the 'scene' that will be loaded.

    lua
    lua
    Level 9.lua
    9K
  • And here's a rube file for that level...

    zip
    zip
    Level 9.rube.zip
    13K
  • @Tom2012 thanks for sharing. You saved me from lots of effort.
  • Wow @Tom2012 it's really amazing, thanks for sharing. :D

    I I've been thinking about whether or not I use this tool, but I'm sure that this resource will allow me to take things more clear.

    Thanks again. :)>-
Sign In or Register to comment.