Skip to content

Instantly share code, notes, and snippets.

@markbiek
Created February 3, 2017 19:25
Show Gist options
  • Save markbiek/4c203d9e8956f05e536a226b2671eccb to your computer and use it in GitHub Desktop.
Save markbiek/4c203d9e8956f05e536a226b2671eccb to your computer and use it in GitHub Desktop.
import React, { Component } from 'react';
import {
AppRegistry,
StyleSheet,
Text,
Button,
Navigator,
View,
TouchableHighlight
} from 'react-native';
import {
Loop,
Stage,
Sprite
} from 'react-game-kit/native';
export default class App extends Component {
constructor(props) {
super(props);
this.state = {
steps: [0]
};
this.stepRocket = this.stepRocket.bind(this);
}
stepRocket() {
let { steps } = this.state;
this.setState({
steps: [steps[0] == 0 ? 20 : 0]
});
}
render() {
const { steps } = this.state;
if (!steps) {
console.log('Not ready yet');
return null;
}
console.log(steps);
return (
<Loop>
<Stage>
<TouchableHighlight onPress={this.stepRocket}>
<View style={styles.container}>
<Sprite
repeat={false}
src={require('../../img/sprite-rocket.png')}
tileWidth={128}
tileHeight={128}
ticksPerFrame={1}
scale={2}
state={0}
steps={steps}
/>
</View>
</TouchableHighlight>
</Stage>
</Loop>
);
}
}
const styles = StyleSheet.create({
container: {
width: 1000,
height: 2000,
borderColor: 'red',
borderWidth: 1
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment