ellipticaldoor

Why the ticker is not redrawing the stage?

Recommended Posts

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?

 

Share this post


Link to post
Share on other sites

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()

 

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.