Migration x(y)Reference -> anchorX(Y) not interchangeable

Hi

In old version corona sdk I can set xReference and yReference any value like 100, - 100 etc. And I can set this point outside object (it’s very important!!!)

Now I try change all my game (ready and publishing on stores) to v2.0 and have big problem with anchorX and anchorY, because its can set from [0, 1] and only inside object.

For little example how do such as the planet’s rotation around an external point (like sun). With old API its several lines. How do it using anchorX and anchorY and not using formulas?

I have simular problem with xAnchor and yAnchor when porting game with Marmalade Quick. xAnchor  and yAnchor in Maralade doc range [0,1], but when I use - 1, - 100, 100, 2.345 its work fine and solved my problem. In new Corona API if I set like anchorX = - 1.5 then anchorX = 0.

So what I can use instead x(y)Reference ?

You can use the v1 compatibility mode to keep the setReferencePoint API.  Add:

graphicsCompatibility = 1

in your config.lua at the same place where you would put your width and height.

Rob

Thank you Rob,

but I want change my game for future Windows Phone support as I now windows will be work only with corona v 2. I dont have so much time to rewrite all my logic for corona v2 I want quick migrate to v 2 (and I all change successfull), but have only one problem described above.

it’s difficult add support anchor outside object or add some other property?

One way would be to group the objects in a container.

Make the container bigger than the object and use the object’s anchors and x, y to position the object within the container.

You can then use the container’s anchors and x, y to position the object with an offset on the stage.

local r = display.newRect(0, 0, 100, 50); r:setFillColor(1); r.anchorX = 0; r.x = 50; local c = display.newContainer(300, 50); c:insert(r); c.x = 20; c.y = 100; c.anchorX = 0; transition.to(c, {delay=1000, time=2000, rotation=30})

You can use the v1 compatibility mode to keep the setReferencePoint API.  Add:

graphicsCompatibility = 1

in your config.lua at the same place where you would put your width and height.

Rob

Thank you Rob,

but I want change my game for future Windows Phone support as I now windows will be work only with corona v 2. I dont have so much time to rewrite all my logic for corona v2 I want quick migrate to v 2 (and I all change successfull), but have only one problem described above.

it’s difficult add support anchor outside object or add some other property?

One way would be to group the objects in a container.

Make the container bigger than the object and use the object’s anchors and x, y to position the object within the container.

You can then use the container’s anchors and x, y to position the object with an offset on the stage.

local r = display.newRect(0, 0, 100, 50); r:setFillColor(1); r.anchorX = 0; r.x = 50; local c = display.newContainer(300, 50); c:insert(r); c.x = 20; c.y = 100; c.anchorX = 0; transition.to(c, {delay=1000, time=2000, rotation=30})

Thanks for your solution igemar, very smart.

I’d like to contribute with a minor improvement that gets rid of masks. Using multiple masks can give you problems due to the Texture Units limit and I think they also consumes more processing capacity, but of that I am not sure.

Use an invisible rectangle instated:

 local superG=display.newGroup() superG.anchorChildren=true local referenceRect=display.newRect(superG, display.screenOriginX, display.screenOriginY, display.contentWidth, display.contentHeight) referenceRect.isVisible=false

and then to scale

 local originX, originY = event.xReference, event.yReference superG.anchorX, superG.anchorY = originX/display.contentWidth, originY/display.contentHeight superG.x, superG.y = originX, originY superG.xScale=.01 superG.yScale=.01 transition.to(superG, {xScale=1, yScale=1})

Ernest B.

Hi Rob ,

http://developer.coronalabs.com/code/puzzleapp

 

 Itz jigsaw puzzle game. But I find it difficult in touching and dragging the image.Is there a problem with my device or there is really some problem with touch? 

The source for those gave me 404 errors when I went to look at it. But given it’s age and I don’t believe the author is doing Corona apps any more, the code is probably not compatible with our current version of Corona SDK.  Since I couldn’t see the code, I can’t see how difficult it will be to adapt it to the new engine.

Rob

