Jump to content

Problem creating/removing sprites on button click


Recommended Posts

I am trying to create a click through image gallery for a project in pixi. You can see in my fiddle when you click on the right side of the screen it adds the next image. The problem is when you click on the left to delete the image it will only delete one and not the rest. 

Can someone please help me with this issue.  If you have any more questions, please feel free to ask. If there is a better solution please let me know. 


const createSprite = function() {
      imageCreated = true
      image = new Sprite(resources[images[step]].texture)
      image.width = 400;
      image.height = 300;
      image.x = left
      step += 1
      left += 40

    const removeSprite = function() {
      step -= 1

    loader.load((loader, resources) => {

    nextTag.addEventListener("click", function() {

    backTag.addEventListener("click", function() {


Link to comment
Share on other sites

I can tell you why it happens: "image" is a global variable , it holds only last image that was added. There's no way for your function to get images that were added before it.

Its a javascript problem, so Im really cant help you because I think that people should deal with that on their own.

You'll have 1000 problems like that in the future.

Just take a cup of tea, a list of paper, a pen, read what Array and Stack is, look at PIXI.Container documentation and think about it. Stop tormenting the keyboard.

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.

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.


  • Recently Browsing   0 members

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