Ravm Posted May 29, 2013 Share Posted May 29, 2013 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: Thanks. Quote Link to comment Share on other sites More sharing options...
rich Posted May 29, 2013 Share Posted May 29, 2013 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). Quote Link to comment Share on other sites More sharing options...
Ravm Posted May 29, 2013 Author Share Posted May 29, 2013 EDIT Thanks man, i fixed the problem, thanks!i flip the context and use this formule to get the same position of the player:ctx.drawImage(img, canvas.width - (x-5) -Sx,y-5,Sx,Sy); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.