I am sorry and i mean it Rob for the unknown source.  https://github.com/LadySobriquet/Puzzle-App , this is the correct source where you can see the code of this Corona app .    

Thank you

You could try adding this line to your config.lua where you define the width and height:

graphicsCompatibility = 1

And see if that helps things.  However this is not a long term solution.  You should learn the new techniques of Graphics 2.0.  This guide will help you convert it to the new way.  http://docs.coronalabs.com/guide/graphics/migration.html

Rob

yes Rob , i have tried to run this code in compatibility mode .but it is not working, So let me try to understand the migration of reference point to anchor point .

Thank you 

Hi alexandr

Try this function for convert xReference and yReference to anchorX and anchorY

I am sure it will work for you.

local min, max = math.min, math.max

 

function setAnchorCoordinates( object, xReference, yReference )

  object.anchorX = min( 1, max( 0, (xReference / object.width)+.5))

  object.anchorY = min( 1, max( 0, (yReference / object.height)+.5))

end

 

Regards,

 

Sptechnolab Team

You can always do it as a mixin if it is just the setReferencePoint() method you are after (probably not wise to tinker with the display.group prototype …) e.g.

-- setreference point decorating. display.newLine(0,240,320,240):setStrokeColor( 0,1,0 ) display.newLine(160,0,160,480):setStrokeColor( 0,1,0 ) local r = display.newRect(0,0,100,100) r:setFillColor( 0,0,1 ) r.x,r.y = 160,240 r:toBack() r:setStrokeColor(1,1,1) r.strokeWidth = 1 function decorateReference(obj) display.TopLeftReferencePoint = 0 -- Define the required constants. These are done this way to make display.TopCenterReferencePoint = 1 -- the calculation easy. display.TopRightReferencePoint = 2 display.CenterLeftReferencePoint = 3 display.CenterReferencePoint = 4 display.CenterRightReferencePoint = 5 display.BottomLeftReferencePoint = 6 display.BottomCenterReferencePoint = 7 display.BottomRightReferencePoint = 8 obj.setReferencePoint = function(self,refPoint) obj.anchorX = refPoint % 3 / 2 obj.anchorY = math.floor(refPoint / 3) / 2 end return obj end r = decorateReference(r) -- you can chain this e.g. r = decorateReference(display.newRect()) r:setReferencePoint(display.CenterRightReferencePoint)

Hi
 
Thanks to everyone, especially grateful to SP Technolab your method work perfectly. I think it should be included in the migration guides for those who want quickly move for Graphics 2.0.
 
Best regards
Alexander

Thanks for your solution igemar, very smart.

I’d like to contribute with a minor improvement that gets rid of masks. Using multiple masks can give you problems due to the Texture Units limit and I think they also consumes more processing capacity, but of that I am not sure.

Use an invisible rectangle instated:

 local superG=display.newGroup() superG.anchorChildren=true local referenceRect=display.newRect(superG, display.screenOriginX, display.screenOriginY, display.contentWidth, display.contentHeight) referenceRect.isVisible=false

and then to scale

 local originX, originY = event.xReference, event.yReference superG.anchorX, superG.anchorY = originX/display.contentWidth, originY/display.contentHeight superG.x, superG.y = originX, originY superG.xScale=.01 superG.yScale=.01 transition.to(superG, {xScale=1, yScale=1})

Ernest B.

Hi Rob ,

http://developer.coronalabs.com/code/puzzleapp

 

 Itz jigsaw puzzle game. But I find it difficult in touching and dragging the image.Is there a problem with my device or there is really some problem with touch? 

The source for those gave me 404 errors when I went to look at it. But given it’s age and I don’t believe the author is doing Corona apps any more, the code is probably not compatible with our current version of Corona SDK.  Since I couldn’t see the code, I can’t see how difficult it will be to adapt it to the new engine.

Rob

I am sorry and i mean it Rob for the unknown source.  https://github.com/LadySobriquet/Puzzle-App , this is the correct source where you can see the code of this Corona app .    

Thank you