I’m a more moderen in Cocos2dx JavaScript and I’m gonna make a easy tetris app utilizing React Native + Cocos2dx.
Additionally, I discovered an instance which utilizing ‘npm set up @remobile/react-native-cocos2dx –save’ however it doesn’t work as a result of it couldn’t acknowledge ‘cc.xxx’.
Right here is the pattern code.
'use strict';
var React = require('react');
var ReactNative = require('react-native');
var {
StyleSheet,
View,
} = ReactNative;
var resolveAssetSource = require('resolveAssetSource');
var Cocos2dx = require('@remobile/react-native-cocos2dx');
module.exports = React.createClass({
renderCocos2dx() {
return (res, transProps)=> {
cc.recreation.onStart = operate(){
var MyScene = cc.Scene.lengthen({
alert(transProps.textual content);
onEnter:operate () {
this._super();
var dimension = cc.director.getWinSize();
var sprite = cc.Sprite.create(res.img.qq);
sprite.setPosition(dimension.width / 2, dimension.peak / 2 - 200);
sprite.setScale(0.8);
this.addChild(sprite, 0);
var sprite = cc.Sprite.create(res.img.weixin);
sprite.setPosition(dimension.width / 2, dimension.peak / 2);
sprite.setScale(0.8);
this.addChild(sprite, 0);
var label = cc.LabelTTF.create("Howdy World", "Arial", 40);
label.setPosition(dimension.width / 2, dimension.peak / 2 + 200);
label.setColor(255, 0,255);
this.addChild(label, 1);
}
});
cc.director.runScene(new MyScene());
};
cc.recreation.run();
}
},
render () {
const useful resource = {
img: {
qq: resolveAssetSource(require('./img/qq.img')).uri,
weixin: resolveAssetSource(require('./img/weixin.img')).uri,
}
};
return (
<View fashion={kinds.container}>
<Cocos2dx
render={this.renderCocos2dx()}
useful resource={useful resource}
transProps={{textual content: 'I'm from react-native'}}
width={sr.tw}
peak={sr.tch}
/>
</View>
);
},
});
var kinds = StyleSheet.create({
container: {
flex: 1
},
});
Wanting ahead to get a solution asap.
Thanks.
You need to use net view to load native html, it wil be simpler. With this technique, you should use cocos creator, it’s new, nice editor and often maintained. After construct recreation, will probably be export information embody html for you
Instance:
const recreation = require('./recreation.html');
<WebView
supply={recreation}
fashion={{flex: 1}}
/>