News:

PlayBASIC2DLL V0.99 Revision I Commercial Edition released! - Convert PlayBASIC programs to super fast Machine Code. 

Main Menu

Quick Clarification

Started by Tracy, January 21, 2006, 01:47:53 AM

Previous topic - Next topic

Tracy

Hi there.

I was wondering if there was a way to center an image's shape in the middle of the image, instead of drawing it from the upper left corner?

I'm trying to get the image's shape to have a collision detection where I see the image on the screen and can't seem to wrap my head around how to do it properly. Basic creation of the sprite is as follows:

Global Rectangle `Standard Collision Rectangle
      Rectangle=GetFreeShape()
     CreateShape rectangle,4,4
 
 SetShapeVertex rectangle,1,10,10
 SetShapeVertex rectangle,2,28,10
 SetShapeVertex rectangle,3,28,38
 SetShapeVertex rectangle,4,10,38
 
 SetShapeEdge rectangle,1,1,2
 SetShapeEdge rectangle,2,2,3
 SetShapeEdge rectangle,3,3,4
 SetShapeEdge rectangle,4,4,1

If Character(currentchar).Stand_Animation$<>"0"
      PLayer(Player).Stand_Animation=GetFreeImage()
      LoadImage Character(currentchar).Stand_Animation$,PLayer(Player).Stand_Animation
      ImageShape PLayer(Player).Stand_Animation,rectangle
      ScaleImage PLayer(Player).Stand_Animation,PLayer(Player).SizeX,PLayer(Player).SizeY,1
EndIf

s=GetFreeSprite()
      CreateSprite s
            SpriteImage s,PLayer(Player).stand_Animation
      SpriteCollision s,True
      SpriteCollisionClass s,1
      SpriteCollisionMode s,3
      
      PositionSprite s,xpos#,ypos#
     Player(Player).Spr         =s

The result I'm actually getting is that my image's shape seems to not only be located in the upper left corner, it seems to be a single pixel. It makes me think that I'm (yet again) missing something and the shape's not loading properly.

Thanks again for the help.

I'm off to bed.

kevin

#1
When in doubt, draw it.   :)

The issue is that vertex + edge indexs start from zero, not 1.  


PlayBASIC Code: [Select]
Global Rectangle `Standard Collision Rectangle
Rectangle=GetFreeShape()
CreateShape rectangle,4,4

SetShapeVertex rectangle,0,10,10
SetShapeVertex rectangle,1,28,10
SetShapeVertex rectangle,2,28,38
SetShapeVertex rectangle,3,10,38
SetShapeVertex rectangle,4,100,100

SetShapeEdge rectangle,0,0,1
SetShapeEdge rectangle,1,1,2
SetShapeEdge rectangle,2,2,3
SetShapeEdge rectangle,3,3,0


DrawShape rectangle,0,0,2
setcursor 0,100

For lp=0 to 4
print GetShapeVertexX(rectangle,lp)
print GetShapeVertexY(rectangle,lp)
Next

For lp=0 to 4
print GetShapeEdge(rectangle,lp,0)
print GetShapeEdge(rectangle,lp,1)
Next


sync
waitkey





Tracy

#2
Hmm. I've treid drawing my rectangle (in another program window), and I can see it and there's volume to it. and I'm still getting a corner pixel on it with no volume when I apply it to my image, though.

I've tried drawing it [the rectangle] to the image I've got so I can see it in the actual game, but that didn't work either. Again, I'm guessing that somehow 'rectangle' is giving me a null value.

I've tried to create the shape inside the function I'm using it in, I've tried using it as a global variable, and neither work. Anything else I'm missing? I've got this plugged into the "basic 2D game design example" and only get a 'hit Me' when I cross the upper left corner of my sprite across an alien.

I'll play with it some more and see if I can't figure it out when I get a chance.

Note: I'm plugging this into the code I posted a few days ago. Thanks.