Skip to content
This repository was archived by the owner on Feb 7, 2024. It is now read-only.
This repository was archived by the owner on Feb 7, 2024. It is now read-only.

changing steps or repeat on a sprite doesn't work #18

Description

@joe-lloyd

Hey Im changing the steps and repeat with key presses on a Sprite. I see the state change in the react dev tools but it does not change the way the sprite behaves.

<Sprite repeat={this.state.repeat}
         scale={0.1}
         offset={[0, 10]}
         state={this.state.facing}
         steps={this.state.steps}
         tileHeight={2400/4}
         tileWidth={1841/4}
         src="./sprites/test2.png" />

Like this, handing state to the sprite.
It works when i make my first key press but not on release

checkKeys = () => {
	const { keys } = this.props;
	let { facing, repeat, steps } = this.state;

	if (keys.isDown(keys.DOWN)) {
		facing = 0;
		repeat = true;
		steps = [3, 3, 3, 3];
	}

	if (keys.isDown(keys.LEFT)) {
		facing = 2;
		steps = [3, 3, 3, 3];
		repeat = true;
	}

	if (keys.isDown(keys.RIGHT)) {
		facing = 1;
		steps = [3, 3, 3, 3];
		repeat = true;
	}

	if (keys.isDown(keys.UP)) {
		facing = 3;
		steps = [3, 3, 3, 3];
		repeat = true;
	}

	if (!keys.isDown(keys.UP) && !keys.isDown(keys.RIGHT) && !keys.isDown(keys.LEFT) && !keys.isDown(keys.DOWN)) {
		steps = [0, 0, 0, 0];
		repeat = false
	}

	this.setState({facing: facing, repeat: repeat, steps: steps});
}

This is my check keys function

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions