Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Migration x(y)Reference -> anchorX(Y) not interchangeable
Started by alexandr Dec 04 2013 06:44 AM

12 replies to this topic
xreference yreference anchorx anchory migration guide
[TOPIC CONTROLS]
This topic has been archived. This means that you cannot reply to this topic.
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

alexandr

[GLOBAL: userInfoPane.html]
alexandr
  • Observer

  • 27 posts
  • Corona SDK

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 ?



[TOPIC: post.html]
#2

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 26,544 posts
  • Enterprise

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



[TOPIC: post.html]
#3

alexandr

[GLOBAL: userInfoPane.html]
alexandr
  • Observer

  • 27 posts
  • Corona SDK

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?



[TOPIC: post.html]
#4

ingemar

[GLOBAL: userInfoPane.html]
ingemar
  • Corona Geek

  • 2,733 posts
  • Enterprise

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})



[TOPIC: post.html]
#5

igenapps

[GLOBAL: userInfoPane.html]
igenapps
  • Enthusiast

  • 66 posts
  • Corona SDK

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.



[TOPIC: post.html]
#6

divakarjoshi257

[GLOBAL: userInfoPane.html]
divakarjoshi257
  • Enthusiast

  • 38 posts
  • Corona SDK

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? 



[TOPIC: post.html]
#7

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 26,544 posts
  • Enterprise

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



[TOPIC: post.html]
#8

divakarjoshi257

[GLOBAL: userInfoPane.html]
divakarjoshi257
  • Enthusiast

  • 38 posts
  • Corona SDK

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



[TOPIC: post.html]
#9

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 26,544 posts
  • Enterprise

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



[TOPIC: post.html]
#10

divakarjoshi257

[GLOBAL: userInfoPane.html]
divakarjoshi257
  • Enthusiast

  • 38 posts
  • Corona SDK

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 



[TOPIC: post.html]
#11

SP Technolab

[GLOBAL: userInfoPane.html]
SP Technolab
  • Enthusiast

  • 62 posts
  • Corona SDK

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



[TOPIC: post.html]
#12

paulscottrobson

[GLOBAL: userInfoPane.html]
paulscottrobson
  • Contributor

  • 456 posts
  • Corona SDK

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)


[TOPIC: post.html]
#13

alexandr

[GLOBAL: userInfoPane.html]
alexandr
  • Observer

  • 27 posts
  • Corona SDK

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


[topic_controls]
[/topic_controls]