Re: does this.body.pos.y (or similar) exist?

12 views
Skip to first unread message
Message has been deleted

aaron.g...@gmail.com

unread,
Nov 22, 2016, 2:36:13 PM11/22/16
to melonJS - A lightweight HTML5 game engine
We you able to bring the player back or something? curious how you know it didn't disappear :)

One thing you can do to restart is simply call: me.state.restart(). That will remove everything from me.game.world, and restart the current screen. It's a good place to start on doing game restarts. I use it in a couple instances myself.

On Tuesday, November 22, 2016 at 2:24:36 PM UTC-5, Noah Swainland wrote:
> Hi,
>     I was working on an experimental game, and I want to make it so that if you go too high or too low on the map, the game restarts. What's the best way to go about this. I looked in the docs, but couldn't see a mention of something like me.body.pos.y. I'm assuming the code would be kinda thus:
>
>
>
> if(this.body.pos.y < 0 || this.body.pos.y > 480) { //480 is my viewport height
>     //delete the player
>     me.game.world.removeChild(this);
> }
>
>
> I used this code and nothing happened, the player didn't disappear when I went off the screen, but similarly I got no errors and it ran fine.
> Any help is greatly appreciated. Thanks,
> Noah

Message has been deleted

aaron.g...@gmail.com

unread,
Nov 22, 2016, 2:51:36 PM11/22/16
to melonJS - A lightweight HTML5 game engine, aaron.g...@gmail.com
Oh, try using this.pos.y instead. I believe the body position is one that's relative to the entity. So the entity has its own "world" or "relative to parent" position. The body is the physics body relevant to the entity. Which maintains velocity and movement so you can update the position of the entity.

On Tuesday, November 22, 2016 at 2:44:59 PM UTC-5, Noah Swainland wrote:
> Yeah, basically I'm working on an improved version of an experimental javascript game I made, i Am a Cow. You can fly around and stuff. On my new version, I flew up so that the cow went off the screen, but they always came back on again.
>
>
> So are you saying that I can use this.body.pos.y? Or is that why it doesn't work?
>
>
> Thanks, Noah
>
> On Tuesday, November 22, 2016 at 7:36:13 PM UTC, aaron.g...@gmail.com wrote:We you able to bring the player back or something? curious how you know it didn't disappear :)

Jay Oster

unread,
Nov 22, 2016, 5:56:29 PM11/22/16
to mel...@googlegroups.com, Aaron McLeod

--
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+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages