Jump to content

Sprite sticking to object wall


megmut
 Share

Recommended Posts

Not sure what to call the title.. sorry if it's misleading! I was helping someone in the chatroom and came up with this example to show them:

 

http://phaser.io/sandbox/DqUvNpYR/play

 

http://phaser.io/sandbox/DqUvNpYR

 

Just out of curiosity, is there a better way of doing this? I'm sure there's a way it could check the 'platforms' x and y instead of using world x and y, but that still feels hacky. 

 

Thanks in advance :)

 

Megmut

Link to comment
Share on other sites

Just out of curiosity, is there a better way of doing this? I'm sure there's a way it could check the 'platforms' x and y instead of using world x and y, but that still feels hacky. 

Hmm, why would this feel hacky? I would think it would be better because it would then allow you to change, remove, or add platforms without having to change the code. Right now, if you delete a platform, you will need to update the magic values in the code that are based on the world position in order to make the wall sticking to look right.

Link to comment
Share on other sites

 

 

but would it not be better to have the platfrom as an object.. a sprite, or a group of sprites.. and just call a stickTo method.. where by you stick to that object?

 

Yup! :) I would assume that the  stickTo method end up checking the platform's x/y values, as opposed to the world x/y values, which would be considered a less hacky approach. 

 

Maybe I'm misunderstanding your question -- I thought it was just a comparison between (i) using the world x/y positions versus (ii) using the platform's x/y positions.

 

From your latest post, I believe  you're talking about a design pattern as opposed something implementation-specific?  :)

Link to comment
Share on other sites

I think if it works then you're more than halfway there. ( =

 

You should probably use velocity instead of modifying the position directly; that way the sprite will participate in physics collisions. You should also not use +1; try +1*this.game.time.physicsElapsedMS. That will make the speed invariant under frame skips.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...