Hi guys,
Finally I can start learning Gideros .
I started my first example, and I found a little strange thing.
The Textfield doesn't appear in the red box.
I watched in the Gideros tutorials,it uses the similar coordinates system to flash, and I didn't find in the documentation, if the Textfield has a different coordinate.
Any object what I add with addChild, the player view in the correct position.
Anybody know why happened this ?
// CODE
FirstButton = Core.class(Sprite)
function FirstButton:init()
local text = TextField.new(nil, "Change direction")
local shape = Shape.new() -- create the shape
shape:beginPath()
shape:setLineStyle(1,0xddeecc,0.7)
shape:setFillStyle(Shape.SOLID, 0xff0000, 0.5)
shape:lineTo(0,0)
shape:lineTo(text:getWidth()+10,0)
shape:lineTo(text:getWidth()+10,text:getHeight()+10)
shape:lineTo(0,text:getHeight()+10)
shape:lineTo(0,0)
shape:endPath()
print(text:getY(0))
self:addChild(shape)
self:addChild(text)
end
local rotate_btn = FirstButton.new()
local countNum = 1
local orientations ={Application.PORTRAIT,Application.PORTRAIT_UPSIDE_DOWN,Application.LANDSCAPE_LEFT,Application.LANDSCAPE_RIGHT}
local rotateScreen = function ()
countNum = countNum + 1
if countNum > #orientations then
countNum = 1
end
application:setOrientation(orientations[countNum])
end
rotate_btn:addEventListener(Event.MOUSE_DOWN, rotateScreen)
stage:addChild(rotate_btn)
or
Thanks a lot for any suggestion.
NG
Comments
Also, just some small things you may want to look out for/find easier:
Instead of doing the last shape:lineTo(0,0) you can do shape:closePath() and it will automatically draw a line to the originating point. I also usually start with shape:moveTo() instead of lineTo() for the first point (not sure if it makes a difference).
And your event listener will fire whenever someone clicks anywhere on the screen right now. All sprites will receive any touch/mouse event, so you need to add a parameter to your rotateScreen function and test the point like so:
Put this (where the print statement is) to compensate for the way that text is positioned
cheers
evs
Thanks all, for the code optimization and for the good explanation.
Have a nice day
NG
It seems that it is bottom left.
Author of Learn Lua for iOS Game Development from Apress ( http://www.apress.com/9781430246626 )
Cool Vizify Profile at https://www.vizify.com/oz-apps
Thank you for clarify
Also there is an undocumented function Sprite:getBounds(targetSprite). It returns the exact bounds as x, y, width and height which appears in another coordinate system (targetSprite's coordinate system).
For example, you can use Sprite:getBounds function to get untransformed local bounds as: