Positioning objects - Can't get it to work

Hey guys,

I’m trying to make a business type of app. Now, I’d like to place my a card under my navbar (these are basically just rects).

This is how I create the navbar:

function M.getHeight() return centerY \* 0.35 end function M.new(opt) local bg = display.newRect(centerX, originY, actualW, M.getHeight()) bg.anchorY = 0 bg:setFillColor(175/255, 65/255, 74/255) navbar:insert(bg) local navbarCenterX, navbarCenterY = bg:localToContent( 0, 0 ) if (opt.title ~= nil) then local title = display.newText(opt.title, centerX, navbarCenterY, native.systemFontBold, 20) title.anchorY = 0 navbar:insert(title) end if ((opt.menu ~= nil) and (opt.menu == true)) then local menu = display.newImageRect("Assets/Img/Icon/menu.png", bg.height \* 0.4, bg.height \* 0.4) menu.x, menu.y = originX + 5, (navbarCenterY - (menu.height \* 0.15)) menu.anchorY, menu.anchorX = 0, 0 navbar:insert(menu) end if ((opt.transparent ~= nil) and (opt.transparent == true)) then bg.alpha = 0.85 end return navbar end

The card module also defines a method “new()” which allows a param “y” which should be the height.

Here is the code for that:

function M.getHeight() return centerY \* 0.7 end function M.new(y) local bg = display.newRect(centerX, centerY, actualW, M.getHeight()) bg:setFillColor(175/255, 65/255, 74/255) bg.anchorY = 0 card:insert(bg) bg.y = y return card end

So, my thought was that if I’d want to make a new card under my navbar, I could simply call the function like this:

card.new(navbar.getHeight)

but that does not position is correctly :frowning:

I feel like I should not be struggling with this, but I can really not figure it out…

Could someone give me some help?

Kind regards

Bram

I’m not sure how it does not position correctly but it may be related to the :localToContent() part of the code in navbar module.

Hi bgmadclown,

I just found out the problem. I had to add the height with my originY! :slight_smile:

I’m not sure how it does not position correctly but it may be related to the :localToContent() part of the code in navbar module.

Hi bgmadclown,

I just found out the problem. I had to add the height with my originY! :slight_smile: