c# - Draw travel distance in XNA 4 -


so creating xna game @ college , need cannot seem figure out myself , i'm pretty new this.

basically have spaceship scrolling background of stars. have falling asteroids , point of game travel far possible without being hit said asteroids.

i'm looking guidance how measure theoretical distance travelled ship , draw on screen?

any appreciated.

many thanks.

solution a

somewhere in code defining offset of backdrop each frame. invert* value , add total amount every frame:

totaldistance += -backdropoffset; 

if offset defined in pixels have convert game world unit (kilometers, lightyears, ...) before displaying distance.

* if ship moves forward, backdrop "slides" in other direction.


solution b (more work less headaches)

it not backdrop moving; it's ship. why not move ship , follow camera?

you able kinds of motion. right have invert every movement of ship , apply backdrop. kind of counter-intuitive, don't think? going solution code closer reality => less headaches during debugging, easier maintenance of application , quicker when adding new features.

and of course, getting total distance trivial as

var totaldistance = myship.position.y; 

Comments

Popular posts from this blog

jasper reports - Fixed header in Excel using JasperReports -

media player - Android: mediaplayer went away with unhandled events -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -