- 23
- Posts
- 9
- Years
- United Kingdom
- Seen Dec 4, 2019
Hi there. I've been trying to solve this problem for the last few days now but I just can't seem to figure it out, so any help would be greatly appreciated.
I've created an extra scene in the Trainer Card script which contains the badges for the current region. What I want to do is to let the player be able to select each of the smaller badge sprites, so that it displays a larger version along with the trainer sprite of the gym leader who gives the badge.
So far I've gotten the gym leader and the large badge sprite to appear, but this is where my issue comes in. When switching between the badges, the sprites don't change like they're supposed to, and they always stay the same. Here are the relevant bits of code which try to do this:
This is where everything is initialized. "@leadernumber" is used to store the integer that corresponds with the gyms (e.g. 0 = 1st gym, 7 = 8th gym). This is used by the methods in the code sections below.
This is the method which tries to display the gym leader and large badge sprites. It uses an array to get each trainer sprite, and uses the values of "leaders" and "leader", which stem from "@leadernumber", to determine which one to use.
This code was added in the Settings script section. This is where pbShowLeaderInfo gets the trainer sprite information.
And this contains all the input methods. Every time either Left or Right is pressed on the keyboard, the value of "@leadernumber" is changed by 1 unless specified otherwise. Then pbShowLeaderInfo is run each time to check for any changes.
This method is based off of the one used in the BW Essentials Kit in the same script sections. Obviously it works there, so you could read through the same scripts to get an understanding there.
A snapshot of what it should look like visually is attached.
I've created an extra scene in the Trainer Card script which contains the badges for the current region. What I want to do is to let the player be able to select each of the smaller badge sprites, so that it displays a larger version along with the trainer sprite of the gym leader who gives the badge.
So far I've gotten the gym leader and the large badge sprite to appear, but this is where my issue comes in. When switching between the badges, the sprites don't change like they're supposed to, and they always stay the same. Here are the relevant bits of code which try to do this:
This is where everything is initialized. "@leadernumber" is used to store the integer that corresponds with the gyms (e.g. 0 = 1st gym, 7 = 8th gym). This is used by the methods in the code sections below.
Code:
def pbStartScene
# initialises all the sprites used in the scene
@sprites={}
@viewport=Viewport.new(0,0,Graphics.width,Graphics.height)
@viewport.z=99999
@scene=0
@leadernumber=0
@sprites["bg"]=AnimatedPlane.new(@viewport)
@sprites["bg"].bitmap=pbBitmap("Graphics/Pictures/TrainerCard/trainercardbgg")
@sprites["card"]=IconSprite.new(0,0,@viewport)
@sprites["card"].setBitmap("Graphics/Pictures/TrainerCard/trainercardbg")
@sprites["bg2"]=IconSprite.new(0,0,@viewport)
@sprites["bg2"].setBitmap("Graphics/Pictures/TrainerCard/trainercardbg2")
@sprites["trainer"]=IconSprite.new(290,61,@viewport)
@sprites["trainer"].setBitmap(pbPlayerSpriteFile($Trainer.trainertype))
@sprites["trainer"].zoom_x=4.0; @sprites["trainer"].zoom_y=4.0
@totalframe=@sprites["trainer"].bitmap.width/@sprites["trainer"].bitmap.height
realwidth=@sprites["trainer"].bitmap.width/@totalframe
@sprites["trainer"].src_rect.set((@totalframe-1)*realwidth, 0,
realwidth,@sprites["trainer"].bitmap.height)
@sprites["trainer"].z=2
@sprites["leadersprite"]=DynamicTrainerSprite.new(false,-1,@viewport)
trainerfile=sprintf("Graphics/Characters/%s",LEADERINFO[0][0])
@sprites["leadersprite"].setBitmap(trainerfile)
@sprites["leadersprite"].visible=true
@sprites["leadersprite"].zoom_x=2.0; @sprites["leadersprite"].zoom_y=2.0
@sprites["leadersprite"].z=5
@sprites["leadersprite"].toLastFrame
@sprites["leadersprite"].lock
pbPositionPokemonSprite(@sprites["leadersprite"],276,96)
@sprites["badgeinfo"] = Sprite.new(@viewport)
@sprites["badgeinfo"].bitmap = Cache.picture("TrainerCard/badgeslarge")
@sprites["badgeinfo"].x=20; @sprites["badgeinfo"].y=60
@sprites["badgeinfo"].src_rect.set(0,0,192,192)
@sprites["badgeinfo"].visible=false
@sprites["badgeinfo"].z=4
This is the method which tries to display the gym leader and large badge sprites. It uses an array to get each trainer sprite, and uses the values of "leaders" and "leader", which stem from "@leadernumber", to determine which one to use.
Code:
def pbShowLeaderInfo(leaders)
leader=leaders.to_i
@sprites["badgeinfo"].tone=Tone.new(-255,-255,-255,-255)
@sprites["badgeinfo"].visible=true
@sprites["leadersprite"].visible=true
if $Trainer.badges[leaders]
trainerfile=sprintf("Graphics/Characters/%s",LEADERINFO[leader][0])
@sprites["leadersprite"].setBitmap(trainerfile)
@sprites["leadersprite"].toLastFrame
@sprites["leadersprite"].lock
@sprites["leadersprite"].visible=true
@sprites["badgeinfo"].tone=Tone.new(0,0,0,0)
@sprites["badgeinfo"].src_rect.set(leader*192,0,192,192)
@sprites["badgeinfo"].visible=true
end
end
This code was added in the Settings script section. This is where pbShowLeaderInfo gets the trainer sprite information.
Code:
LEADERINFO = [
["trainer059", "Boulder Badge","Leader: Brock"],
["trainer060", "Cascade Badge","Leader: Misty"],
["trainer061", "Thunder Badge","Leader: Lt. Surge"],
["trainer062", "Rainbow Badge","Leader: Erika"],
["trainer063", "Soul Badge","Leader: Koga"],
["trainer064", "Marsh Badge","Leader: Sabrina"],
["trainer065", "Volcano Badge","Leader: Blaine"],
["trainer066", "Earth Badge","Leader: Giovanni"],
]
And this contains all the input methods. Every time either Left or Right is pressed on the keyboard, the value of "@leadernumber" is changed by 1 unless specified otherwise. Then pbShowLeaderInfo is run each time to check for any changes.
Code:
def pbTrainerCard
loop do
Graphics.update
Input.update
self.update
if @scene==1 && @leadernumber>=0
pbShowLeaderInfo(@leadernumber)
elsif @scene==1 && @leadernumber<=7
pbShowLeaderInfo(@leadernumber)
end
if @scene==1 && Input.trigger?(Input::RIGHT)
@leadernumber+=1
if @sprites["badgebutton"].x==267 && Input.trigger?(Input::RIGHT)
@sprites["badgebutton"].x+=0
pbShowLeaderInfo(@leadernumber)
else
pbPlayDecisionSE()
@sprites["badgebutton"].x+=36
pbShowLeaderInfo(@leadernumber)
end
end
if @scene==1 && Input.trigger?(Input::LEFT)
@leadernumber-=1
if @sprites["badgebutton"].x==15 && Input.trigger?(Input::LEFT)
@sprites["badgebutton"].x-=0
pbShowLeaderInfo(@leadernumber)
else
pbPlayDecisionSE()
@sprites["badgebutton"].x-=36
pbShowLeaderInfo(@leadernumber)
end
end
This method is based off of the one used in the BW Essentials Kit in the same script sections. Obviously it works there, so you could read through the same scripts to get an understanding there.
A snapshot of what it should look like visually is attached.