Author Topic: Sprite Definition Creation  (Read 4374 times)

eric22222

  • Fanatic
  • ***
  • Posts: 177
    • View Profile
    • Eric Online
    • Email
Sprite Definition Creation
« on: 2006-12-27, 11:38:57 AM »
Okay, I've gotten the art of creating sprites in script under my belt. Now it's high time I learned how to create sprite definitions in script. I'm starting out by just trying to create one sprite definition. Once I get that figured out, I'll rewrite this loop to include all the sprites I want to copy. Here's my plan: I'll go ahead and create all the player and weapon sprites that will be need for each map. I'll trigger this sub to copy all the sprite definitions:

Code: [Select]
Sub CopySprites
   With ProjectObj.Maps("Home_Mesa_Interior")
      dim I
      I = 0
      Do While I < .SpriteDefCount
         If .SpriteDefs(I).Name = "Player_jumping_right_1" Then Set NewJumpLeftSpr = .SpriteDefs(I).Clone
         I = I + 1
      Loop
   End With
End Sub

Then, whenever the player gets to a new map, I'll trigger this sub to put all those sprite definitions into the map:

Code: [Select]
Sub LoadSprites
   With ProjectObj.Maps("Home_Desert")
      Set NewJumpLeftSpr.rPath = .Paths(1)
      NewJumpLeftSpr.Name = "Player_jumping_right_6"
      Set NewJumpLeftSpr.Template = .SpriteTemplates("Player_jumping_right")
      .AddSpriteDef HostObj.AsObject(NewJumpLeftSpr)
   End With
End Sub

Problem is, once the player is supposed to change over to the jumping sprite, he just kinda disappears... That's telling me I have created a definition (since I would otherwise get an error), but sort of an empty shell of a definition. The map where I'm loading the sprite definition has a template named Player_jumping_right already. It usually changes to a sprite named Player_jumping_right_2, but I'm manually making it try to change to _6 to test if the definition is being made.

The scripts I'm looking at for this are GoldYoink and Wudd, both of which do way more object creation than I plan on, so maybe that's where I missed something. Any help will, as always, be greatly appreciated.

bluemonkmn

  • SGDK Author
  • Administrator
  • Fanatic
  • *****
  • Posts: 2761
    • ICQ Messenger - 2678251
    • MSN Messenger - BlueMonkMN@gmail.com
    • View Profile
    • http://sgdk2.sf.net/
    • Email
Re: Sprite Definition Creation
« Reply #1 on: 2006-12-28, 06:43:08 AM »
Comparing the GoldYoink script to yours I see one thing that it is doing that you are not.  Try setting the rLayer property of the SpriteDef object to the appropriate layer.  The documentation says that rLayer comes from rPath (the path that the layer is on), but that's not entirely accurate.  The path determines the layer when the sprite is created in the IDE, but internally it appears to actually be stored and managed independently, so when creating a SpriteDef via script, you have to set the rLayer property independently of rPath.

eric22222

  • Fanatic
  • ***
  • Posts: 177
    • View Profile
    • Eric Online
    • Email
Re: Sprite Definition Creation
« Reply #2 on: 2006-12-28, 11:08:01 AM »
Haha! Yes! That's got it!  ;D

Now to add a bunch of loops and such to get all the sprites in. Thanks again! I know I've been asking for a lot of help with scripting... Thanks for being patient with me. But hey, it'll be worth it in the end when you guys are playing this game!  ;)

eric22222

  • Fanatic
  • ***
  • Posts: 177
    • View Profile
    • Eric Online
    • Email
Re: Sprite Definition Creation
« Reply #3 on: 2006-12-28, 12:34:59 PM »
Bah! Foiled again!

I'm getting an "Invalid Tileset Object" error. Now, the map where the sprite definitions are loaded is using a different tileset, but the sprite is still using the same tileset so that shouldn't be a problem...

Here's my new script, which copies all 12 of the sprites I need for each map, along with their templates:

