News:

Building a 3D Ray Tracer  By stevmjon

Main Menu

Unknown Problem

Started by Tracy, January 19, 2006, 11:08:35 PM

Previous topic - Next topic

Tracy

Hi again Kevin. I'm back. :)

I've come across another problem that I was hoping you could help me out with. I've been fiddling with it for upwards of an hour now, and I can't seem to pinpoint where I'm making the error. I've included the entire code of the game that I've got so far (most of it's yours),  in case that's helpful to you.

The problem goes as follows:

(exerpt from my Create pPlayer Psub)
...
      playerimage=GetFreeImage()
      LoadImage Character(currentchar).Stand_Animation$,playerimage
      ScaleImage playerimage,PLayer(Player).SizeX,PLayer(Player).SizeY,1
      PLayer(Player).Stand_Animation=playerimage
      
      playerimage2=GetFreeImage()
      LoadImage Character(currentchar).Crouch_Animation$,playerimage2
      ScaleImage playerimage2,PLayer(Player).SizeX,PLayer(Player).SizeY,1
      PLayer(Player).Crouch_Animation=playerimage2
...


When I try to use player(player).Crouch_Animation as the sprite image, it seems to be giving me a null value (i.e. no image, therefore no image length/width, and therefore errors when the program tries to see if there's a collision with the aliens since it uses GetSpriteWidth.) I get a 'Shape number out of legal range' error, and it cites the Function Update_Aliens(Player,ThisMap,ThisLevel) as containing it.

If I use, instead, 'playerimage' as my sprite image, it all works just fine. If I try to do something like

PLayer(Player).Stand_Animation=GetFreeImage()

I also get a null value and a fatal error. It's like the image won't store directly into the Player(player).XXXX variables for some reason, and I don't understand it. I got around it the first time by using 'playerimage' as an intermediate, but I can't seem to use playerimage again, or even playerimage2. I tried to see if 'playerimage' was defined anywhere else, but I can't seem to find it. Is there a rule about using GetFreeImage() more than once in the same function/psub? Or is there some reason that I can't store the images there that I'm not catching?

I'd like to store the images all in memory at the same time (they're small images, as in 90x75 pixels, nothing heavy) so I don't have to continually reload them during gameplay (it slows dramatically when I load a lot), and this was the best way that I could think of. Is there an easier way? (I'm almost positive there is, or I wouldn't ask.)

Anyway, thanks again for your help, Kevin. Anything you can do would be greatly appreciated. I'd not be suprised if I'm missing something fairly obvious here.

(and here's the full code, if you're interested. I can send you the images in question if you're curious, but I've used them succesfully before, so I don't think they're the problem)



PlayBASIC Code: [Select]
   `============================================================================
`this will allow or not allow editing to the map. 0 = no-edit : 1 = edit
`============================================================================
allowedit = 0
`============================================================================
`============================================================================




OpenScreen 640,480,32,2
SetFPS 0
Mouse Off
ScreenVsync On
`ImageQuantity 200000
`Shapequantity 200000

Dim drawblock(3,3)

`===================
`Global Variables/Constants
`===================

`Bullet Values
Global Bullet_Qty

`Character Values
Global CurrentChar
CurrentChar=1
Constant Number_of_pCharacters=1
Global PlayerLevel
Global Rectangle `Standard Collision Rectangle
Rectangle=GetFreeShape()
CreateConvexShape Rectangle,30,4


Randomize 57
`Alien Values
Constant Alive=1
Constant Dead=0

`Map Values
Global Map_width,Map_Height
Constant GlobalGravity# =0.75
Constant Tile_Width =40
Constant Tile_Height =40

ctile = 0


; =================
; Tile Colours
; =================
Data RGB(255,255,255) ` White Block
Data RGB(255,20,25) ` RED/Block
Data RGB(255,255,25) ` Yellow Block
Data RGB(25,255,25) ` GREEN
Data RGB(255,25,255) ` PURPLE
Data RGB(55,95,155) ` PURPLE
Data -1

Cls 0
x=Tile_width
Repeat
Col=ReadData()
Shade_Block(Col,X,0,Tile_Width,Tile_Height)
x=x+Tile_width
Until Col=-1

MapGfxImage=GetFreeImage()
mapgfximage1=GetFreeImage()
`GetImage MapGfxIMage,0,0,x,tile_height
LoadImage "icetiles.png",MapGfxImage
LoadImage "CURSOR.bmp",1000


; ========================================
; Manually Build the a MAP
; ========================================

ThisMap=GetFreeMap()

CreateMap ThisMap,50
MakeMapGFX ThisMap,MapGfxIMage,Tile_width,Tile_height,40,0


ThisMapLevel=2
For i = 2 To 3
Load_Title_Map(ThisMap,i,i-1,Tile_Width,Tile_height)
LevelTransparent Thismap,i,0
If i = 3 Then block = 1
convert_map(ThisMap,i,block)
Next i



; ==============================================
; CREATE A CAMERA To VIEW WORLD WITH..ng
; ==============================================
; The camera also handles the drawingorder, Scrolling And clipping in this example.
; ==============================================

CreateCamera 1
CameraCls 1,Off
LimitCamera 1,True
LimitCameraBounds 1,0,0,GetLevelABSWidth(thisMap,thismaplevel)-40,GetLevelABSHeight(thisMap,thismaplevel)-40


` ===============================
` CReate Player Data Type
` ===============================
Type tPLayer

`These are player variables that ARE NOT loaded from the data array
Spr
SprAngle
Image

Facingleft
Xpos#,Ypos#
XSpeed#,YSpeed#

Level
Experience

Jump_Status
Dash_Status
Dive_Status
Grab_Status
WingFlaps

Poison
Burn
Frozen
Shock `No regeneration if shocked. Ouch.
Stun
Slow

Pause_Timer
Dash_Timer
CantJump_Timer
Animation_Timer
Attack_Timer
Regen_Timer
Stun_Timer
Shock_Timer
Slow_timer
Poison_timer
Login required to view complete source code




Tracy

Update: I've found that if I add a shape to my image, all of a sudden everything seems to work just peachy. I have NO idea why that is, as I was under the impression that if no shape was specifically assigned to an image, the dimensions of the image would be used as its shape.

So it seems as though my player(player).XXXX variable CAN store images (like I thought) but I need to assign them a shape for some reason. Hmm. I don't get it.

Kevin, what have I missed in my hours of combing through function descriptions? (Which, by the way, are very well done. I can almost always puzzle myself through my problems with a quick reference to the help manual. Kudos on that. That's a lot of work.)

kevin

SpriteCollisionMode s,3

 Here your telling the sprite collision engine to use the shape associated/attached to the Image, rather than the image dimensions for this sprite.   If you use this mode, you'll have to create the shape manually  (i.e an outline of the graphics the shape is meant to represent).  It's not automatic.

 You prolly want mode 2,  rotated most of the time.  Which uses the image dimensions (taking into account rotation/scaling).  Which Is good enough most of the time.

Tracy

yup. That was it. Thanks again for taking the time to answer newbie questions. Hopefully as time goes on I'll start having meaningful problems. :)

QuoteSpriteCollisionMode s,3

  Here your telling the sprite collision engine to use the shape associated/attached to the Image, rather than the image dimensions for this sprite.   If you use this mode, you'll have to create the shape manually  (i.e an outline of the graphics the shape is meant to represent).  It's not automatic.

  You prolly want mode 2,  rotated most of the time.  Which uses the image dimensions (taking into account rotation/scaling).  Which Is good enough most of the time.