[4.5.6] Quick tutorial: Adding the ability to switch between the Player and another object

woke up at 6:30 am and had the solutuion in my brain, hopped into nesmaker and tested it:

To avoid slowdowns when there are too many objects in your screen, instead of adding inputs for every single object you might control, do this instead:

1: always remember that immediatly after you create the new object you want to control, add "STA player1_object" or "STA player2_object" to the next line (player2 only if you switching to/spawning the player 2 object)

2: add this code to the beginning of all your input scripts

Code:
TXA
LDA controllerNumber_hold
BNE +player2
   LDX player1_object
   JMP +
+player2
   LDX player2_object
+
STA temp

3: in all your input functions, always refer to "temp" instead of "player1_object" or "player2_object"

4: set up both player 1 and player 2 inputs only once each to use the same scripts

now you have a much cleaner input editor screen, no need to have separate scripts for player 2, and your game isnt contantly trying to control 2-4 (or more) non existant character objects all at the same time, causing huge slowdowns
Was casualling looking at NESmaker posts and found this! This is a great way to have P1 & P2 have the same inputs!!! Will work on that tomorrow ASAP
 

NightMusic

Member
...or heres a thought: my graphics are laid out the same for each player, on the same tile sheet. Is there maybe a way to not change the player1_object at all, but instead just swap out the tiles?
Yes. Use object 16 + for it and treat it as a monster. You don't need to assign it to a group or addit to the screen, but you will have to have it on that monster timesheet in that spot on the sheet.. drawback.. if you use this on another screen you need that monster tilesheet and/or to put those tiles in the exact same spot on it. I'll make a special part in my tutorial just for your question. :)
 

NightMusic

Member
Great tutorial How would I go about setting screenflag so when the screen loads it loads object 15 instead of object )) (player object) Asking because I want to warp to an over world super mario 3 style
You could do it in preload or postload I'll include that in my tutorial.
 

NightMusic

Member
Great tutorial How would I go about setting screenflag so when the screen loads it loads object 15 instead of object )) (player object) Asking because I want to warp to an over world super mario 3 style
We can also make it so when you complete maps it adds to a variable or something to check the level complete or not. We can have multiple world maps (world 1 2 etc) and reset the variable on world map warp. ;)
 
Top Bottom