In traditional display lists, ‘Sprite’ has a ‘scrollRect attribute’,
It is possible to achieve a parallax effect similar to camera motion, but I found that ‘starling’ does not have the ‘scrollRect attribute’
How should I achieve this effect in ‘Starling’? Thank you
Traditional Display List:
var view:Rectangle = new Rectangle(0, 0, 800, 600);
map.scrollRect = view;
addEventListener(Event.ENTER_FRAME, onFrame);
function onFrame(e:Event):void {
view.x -= 5;
map.scrollRect = view;
}
Recently, I have been studying 2D physics engines, Box2D, and Nape.
These days, I need to implement camera motion in the game because “openfl starling” does not have a camera like other game engines, so to achieve the effect of camera motion in the game, I can only change the xy of the map container
But the specification of the 2D physics engine is that all display objects xy synchronize the xy of 2D physical world objects, so when my map container moves, obstacles and other display objects on the map, including corresponding physical world objects, also need to follow the map and easily move accordingly
If the map container and obstacles or other character animations move, and the corresponding physical world objects do not move along, collision detection and physical effects cannot be achieved. Therefore, my initial idea was that when the map container moves, the obstacles and other display objects on the map move, and the corresponding physical world objects also move along
I think moving all display objects and all physical world objects consumes a lot of performance,
So I was looking for a way to display objects without moving them all along. I found the “scrollRect” method in traditional display lists, which can make the displayed objects on the screen move, but the actual xy of the displayed objects remains the same as before. However, I used “starling” and found that this method was not available, so I came directly to the community to ask a question
Actually, my direction was wrong from the beginning.
The correct approach is that the physical world and the display list are independent,
So displaying the motion of the object map camera does not require moving objects in the physical world,
Because the object xy in the physical world is calculated in the physical world, the container xy displaying the list is calculated from the corresponding “parent” origin
That is to say, the movement of the display layer lens does not require the movement of objects in the physical world,
Without anyone to communicate with, I can only practice by myself and get some answers
Environmental and gravity effects are not hard to code in manually and to be honest, I find it kind of fun to play around with. I’ve never personally felt the need for a physics engine in my projects where such effects were needed.
I have recently dabbled a bit with particles though ( in @Matse’s Massive-Starling library), which may perhaps be the exception.