Content Position Problems

Hi, I used Corona many years ago and loved it. I have recently opened up Solar2D and I am having real problems with my content position on the screen. The apps I created in 2010/11 work as in all the functionality is there and I can move/replace images/buttons etc. However, my content is half way over on the left of the screen and half way up!!! It is driving me bananas…please help if you can! TIA Regards Bob

Given how old the apps are, I’d wager they are using graphics version 1, which was deprecated around 2014 if I remember correctly.

One of the changes was how anchors worked. Again, if I remember correctly, with graphics v1, display objects were anchored by their top left corner by default whereas now they are anchored by their centre by default.

This particular issue would likely be resolved by manually setting the following anchor for the affected objects:

object.anchorX = 0
object.anchorY = 0

You could also see about setting the default values for the anchors to 0, see: Solar2D Documentation — API Reference | Libraries | display | setDefault

Hi XeduR,

Thanks for taking the time to respond. Much appreciated. I have fixed this issue but now have another.

The old app has a number of screens that are selected randomly using the “shake” function and it still works. I used a code someone on this forum provided. However, I now do not want to use the ‘shake’ function to change screens but a button. However, I can’t seem to get this. Here is the existing code with “shake” function. Any help would be very much appreciated. Thanks again.
Regards
Bob

module(…, package.seeall)

function new()
local localGroup = display.newGroup()
→ This is how we start every single file or “screen” in our folder, except for main.lua
– and director.lua
→ director.lua is NEVER modified, while only one line in main.lua changes, described in that file


local background = display.newImage (“shake.png”)
localGroup:insert(background)
→ This sets the background

local bletherbutton = display.newImage (“bletherbutton.png”)
bletherbutton.x = 332
bletherbutton.y = 715
localGroup:insert(bletherbutton)

local img = { “1.png”, “2.png”, “3.png”, “4.png”, “5.png”, “6.png”, “7.png”,“8.png”,“9.png”,“10.png”,“11.png”,
“12.png”,“13.png”,“14.png”,“15.png”,“16.png”,“17.png”,“18.png”,“19.png”,“20.png”,“21.png”,“22.png”,“23.png”,
“24.png”,“25.png”,“26.png”,“27.png”,“28.png”,“29.png”,“30.png”,“31.png”,“32.png”,“33.png”,“34.png”,“35.png”,
“36.png”,“37.png”,“38.png”,“39.png”,“40.png”,“41.png”,“42.png”,“43.png”,“44.png”,“45.png”,“46.png”,“47.png”,
“48.png”,“49.png”,“50.png”,};

local function onShake(event)
if event.isShake then
math.randomseed ( os.time () )
local r = math.random(1,#img);
local image = display.newImage(img[r], 0, 0);
end

return true;
end

Runtime:addEventListener(“accelerometer”, onShake);

return localGroup
end

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.