Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
Graphic groups? — Gideros Forum

Graphic groups?

BeatsBeats Member
edited June 2012 in General questions
I am new Gideros user and I previously used Corona SDK. In Corona I made game and there was two groups for graphics. One for all moving graphic objects and one for static game UI graphics. I could make new group with this code: local UI = display.newGroup() and then I just inserted my graphics to that group.

So how can I make same in Gideros? I have searched but haven't found anything. If I have understood right, there is automatically "group" called "stage" and I can insert my graphics to it with code stage:addChild(image)
But how can I make another "stage" where I can put other graphics? I hope I get help soon and thanks for helpers!

Comments

  • ScouserScouser Guru
    edited June 2012
    Just use something like
    static = Sprite.new()
    mobile = Sprite.new()
    stage:addChild(static)
    stage:addChild(mobile)
     
    static:addChild(static1)
    static:addChild(static2)
    static:addChild(static3)
    static:addChild(static4)
     
    mobile:addChild(mobile1)
    mobile:addChild(mobile2)
    mobile:addChild(mobile3)
    mobile:addChild(mobile4)
    As far as I know, stage is just a Sprite & a Sprite can be used just the same as a group in the beer sdk.
  • What @scouser said - In Gideros the sprite is a container and you can use the addChild() and addChildAt() functions to create a display hierarchy. Both the Shape and Bitmap classes extend Sprites (Shape is for vector and Bitmap is for textures / raster images) and so you can add Shapes & Bitmaps to a sprite parent group.

    You can then just move / transform the parent and the children all get moved / transformed as well.

    As Shape & Bitmap objects are also technically Sprites as well, you can call addChild on them as well, in that case the object is drawn first, then each child is drawn in the order added.

    The "stage" object is actually a global that's declared by the framework and represents the "root" of the display system. If you want something to be drawn, it has to be added to the "stage" or one of it's children.

    Hope this helps!

    Likes: hgvyas123, atilim

    WhiteTree Games - Home, home on the web, where the bits and bytes they do play!
    #MakeABetterGame! "Never give up, Never NEVER give up!" - Winston Churchill
    +1 -1 (+2 / -0 )Share on Facebook
  • atilimatilim Maintainer
    edited June 2012
  • BeatsBeats Member
    Thanks for help! Problem solved, now I just need to learn few other things how Gideros works compared to Corona and then I can fully concentrate on my new game.
  • Ask away - there's plenty of ex Corona dev's hanging around here.
    Personally I'm currently looking into replicating the storyboard api and the widget api
    WhiteTree Games - Home, home on the web, where the bits and bytes they do play!
    #MakeABetterGame! "Never give up, Never NEVER give up!" - Winston Churchill
  • BeatsBeats Member
    Well when I want to make image to physical object, in Corona that was so easy, you just add physics to it with one line code and that's it. But now in Gideros I need to first add image and then make another matching physical body. And finally I need to update images position and rotation that it matches with physical body every frame? That is pretty slow if you have many physical objects. Is there any faster way?
  • hgvyas123hgvyas123 Guru
    edited June 2012
    @beats

    you can create one function like this
    function Sprite:createCircleBody(radius,bodyType)
    	if bodyType == nil then
    		bodyType = b2.DYNAMIC_BODY
    	end
     
    	local body = world:createBody{type = bodyType, position = {x = self:getX(), y = self:getY()}}
     
    	local shape = b2.CircleShape.new(0, 0, radius)
    	body:createFixture{shape = shape, density = 1,fixedRotation = self.FixedRotation or false,isSensor = self.isSensor or false, restitution = 0.5, friction = 0.0}
    	body.sprite = self
    	self.body = body
    end
     
     
    local img = Bitmap.new(Texture.new("myImg.png"))
    img.isSensor = false
    img:setPosition(0,0)
    stage:addChild(img)
    img:createCircleBody(50)
     
    or
     
    function Sprite:createBoxBody(bodyType,width,height)
     
    	if bodyType == nil then
    		bodyType = b2.DYNAMIC_BODY
    	end
    	local body = world:createBody{type = bodyType,position = {x = self:getX(), y = self:getY()}}
     
     
     
    	body:setAngle(self:getRotation()* math.pi/ 180 )
    	local shape = b2.PolygonShape.new()
    	if width == nil then
    		width = sprite:getWidth()*0.5
    	end
    	if height == nil then
    		height = sprite:getHeight()*0.5
    	end
    	shape:setAsBox(width,height)
     
    	body:createFixture{shape = shape, density = 1,isSensor = self.isSensor or false}
    	body.sprite = self
    	self.body = body
     
    end
     
    local img = Bitmap.new(Texture.new("myImg.png"))
    img.isSensor = false
    img:setPosition(0,0)
    img:createBoxBody(b2.KINEMATIC_BODY,50,50)
    stage:addChild(img)
Sign In or Register to comment.