Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Thoughts on binding body velocity? #5

Open
pradeeproark opened this issue Sep 11, 2016 · 3 comments
Open

Thoughts on binding body velocity? #5

pradeeproark opened this issue Sep 11, 2016 · 3 comments

Comments

@pradeeproark
Copy link

pradeeproark commented Sep 11, 2016

@evilfer
I was wondering whether it was possible to expose velocity property in sprite body for binding. So you can bind it to state values instead of directly setting it on context nodes.

I noticed that you have exposed body properties as prefixed properties https://github.com/evilfer/react-phaser/blob/master/src/impl/properties/custom/body.js#L9-L10

How do you extend this to support velocity which it itself a object with x/y properties.?

Also is it possible to have body as a nested property of sprite with all attributes of physics body exposed on it instead of using prefixed approach.

<sprite>
<body>
   <velocity x={this.state.playerXVelocity}/>
</body>
</sprite>
@evilfer
Copy link
Owner

evilfer commented Sep 13, 2016

I think "prefixed properties" do exactly the opposite to what you want: they are props of a node that affect Phaser attributes of children objects.

You can create a new "velocity" tag, which wouldn't really have any own Phaser object (in contrast with the "body" tag). Your velocity tag can do whatever it wants with its properties, including getting the parent node, and making changes to it.

None of the helpers in https://github.com/evilfer/react-phaser/blob/master/src/impl/properties/utils.js does this currently automatically, but you can use "generateCustomPropMap", and create functions that modify the parent body velocity.

@evilfer
Copy link
Owner

evilfer commented Sep 13, 2016

Here's one (slightly convoluted) example:

https://github.com/evilfer/react-phaser/blob/master/src/impl/types/graphics/create-graphics-item.js#L7

create-graphics-item.js implements a tag generator. It's used to create all the children tags that can be added to a <graphics>, e.g. <rect>. These children tags, like your <velocity>, do not have their own Phaser object. Instead, they grab their (<graphics>) parent's Phaser object and make changes on it.

@pradeeproark
Copy link
Author

Understood, Velocity as a tag appears to be excessive. However having a body as a nested component might be syntactically better as they body properties would live on it, instead of prefixed properties on sprite.

For now I added velocity to the list at https://github.com/evilfer/react-phaser/blob/master/src/impl/properties/custom/body.js#L10 and able to bind velocity as a point object from state values which solves my original goal.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants