Canvas Position

14 views
Skip to first unread message

mwebi

unread,
Jan 3, 2011, 3:08:54 PM1/3/11
to The Render Engine
Is there a function with which I can get the current Position of the
Canvas?
I mean the Position in Browsercoordinates. The same coordinates the
cursor has.
I searched for it now for like 1 houre and couldn't find it.

bfat...@gmail.com

unread,
Jan 4, 2011, 9:29:42 AM1/4/11
to The Render Engine
The canvas context has a jQ() method which will return a jQuery object
that represents it. You should be able to get to jQ().position() or
something like that.

- Brett

mwebi

unread,
Jan 4, 2011, 11:24:50 AM1/4/11
to The Render Engine
Hey,

thank you. that set me on the right track.
I got the Position via this.renderContext.jQ().offset()

.offset() retrieves the current position relative to the document

Brett Fattori

unread,
May 3, 2011, 9:23:33 AM5/3/11
to miskovac, the-rend...@googlegroups.com
When the engine starts, it grabs the document and makes it the default context to which you can add any other contexts or objects.  You could use the HTMLElementContext and point it at an existing HTML element in the page like so:

var root = R.rendercontexts.HTMLElementContext.create("root_element", document.getElementById("foo"));

It would find the element with the Id "foo" and make it the element which represents the HTMLElementContext in the DOM.  Then you could add the CanvasContext to the HTMLElementContext and finally, the HTMLElementContext to the default context.  I know it seems like a lot of steps, but the structure of the scenegraph needs to be maintained.  So, if we combined the example above, it might look something like the following:

var root = R.rendercontexts.HTMLElementContext.create("root_element", document.getElementById("foo")),
     playField = R.rendercontexts.CanvasContext.create("playfield", 640, 480);

root.add(playField);
R.Engine.getDefaultContext().add(root);


- Brett



On Tue, May 3, 2011 at 5:53 AM, miskovac <milan...@gmail.com> wrote:
Is there a way to tell to Engine where to nest canvas in DOM tree?

Thanks

miskovac

unread,
May 3, 2011, 2:20:33 PM5/3/11
to The Render Engine
Thanks for your reply.

I don't mind if it take that much lines of code :)

One more thing, I guess R is shortcut for Engine object , am I right?

Brett Fattori

unread,
May 3, 2011, 2:43:05 PM5/3/11
to the-rend...@googlegroups.com
Are you using v2.0 or v1.5.3?

In v2.0, "R" is the "package" root for all the engine.  The engine class is actually located in R.Engine.  The R was a choice I made so I didn't have to type "RenderEngine." everytime.  The engine's classes used to be located on the "window" object, but that could have caused conflicts with the browser or other libraries.

- Brett

--
You received this message because you are subscribed to "The Render Engine" group.
To post to this group, send email to the-rend...@googlegroups.com
To unsubscribe from this group, send email to
the-render-eng...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/the-render-engine?hl=en

Reply all
Reply to author
Forward
0 new messages