Uncaught TypeError: Cannot read property 'offset' of undefined

1,047 views
Skip to first unread message

Alexandre Ferreira

unread,
May 7, 2013, 12:51:24 AM5/7/13
to mel...@googlegroups.com
During the process of migration of my wip game write using melonJS 0.9.6 to 0.9.7, I encountered some difficulties about the using of "renderable". I'm trying to index in the character object, his sprite, so is that what I've did:

this.renderable = new me.AnimationSheet(x, y, settings.image, settings.spritewidth, settings.spriteheight);

What I did wrong?


Thanks!

Alexandre Ferreira

unread,
May 7, 2013, 4:40:57 PM5/7/13
to mel...@googlegroups.com
Ok, it's confuse! I managed to make the sprites work properly with my entities! But, I'm sure that I don't know how I did this... the me.ObjectEntity is completely separated of me.Renderable, right? So, if I'm right, how am I did it work without initiate the renderable? Or in the moment I passed the settings parameters to me.ObjectEntity the content with the image name, loaded previously, the system recognized this and set my object renderable? Because, after this I just could set the parameter alwaysUpdate to true and everything works fine!

Please, creators, explain this!

I did not uploaded my last code to my server yet, but, I'm testing it in localhost.

I hope you guys understand what I wrote before... because my english is bad, and I don't use translators! :P

Aaron McLeod

unread,
May 7, 2013, 4:53:41 PM5/7/13
to mel...@googlegroups.com
I haven't gone over your code extensively, but I feel like you're using renderable wrong. Renderable is a whole other class, and not an animation sheet: http://melonjs.github.io/docs/me.Renderable.html


When you create an object entity, the image and so forth is passed so the renderable object part of the entity know what's what. You then add animations on the renderable, instead of the objectEntity instead. Personally, i would kind of like accessor methods for doing it to reduce breaking the law of demeter and such, but that also adds framework bloat. 


--
You received this message because you are subscribed to the Google Groups "melonJS - A lightweight HTML5 game engine" group.
To unsubscribe from this group and stop receiving emails from it, send an email to melonjs+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
Aaron McLeod
http://agmprojects.com

Jay Oster

unread,
May 7, 2013, 9:14:24 PM5/7/13
to mel...@googlegroups.com
`me.ObjectEntity` constructor will automatically create a renderable if it is given an `image` property in the settings argument.

To change the offset on the renderable, just change `this.offset.set()` to `this.renderable.offset.set()` ...

Jay Oster

unread,
May 7, 2013, 9:29:51 PM5/7/13
to mel...@googlegroups.com
FWIW, `me.AnimationSheet` constructor expects a real image object, and you're passing a string. It should be:

new me.AnimationSheet(x, y, me.loader.getImage(settings.image), settings.spritewidth, settings.spriteheight);

Alexandre Ferreira

unread,
May 7, 2013, 10:03:18 PM5/7/13
to mel...@googlegroups.com
@Aaron, what you have looked was the old code, I have been developing locally and when I arrive home at night I upload my work to the server, like I did a minute ago! Take a look again, if you could.

@Jason, the respawn object haven't an image associated, so what I'm doing is set the x and y positions with the anchor point positioned in left up corner of my square area, then I change the offset as you can see in my code. The offset will gonna work, even if no image are seted?

Thanks!

Em terça-feira, 7 de maio de 2013 01h51min24s UTC-3, Alexandre Ferreira escreveu:

Jay Oster

unread,
May 7, 2013, 11:50:23 PM5/7/13
to mel...@googlegroups.com
Oh, yes. The respawn object does not need an image because it doesn't have a renderable associated with it. In fact, it doesn't even need to extend ObjectEntity! :)

It's creating Enemy entities, which reference their own image, and have their own renderable objects to display the animations.

Alexandre Ferreira

unread,
May 7, 2013, 11:56:04 PM5/7/13
to mel...@googlegroups.com
Yes! But, I need to set the position and size of the RespawnManager, what class you sugest to extend? me.Rect?

Jay Oster

unread,
May 8, 2013, 2:56:39 AM5/8/13
to mel...@googlegroups.com
me.Rect does have size and position, so it's probably a good one to use as a base class. :) 

Alexandre Ferreira

unread,
May 8, 2013, 3:21:05 PM5/8/13
to mel...@googlegroups.com
Thanks! :)
Reply all
Reply to author
Forward
0 new messages