PDA

View Full Version : Problem when overriding GetBoundsRect.



Chesso
08-01-2007, 11:52 AM
Iv'e asked alot of questions lately haha, am I keeping you all busy?

Anyway, here is a copy of the email I sent off to Micrel (the guy doing UnDelphiX atm) after some after small discussions, this is basically the best way I could describe my problem.


Hello, I will explain a little more as to the problem with GetBoundsRect.

I override it so I can specify the bounding rectangle (that's used with collisions, so basically resize the invisible box around the sprite).

Like so:

Result := Bounds(Round(WorldX), Round(WorldY), Width, Height);

Now the last two values, Width and Height (or Right and Bottom if you like), work fine and can be adjusted.

However, modyfing The Top and Left doesn't really have much of an effect at all it seems.

Like, if I wanted to reduce the height of the bounding box so that the sprites head was not treated during collisions, logically (for me), I would increase the TOP value so it pushes the bounding rectangle down further.

But this does not seem to work, infact changing it in minus or plus, does absolutely nothing, unless I set it to 0 and the sprite will not move anymore.

You could probably test his yourself quite easily, using UnDelphiX 1.07B, make up two basic filled boxes in MSPaint, one will be the one you move around and the other a collisioned object. Override the GetBoundsRect function for the moving sprite and try what I did and hopefully you will see what I mean.

jasonf
08-01-2007, 12:47 PM
I think I see your problem here.

You want to have a smaller area near to the characters' feet as the only place where collisions are detected so that you interract with the background as if you were looking down from an angle over the game screen.

Well, to achieve this, you could always think outside the box ;)

How about this idea.
You use 2 sprites.

You have a sprite with no image - just a bounding box, or at the most, it's a shadow circle. This is your main sprite... All background collision detection is done via this sprite. In fact, all movement is done via this sprite too.

Next, you create a second sprite. This is your player avatar sprite. This sprite does not react to background collisions, only to bullets. This sprite can shoot things but cannot move on its own.

The first sprite (the shadow) has reference to the avatar sprite and on each doMove, it updates the avatar sprite with the new X&Y co-ordinates. (positioned so that the characters' feet appear inside the shadow sprite) You can be sure that these co-ordinates are valid places on the map because you've already done those checks in the onCollide method.

Your shadow sprite moves when you press the arrow keys
Your avatar sprite fires bullets when you press the fire button.
The shadow sprite moves the avatar.
The avatar sprite has a Z-axis slightly higher than that of the shadow so it's always drawn on top.


Personally, I wouldn't do it this way, I'd use a collision array and check my position against it vs the walls. The collision map and the artwork are seperate that way. But my way involves more coding and this way uses more DelphiX internals. But it does involve 2 sprites instead on one... but that's no big deal. DelphiX can handle it.

Chesso
08-01-2007, 12:56 PM
Yeah I have taken that way into consideration (basically a quick and more bloated way to do it).

I didn't write how GetBoundsRect works but I'm fairly sure that there is something really wrong with how some portion of it works lol.

Iv'e been talking with Micrel but I don't think he's understanding my english, it's difficult to spell out my problem in a simple way.