[4.5.9 Metroidvania SOLVED] Switching Player on scrolling screens

9Panzer

Well-known member
Another Scrolling gremlin... I feel like I am close but I'm missing something simple.
So in my game there is an input that will allow the player to switch characters. It uses a variable to determine if the player has "unlocked" the character. For this I just have them all unlocked.
When I use the input on the first screen everything works perfectly. But when the player leaves the first screen the input just destroys the player object and doesn't create the new one.


This is my Uber complicated code. 99% sure its got something to do with the scrolling screen data. Can anyone see what I'm missing?


LDX player1_object
canSwitchPlayer:

INC character
LDA character
CMP #04 ;; one more than the max
BNE +dontNormalizeValue
LDA #00 ;; normalize the value to 7 if it got bigger than 7
STA character
+dontNormalizeValue
STA character

TXA
PHA

;;; Setting up the player position

LDX player1_object
LDA Object_x_hi,x ;; the current horizontal position
STA tempA

LDA Object_screen,x
ADC #$00
STA tempD

LDA Object_y_hi,x ;; the current vertical position
STA tempB

LDA Object_direction,x ;; the current facing and movements
STA tempC


continueChangePlayerInto:

;;; Destroy old Player and create new one
DestroyObject
CreateObject tempA, tempB, character, #$00, tempD

TXA
STA player1_object ;; store that new created object in the Player 1 var
STA camObject
LDA tempC ;; set back the player directions
STA Object_direction,x
PLA
TAX

doneSwitchingPlayer:
RTS
 

9Panzer

Well-known member
... And thanks to @CutterCross and @mouse spirit we managed to figure out what the issue was. The Macro for CreateObject doesn't have a variable for the Object Screen that I was using:

MACRO CreateObject arg0, arg1, arg2, arg3
;; arg0 = x
;; arg1 = y
;; arg2 = object
;; arg3 = beginning state

BUT the CreateObjectOnScreen Does:

MACRO CreateObjectOnScreen arg0, arg1, arg2, arg3, arg4
;; arg0 = x
;; arg1 = y
;; arg2 = object
;; arg3 = beginning state
;; arg4 = what screen do youw ant to create this object on?

So it was an easy fix to change my Macro from one to the other. Works like a charm now!
 

cramske

Member
How would I use this ? I would like to change my character for certain screens or have a different outfit to then be able to access different screens.. would this code be something to do this with ?
and where does it go ?!
 
Top Bottom