I can't really understand why it doesn't work.
If i use
Shape:hitTestPoint(event.x,event.y)==true
it works.
But when i try Shape:getX() it returns 0.
Why so?
And is there any simple method to draw line in real time? I mean set start point on mouse down and then redraw it every time on MouseMove?
And how often MouseMove happens? Because if i use lineTo(event.x,event.y) onMouseMove and move mouse fast enough i have not straight line, but dashed.
Comments
most probably your shape is at 0 0 coordinate, thats why getX returns 0.
Although shape is as 0;0 coordinate, you can draw using moveTo/lineTo in any place, shape will still be at 0;0
And mouse move I'd guess it is updated as often as onEnterFrame is.
Hmm, I don't get how you can have dashed line, if you are drawing from the last point to current. Can you show the code ?
My shape has 20,20,30,30 coordinates, for example. But it still returns 0.
I attached screenshot. Every shape from screen returns 0 on getX() or getY(). I can't understand why.
code for dashed line
function game:onMouseMove(event)
line[linecur]:lineTo(event.x,event.y)
line[linecur]:endPath()
self:addChild(line[linecur])
end
But it is not what i really want. I want straight line that redraws every time.
I thought it should works something like that
line[linecur]:clear()
line[linecur]:lineTo(event.x,event.y)
line[linecur]:endPath()
self:addChild(line[linecur])
line[linecur]:moveTo(startx,starty)
but it doesn't. Something wrong with my logic:(
you should have to use shape api like this
Likes: unlying
But? Is it really ok???
About line. It works for me now.
If anybody will need this too:
function game:onMouseMove(event)
if oldy~=event.y then
line[linecur]:clear()
line[linecur] = Shape.new()
line[linecur]:setLineStyle(3)
line[linecur]:setFillStyle(Shape.SOLID, color)
line[linecur]:beginPath()
line[linecur]:moveTo(startx,starty)
end
oldx=event.x
oldy=event.y
if draw==1 then
line[linecur]:lineTo(event.x,event.y)
line[linecur]:endPath()
self:addChild(line[linecur])
end
end
http://giderosmobile.com/forum/discussion/742/problem-with-shape-position#Item_5
Btw, thanks for your shapes snippets. May be i'll use it someday.
Likes: hgvyas123
Try this
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
------------------
0 0
0 0 300 300
0 0
100 100 200 200------------why 100,100
You have a Shape object which has some coordinates, and then you draw relative to these coordinates.
For example if you set shape coordinated to 50, 50, then when you use 0, 0 when drawing shape (local points), they will be 50, 50 in global coordinates, 50, 50, would be 100, 100, etc.
Likes: hgvyas123
x1,y1,width,height = shape:getBounds(stage)
and
x2,y2 = shape:getPosition()
here x1,y1 is supposed to be same as x2,y2 doesn't it?
As I said, getBounds discards all those Gideros wrappers, and just checks raw contents of objects, as the second shape is drawn at 100, 100, thus it returns 100, 100
Likes: hgvyas123
getX() and getBounds() should works same. Probably(ar2sawseen like this word:) ), it's named unification.
Even if it shouldn't - it should be documented.
well on the other hand, if they do the same, why then both of them exist, it would be enough to have only one. So there must be a different purpose between them
Now the discussion is about getbounds. I understand that the bounds should still be the size from 0,0 as the shape has not been moved. However I am not 100% sure but this could also have something to do with texture size whereby the first shape since it intersects at x:0 and y:0 has the bounds starting from 0,0 where as in the second shape, it starts from 100,100. This behaviour can only be explained by @Atilim as it is internal to Gideros and we can only speculate.
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
Likes: ar2rsawseen