O'Reilly logo

Game Programming using Qt 5 Beginner's Guide - Second Edition by Lorenz Haas, Witold Wysota, Pavel Strakhov

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

What just happened?

First, we ask the JS engine to create a new JavaScript array object. Then, we iterate over all entities and skip entities that were already killed. We use QJSValue::setProperty to add the proxy object of each entity to the array. We need to specify the index of the new array item, so we create the arrayIndex counter and increment it after each insertion. Finally, we return the array.

This function completes the SceneProxy class implementation. We just need to create a proxy object and add it to the JS engine in the constructor of the Scene class:

SceneProxy *sceneProxy = new SceneProxy(this);
m_sceneProxyValue = m_jsEngine.newQObject(sceneProxy);

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required