ellipticaldoor Posted April 24, 2018 Share Posted April 24, 2018 import { utils, Application, Graphics } from 'pixi.js' import { PixiConfig } from './constants' const kind = utils.isWebGLSupported() ? 'WebGL' : 'canvas' utils.sayHello(kind) const state = { circle: { x: 0, y: 0} } const stage = () => { const graphics = new Graphics() graphics.lineStyle(0) graphics.beginFill(0xFFFF0B, .5) graphics.drawCircle(state.circle.x,90,60) graphics.endFill() return graphics } const gameLoop = delta => { state.circle.x += 1 + delta } const setup = () => { const app = new Application(PixiConfig) document.body.appendChild(app.view) app.stage.addChild(stage()) app.ticker.add(delta => gameLoop(delta)) } setup() Hi, I recently started to learn PIXI and now Im playing with animations using the ticker. This code actually draws a circle and I can se gameLoop() is being called and updating state.circle.x though it looks like it not redrawing the stage. What Im missing? Quote Link to comment Share on other sites More sharing options...
jonforum Posted April 25, 2018 Share Posted April 25, 2018 const myTicker = new PIXI.ticker.Ticker().add((delta) => { gameLoop(delta) }); Quote Link to comment Share on other sites More sharing options...
ellipticaldoor Posted April 25, 2018 Author Share Posted April 25, 2018 Uhm, like this also doesn't work import { utils, Application, Graphics, ticker } from 'pixi.js' import { PixiConfig } from './constants' if (module.hot) { module.hot.accept(() => {}) module.hot.dispose(() => window.location.reload()) } const kind = utils.isWebGLSupported() ? 'WebGL' : 'canvas' utils.sayHello(kind) const app = new Application(PixiConfig) document.body.appendChild(app.view) const state = { circle: { x: 0, y: 0} } const stage = () => { const graphics = new Graphics() graphics.lineStyle(0) graphics.beginFill(0xFFFF0B, .5) graphics.drawCircle(state.circle.x,90,60) graphics.endFill() return graphics } const gameLoop = delta => { state.circle.x += 1 + delta } const gameTicker = new ticker.Ticker().add((delta) => { gameLoop(delta) }) const setup = () => { app.stage.addChild(stage()) gameTicker.stop() gameTicker.add(delta => gameLoop(delta)) gameTicker.start() } setup() Quote Link to comment Share on other sites More sharing options...
ivan.popelyshev Posted April 25, 2018 Share Posted April 25, 2018 Ok, i see many closures, it seems that you know javascript operators. Why do you think pixi should update graphics element when you change "state.circle"? Pixi is not a telepathic reactive framework, its a renderer library. Quote Link to comment Share on other sites More sharing options...
ellipticaldoor Posted April 25, 2018 Author Share Posted April 25, 2018 I pasted all the code just in case. Im starting to learn pixi and Im kind of lost. Which is the recommended project structure? I want to make a tiling based game Quote Link to comment Share on other sites More sharing options...
xerver Posted April 26, 2018 Share Posted April 26, 2018 All the ticker does is run the function you give it on some interval. To render the scene you need to create a renderer and call the render method on it, passing in the scene you wish to render. Application does this for you. I'd expect your OP to render a circle that does not move. Is that what you get? Quote Link to comment Share on other sites More sharing options...
Gerente Posted April 26, 2018 Share Posted April 26, 2018 This might help you to start: https://jsfiddle.net/vwcns1qk/4/ Quote Link to comment Share on other sites More sharing options...
ellipticaldoor Posted April 27, 2018 Author Share Posted April 27, 2018 I just figured out reading the docs, thanks for the help. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.