randomnovice wrote: ↑Sat Mar 16, 2019 10:29 am
Thank you, you guessed correctly. In my (simple) plan I had 80 cards drawn on the screen at the same time (every frame). I could bring that number down however as many of the cards are on top of one another in the stack.
More importantly, I don't think many cards will change between frames, so why not update the canvases of only those that do?
I may be wrong though, perhaps all cards are animated all the time?
randomnovice wrote: ↑Sat Mar 16, 2019 10:29 am
If I understand correctly I think that when sx, sy, ox and oy are provided in the function love.graphics.draw...
- The x,y coordinates refer now to the centre of the image.
- ox and oy refer to how far from the centre you would like the top left corner of your image, in the unscaled version. (Positive numbers move the image
up and left, negative numbers move the image
down and right.)
Close. First, preferably don't call it centre; that may be the cause of the confusion, because it's just an arbitrary point within the image. The LÖVE docs call it "origin offset". I sometimes call it "hook", like in a picture frame. Now, the x, y coordinates *always* refer to that "hook". Simply the default values for sx and sy are 1, which means no scale change, and the default values for ox and oy are 0, which means the top left. Conceptually, they are always applied; I haven't looked up whether LÖVE optimizes the case where no parameters are given, but the concept doesn't change either way.
Let's see if you understand it better this way. Think of the screen and the image as coordinate systems. Then LÖVE performs a linear transform of coordinates between both. When no transformation is performed, the image's origin and the screen's origin coincide, and is located at the screen's upper left corner. If the screen is say 800x600 and the image is 400x300, the image will occupy the upper left 1/4 of the screen.
Now LÖVE performs a series of transformations to the image: first a displacement by -ox,-oy (which will be in image coordinates because it's the first one), then skew, then scale, then rotation and finally a displacement by x,y (the draw coordinates, which will be in screen coordinates because it's the last one).
You can see these steps in the source, here:
https://bitbucket.org/rude/love/src/412 ... ix.cpp-239 (note that the matrices are left-multiplied, so the order is right-to-left).
The important points to keep in mind are that ox,oy are in image coordinates, and that wherever you place them, that will be the "hook", and the default "hook" (ox=oy=0) is at the top left of the image. Scaling and rotation will be performed around that "hook". Normally you want the hook either at the top left or at the centre, but in some cases, selecting a different hook can be advantageous. For example, in a "pinch to zoom" library I've been working on, the hook is at the midpoint between the two fingers, so that scaling is centred on that point. In a simple platformer, placing the hook at the bottom left of the player may help making physics easier, as that's the vertical coordinate where contact happens, so you don't have to account for the sprite's height in the calculations. And so on.
As a final example, all of these are equivalent:
Code: Select all
-- Draw an undeformed, unrotated image with origin at ox,oy displaced by ox,oy
love.graphics.draw(img, x + ox, y + oy, 0, 1, 1, ox, oy)
-- Draw the image with origin at 0,0 with no displacement
love.graphics.draw(img, x, y, 0, 1, 1, 0, 0)
-- Same as above (just leave the parameters at their defaults: 0 rotation, 1,1 scale, 0,0 origin offset)
love.graphics.draw(img, x, y)