Skip to content

Instantly share code, notes, and snippets.

@risingBirdSong
Last active June 28, 2020 21:35
Show Gist options
  • Save risingBirdSong/0c35f0366409ec85e3bc6e2718b5a8b5 to your computer and use it in GitHub Desktop.
Save risingBirdSong/0c35f0366409ec85e3bc6e2718b5a8b5 to your computer and use it in GitHub Desktop.
import * as React from "react";
import Konva from "konva";
import {
Star,
} from "react-konva";
interface PlayState {
x: number;
y: number;
}
class Play extends React.Component<{}, PlayState> {
private star!: typeof Star;
constructor(props: any) {
super(props);
this.state = {
x: 0,
y: 0,
};
}
componentDidMount() {
this.setState({ x: window.innerWidth / 2, y: window.innerHeight / 2 });
this.timing();
}
change = () => {
// Property 'to' does not exist on type 'KonvaNodeComponent<Star, StarConfig>'.
this.star.to({
scaleX: Math.random() + 0.8,
scaleY: Math.random() + 0.8,
duration: 0.2,
});
};
timing = () => {
setInterval(() => {
this.change();
}, 100);
};
render() {
return (
<Star
ref={(node) => {
//@ts-ignore
this.star = node;
}}
onMouseEnter={this.timing}
draggable
innerRadius={20}
outerRadius={40}
x={this.state.x}
y={this.state.y}
numPoints={6}
fill="blue"
/>
);
}
}
export default Play;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment