🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

How to update scene to keep in sync with data

Started by
0 comments, last by gsoutz 4 years, 2 months ago

I have a list where I add remove elements:

   let l = [1, 2, 3, 4, 5];
   l.push(10);
   l.pop();
   l.splice(2, 1);

I want to render this list where each item has a sprite laid out horizontally:

   function renderList() {
     l.forEach((_, i) => {

       // create a sprite
       let s = new Sprite(textures[_]);

       // set the position
       s.position.set(i * 10, 0);

       // add to the stage
       stage.addChild(s);
     });
   }

On each game update this list changes, so I need to update the scene graph somehow to reflect this, possible add new items to the stage, remove deleted items from the stage, and update existing items position. What would be a generic simple way to code this?

I think I need something like an ArrayAdapter as described here https://guides.codepath.com/android/Using-an-ArrayAdapter-with-ListView

This topic is closed to new replies.

Advertisement