Jump to content

I can't seem to make the Graphics clear method work


mwatt
 Share

Recommended Posts

So, like the title says.

 

A simplified version of the code I am trying to use looks like this:

 

var graphics = new PIXI.Graphics();

.

.

.

... draw some stuff ...

.

.

.

graphics.clear();

 

In reality, things are a bit more complicated than I show above, so it might be a problem that I am causing.  I don't see how though, so I thought I would post and ask:

1. Am I using it right?

2. Is there a possible bug?

 

I tried to work around by forcing Pixi to use a canvas and getting a context to that canvas and clearing it myself with clearRect but that didn't work either.  I get the feeling I am having some fundamental misunderstanding...

Link to comment
Share on other sites

Perhaps I misunderstood, but it looks like you are clearing after you draw... rather than before you draw.

 

If you clear after, then you are wiping all the drawings before you even render.

 

Suppose you want to draw inside the graphics instance every frame, clearing the previous drawing.

Then you would repeatedly call a function like:

 

function draw(){

// clear all drawing from graphics

graphics.clear();

// draw some stuff

graphics.beginFill(0x000000);

// etc.

}

 

Also, make sure graphics has been added as a child of the stage (or similar).

Link to comment
Share on other sites

Sorry for the confusion rob - yeah I am clearing before I re-draw, or at least, wanting to clear.  Your example code does assure me that I am calling clear correctly... I dunno what's wrong.   Perhaps I am setting up the renderer wrong.  Perhaps I need to refactor my code.  I'll do some experimentation and either figure it out of post a more extensive example of what I am doing and plead for help again.

 

I guess I will ask one more question before I close here.  Is Graphics intended to be a singleton object perhaps?  I am using multiple instances of it (but I am certain I am pairing the clear to the some Graphics instance that does the drawing I wish to erase).

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...