Code: [Select]
Sub CopySprites
   dim I
   I = 0
   Do While I < ProjectObj.Maps("Home_Mesa_Interior").SpriteDefCount
      With ProjectObj.Maps("Home_Mesa_Interior").SpriteDefs(I)
         If left(.Name, 6) = "Player" Or left(.Name, 5) = "Spear" Or left(.Name, 4) = "Hurt" Then
            If .Name = "Player_spear_1" Then Set NewPlayerSpear = .Clone
            If .Name = "Player_jumping_left_1" Then Set NewJumpLeftSpr = .Clone
            If .Name = "Player_jumping_right_1" Then Set NewJumpRightSpr = .Clone
            If .Name = "Player_swimming_1" Then Set NewSwimming = .Clone
            If .Name = "Hurt_animation_1" Then Set NewHurtAnimation = .Clone
            If .Name = "Player_climbing_1" Then Set NewPlayerClimbing = .Clone
            If .Name = "Spear_1" Then Set NewSpear = .Clone
            If .Name = "Spear_ground_1" Then Set NewSpearGround = .Clone
            If .Name = "Spear_slant_left_1" Then Set NewSpearSlantLeft = .Clone
            If .Name = "Spear_slant_right_1" Then Set NewSpearSlantRight = .Clone
            If .Name = "Spear_wall_left_1" Then Set NewSpearWallLeft = .Clone
            If .Name = "Spear_wall_right_1" Then Set NewSpearWallRight = .Clone
         End If
         I = I + 1
      End With
   Loop
   Set NewJumpLeftTmp = NewJumpLeftSpr.Template
   Set NewJumpRightTmp = NewJumpRightSpr.Template
   Set NewSpearGroundTmp = NewSpearGround.Template
   Set NewPlayerSpearTmp = NewPlayerSpear.Template
   Set NewSpearSlantLeftTmp = NewSpearSlantLeft.Template
   Set NewSpearSlantRightTmp = NewSpearSlantRight.Template
   Set NewSpearWallRightTmp = NewSpearWallRight.Template
   Set NewSpearWallLeftTmp = NewSpearWallLeft.Template
   Set NewSwimmingTmp = NewSwimming.Template
   Set NewHurtAnimationTmp = NewHurtAnimation.Template
   Set NewPlayerClimbingTmp = NewPlayerClimbing.Template
   Set NewSpearTmp = NewSpear.Template
End Sub

Code: [Select]
Sub LoadSprites
   With ProjectObj.Maps("Home_Desert")
      Dim NewSprDef, I
      For I = 0 to 11
         If I = 0 Then
            Set NewSprDef = NewPlayerSpear
            NewSprDef.Name = "Player_spear_" + MapNum
            Set NewSprDef.Template = NewPlayerSpearTmp
         ElseIf I = 1 Then
            Set NewSprDef = NewJumpLeftSpr
            NewSprDef.Name = "Player_jumping_left_" + MapNum
            Set NewSprDef.Template = NewJumpLeftTmp
         ElseIf I = 2 Then
            Set NewSprDef = NewJumpRightSpr
            NewSprDef.Name = "Player_jumping_right_" + MapNum
            Set NewSprDef.Template = NewJumpRightTmp
         ElseIf I = 3 Then
            Set NewSprDef = NewSwimming
            NewSprDef.Name = "Player_swimming_" + MapNum
            Set NewSprDef.Template = NewSwimmingTmp
         ElseIf I = 4 Then
            Set NewSprDef = NewHurtAnimation
            NewSprDef.Name = "Hurt_animation_" + MapNum
            Set NewSprDef.Template = NewHurtAnimationTmp
         ElseIf I = 5 Then
            Set NewSprDef = NewPlayerClimbing
            NewSprDef.Name = "Player_climbing_" + MapNum
            Set NewSprDef.Template = NewPlayerClimbingTmp
         ElseIf I = 6 Then
            Set NewSprDef = NewSpear
            NewSprDef.Name = "Spear_" + MapNum
            Set NewSprDef.Template = NewSpearTmp
         ElseIf I = 7 Then
            Set NewSprDef = NewSpearGround
            NewSprDef.Name = "Spear_ground_" + MapNum
            Set NewSprDef.Template = NewSpearGroundTmp
         ElseIf I = 8 Then
            Set NewSprDef = NewSpearSlantLeft
            NewSprDef.Name = "Spear_slant_left_" + MapNum
            Set NewSprDef.Template = NewSpearSlantLeftTmp
         ElseIf I = 9 Then
            Set NewSprDef = NewSpearSlantRight
            NewSprDef.Name = "Spear_slant_right_" + MapNum
            Set NewSprDef.Template = NewSpearSlantRightTmp
         ElseIf I = 10 Then
            Set NewSprDef = NewSpearWallLeft
            NewSprDef.Name = "Spear_wall_right_" + MapNum
            Set NewSprDef.Template = NewSpearWallLeftTmp
         ElseIf I = 11 Then
            Set NewSprDef = NewSpearWallRight
            NewSprDef.Name = "Spear_wall_right_" + MapNum
            Set NewSprDef.Template = NewSpearWallRightTmp
         End If
         Set NewSprDef.rLayer = ProjectObj.Maps("Home_Desert").MapLayer("Main")
         Set NewSprDef.rPath = .Paths(1)
         .AddSpriteDef HostObj.AsObject(NewSprDef)
      Next
   End With
