Jump to content

Why the ticker is not redrawing the stage?


ellipticaldoor
 Share

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?

 

Link to comment
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()

 

Link to comment
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?

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...