Jump to content

Canvas.scale error


Ravm
 Share

Recommended Posts

Hi everyone, i'm here because i have a little problem with the canvas.

i'm doing a multiplayer game, MMORPG or what ever, i need your help because i have this lines:
 

 

ctx.save();ctx.scale(-1,1);ctx.drawImage(img,x - 5 ,y - 5,Sx,Sy);ctx.restore(); 

 


That lines are used to get an horizontal flip in the context, and draw de sprite, but my problem is that isn't working and i don't know why.

I test with ctx.scale(2,2); and it's works but when i want to flip horizontal isn't works(when i put scale(-1,X)).

So if someone knows about this, please answer me.
 
EDIT:
My problem is the sprite, when i scale the context, the sprite or the image, disappears.
 
PIC:
2903361251a55b8c1e43a.png
 

Thanks.
Link to comment
Share on other sites

When you scale the context like that you're basically inverting the coordinate system as well. You need to translate first, then scale, then drawImage with probably a 0,0 or negative half-width/height origin (depending on desired outcome).

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...