Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Renderer rotation issue聽#56

Copy link
Copy link
@lexengineer

Description

@lexengineer
Issue body actions

Hello everyone 馃憢

I am trying to rotate one of my elements on the screen and I do this with Matter.js and react-native-game-engine all together.

I have the following logic:

Count angle for rotation manually => set this angle to the Matter.js body => achieve this newly set angle inside my render via props => trying to rotate my View with transform.

So everything works well until the last step when I am trying to rotate my View. It is not rotating at all, but Matter.js body has newly set angle. I think the issue can be inside rendering logic, but still not sure. Tried a lot of solutions already. Any help is appreciated.

This is my code:

This is my renderer component

const Dolphin = props => {
  const width = props.size[0];
  const height = props.size[1];
  const x = props.body.position.x - width / 2;
  const y = props.body.position.y - height / 2;
  
  return (
    <View
      style={[
        {
          position: 'absolute',
          width,
          height,
          backgroundColor: props.color,
          transform: [{ rotate: `${parseInt(props.body.angle)}deg` }],
        },
        { left: x, top: y },
      ]}
    >
      <Text color="white">{props.title}</Text>
    </View>
  );
};

This is how I set angle with Matter.js:

onPress={event => {
        event.persist();
        const dolphin = gameEngineRef.current.state.entities.dolphin;
        const pressEventX = event.nativeEvent.locationX;
        const pressEventY = event.nativeEvent.locationY;

        const angle = countAngle(40, 40, pressEventX, pressEventY);

        Matter.Body.setAngle(dolphin.body, angle);
      }}
Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.