c# - How do I apply multiple matrices in spriteBatch.Draw()? -


i'm making game in c# , xna 4.0. in levels need camera matrix make level appear scroll left/right. additionally, need scaling matrix scale graphics when settings used change window size. both of matrices functional, i'm calling them in draw method this:

if (scrollinglevel) {     //use camera matrix make stage scroll     spritebatch.begin(spritesortmode.deferred, blendstate.alphablend, null, null, null, null, camera.transform); } else {     //use scaling matrix scale graphics     spritebatch.begin(spritesortmode.deferred, null, null, null, null, null, transform); } 

what want apply both matrices @ same time if scrolling level (scale graphics based on window size , use camera matrix make level scroll). however, adding , multiplying matrices not produce accurate result (adding prevents graphics scaling exact amount should , multiplying makes camera scroll inaccurately). how can apply both of matrices @ once?

simply multiply matrices before passing spritebatch.begin.

matrix multiplication allows effects of both matrices appended single matrix. note operation not commutative, meaning a * b != b * a.

in case, should multiply scaling matrix camera matrix.


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -