Reputation: 6394
I'm developing a simple game using EaselJS/CreateJS, part of which needs to animate a sprite across the screen in a marquee fashion.
http://jsfiddle.net/gRoberts/af6xr8u4/
As you can see from the above, the code below calculates the x position from 0 to the stage width + icon width.
icon.x = ((icon.x + w)-deltaS*50) % w;
This makes it start off screen, appear and then once it reaches 0, starts again.
Is there a way to adjust this calculation to go beyond 0, to the width of the icon, so it would be -128 (icon width) to 448 (stage + icon width)?
Thanks :)
Upvotes: 2
Views: 107
Reputation: 386786
I have tried with this values,
icon.x = -icon.tileW + ((icon.x + w + 2 * icon.tileW) - deltaS * 50) % (w + icon.tileW);
because the negative offset moves it to the right position and the added value as modulus give the space to move. Additionally you need the double of the width, because the values are required at the start and at the end.
Upvotes: 1
Reputation: 5352
icon.x = -icon.width + (((icon.x + icon.width + w) - deltaS * 50) % w)
Upvotes: 1