It looks like you're new here. If you want to get involved, click one of these buttons!
I am trying to scale a sprite while keeping its original location. However, the sprite moves whenever the image is scaled. How can I scale this and maintain the same original position?
For example, in this program I want the heart to always stay in the center of the rectangles even when scaled:
function setup()
end
function draw()
-- This sets a dark background color
background(40, 40, 50)
-- This sets the line thickness
strokeWidth(5)
-- Do your drawing here
scalefactor=1
scale(scalefactor)
fill(255,255,255,40)
rect(WIDTH/12.4271,HEIGHT/4*1.7,WIDTH/3.072,HEIGHT/13.653333)
fill(255, 255, 255, 255)
sprite("Planet Cute:Heart",WIDTH/4.1513,HEIGHT/2.174)
fill(255,255,255,50)
rect(WIDTH/1.695,HEIGHT/4*1.7,WIDTH/3.072,HEIGHT/13.653333)
fill(255, 255, 255, 255)
sprite("Planet Cute:Heart",WIDTH/1.3241,HEIGHT/2.1694)
end
Comments
I have solved the problem.
Here is the solution:
An alternative is to translate and then scale:
(You might need to experiment with different
spriteMode
s to get the right part of the sprite fixed in place.)