hexi icon indicating copy to clipboard operation
hexi copied to clipboard

Canvas not rendering makeTiledWorld /worldCamera result

Open jbrod22 opened this issue 8 years ago • 2 comments

I'm following the scrollingWorldExample as best I can.

The imported json and png are actually the url locations of each file. In the image attached the white screen is the renderer. The message is rendered properly but nothing else is.

Sorry about the code formatting. Nothing is working right for me.

'import React, {Component} from 'react'; import {connect} from 'react-redux'; import CanvasStyle from './canvas.scss'; import NewWorld from './assets/newworld.json'; import Tileset from './assets/tileset.png';

class Canvas extends Component {

constructor(props) {
    super(props);
    this.state = {}
}

componentWillReceiveProps() {}

componentDidMount() {
    let camera = {}
    let world = {}
    let g = {}
    let objectsLayer = {}


    let filesToLoad = [NewWorld, Tileset]
    g = hexi(512, 512, setup, filesToLoad, load);
    g.start() 


    function setup() {
        document
            .getElementById('HexiCanvas')
            .appendChild(document.getElementsByTagName('canvas')[0])
        g.fps = 1;
        console.log(PIXI.loader.resources)
        world = g
            .tileUtilities
            .makeTiledWorld(NewWorld, Tileset);
        console.log(g)
        camera = g.worldCamera(world, world.worldWidth, world.worldHeight, g.canvas)
        objectsLayer = world.getObject("Elf");
        let message = g.text("No items found", "12px puzzler", "black");
        message.setPosition(10, 10);
        g.state = play;

    }

    function load() {}

    function play() {
        console.log('Tick Tock!')
        camera.follow(objectsLayer)
    }

    

}

render() {

    return <div
        className={this.props.show
        ? "canvas"
        : "hidden"}
        id="HexiCanvas"></div>
}

}

const mapStateToProps = (state, ownProps) => { return {}; };

const mapDispatchToProps = (dispatch) => { return {} }

export default connect(mapStateToProps, mapDispatchToProps)(Canvas);'

screen shot 2017-10-14 at 13 48 37

jbrod22 avatar Oct 14 '17 17:10 jbrod22

@jbrod22 If you can get it working by slightly modifying the original example code and then making incremental customizations from there, you might be able to track down what's going wrong. One thing I can tell for sure is that filesToLoad needs to be an array of strings.

kittykatattack avatar Oct 15 '17 13:10 kittykatattack

One thing I can tell for sure is that filesToLoad needs to be an array of strings.

The import NewWorld from './assets/newworld.json'; import Tileset from './assets/tileset.png'; are actually url strings

jbrod22 avatar Oct 15 '17 13:10 jbrod22