End Sub

According the the scripting reference, the tileset used by the sprite is part of the sprite definition and template. So, yet again, what's the problem?

bluemonkmn

  • SGDK Author
  • Administrator
  • Fanatic
  • *****
  • Posts: 2761
    • ICQ Messenger - 2678251
    • MSN Messenger - BlueMonkMN@gmail.com
    • View Profile
    • http://sgdk2.sf.net/
    • Email
Re: Sprite Definition Creation
« Reply #4 on: 2006-12-28, 02:26:14 PM »
In order to reduce video memory overhead, GameDev attempts to only load tilesets used within a particular map when switching to a map.  I suspect that the tileset used by your dynamically loaded sprite definition may not be referenced anywhere in the map and therefore not be loaded at the time you are attempting to use it.  To test this hypothesis, try adding a dummy sprite to the map that uses the tileset you need to have loaded.  If that fixes the problem, then the hypothesis is confirmed.  I think the problem could then be resolved by calling some sort of Load or Create method to create/load the tileset into video memory, but I don't remember it off the top of my head.  I can look it up if you confirm that this is in fact the problem.

eric22222

  • Fanatic
  • ***
  • Posts: 177
    • View Profile
    • Eric Online
    • Email
Re: Sprite Definition Creation
« Reply #5 on: 2006-12-28, 02:58:15 PM »
Oh... so that's what a loaded/unloaded tileset means. I'd read that somewhere, can't remember where...

Yeah, I'll give that a shot. Thanks!

Oh, it was in the tileset box where I always see it. Some have Us next to them and some have Ls.

EDIT: That did it. It's gotta be the unloaded tileset. So I'll need to load two tilesets when I load a map. I guess there's something about that in the scripting reference.
« Last Edit: 2006-12-28, 03:35:38 PM by eric22222 »

bluemonkmn

  • SGDK Author
  • Administrator
  • Fanatic
  • *****
  • Posts: 2761
    • ICQ Messenger - 2678251
    • MSN Messenger - BlueMonkMN@gmail.com
    • View Profile
    • http://sgdk2.sf.net/
    • Email
Re: Sprite Definition Creation
« Reply #6 on: 2006-12-29, 06:17:44 AM »
Actually there are two degrees to which a tileset can be loaded.  The first is the one you mention of loading the graphics into system memory (which causes an "L" to be displayed next to the tileset instead of a "U").  This is accomplished with the TileSetDef.Load method.  The second is loading the graphics into video memory (into the DirectX display object) and this is accomplished with a call to various LoadTiles methods.  The one you want is probably on the SpriteDef object.  SpriteDef.LoadTiles will ensure that the Tileset for this SpriteDef's frames has been loaded into system memory and into video memory.  Actually it just calls SpriteTemplate.LoadTiles since that's where the frames are defined, but it's a handy shortcut if the SpriteDef object is what you happen to have a reference to.