[SOLVED] Manually determine characters position in room, and relative to what?

Started by johanvepa, Fri 01/05/2015 21:33:59

Previous topic - Next topic

johanvepa

Where, exactly, are player.x and player.y, relative to what I can see of the character sprite on the screen?

EDIT: Alternatively, where are player.x and player.y relative to the edge of the actual sprite, even if part of the sprite is not visible?


Gurok

player.x is the centre point of the character sprite. player.y is the bottom of the sprite, adjusted according to how you've set the .z property of the player character. Both are relative to the top left corner of the room (not screen).
[img]http://7d4iqnx.gif;rWRLUuw.gi

johanvepa

The .z property? That sounds interesting, what is it?

Also, let me be sure I get this right:
If a sprite is 28 pixels wide, the player.x property will be at... the x location of the leftmost pixel plus 13?


EDIT: Please ignore my last question. I can work with it as it is. Thank you very much!

Gurok

The .z property is an offset applied to the y position. The default is 0. It's useful for simulating depth when dealing with walkable areas.

If a sprite is 28 pixels wide, and you set the x position to 14, the left edge of the sprite will be at 0. So leftmost plus 14.
[img]http://7d4iqnx.gif;rWRLUuw.gi

johanvepa

EDIT: After I wrote the message beneath, I started over from scratch and tested things in a "clean" environment with big squares for character sprites. It works. Too much clutter-up in my test game, I guess :-D



********************************

Not entirely solved yet, I'm afraid. There is a puzzling issue :confused:

What I'm trying to do is determine if two characters come close enough to trigger a function, which I set up for the occasion.

For testing purposes, I use one character, cEgo, who is 80 pixels wide. Another character, cEnemy, is 28 pixels wide.

I have defined integers of cEgoLeftmost and cEnemyLeftmost in global script.

In room script I have:
Code: ags

function room_RepExec()
{
cEgoLeftmost = player.x-40;
cEnemyLeftmost = cEnemy.x-14;

if (cEnemyLeftmost-cEgoLeftmost < 1)
  {
    [Do something]
  }
}


In game, I make cEgo walk from the left side of the screen to the right side of the screen and see when [Do something] reacts. I'd expect that to be at the exact time when the leftmost pixel of cEgo walks past the leftmost pixel of cEnemy.

However, [Do something] happens about three to four pixels BEFORE their leftmost pixels actually meet.

Any idea how come cEgo triggers the reaction before his Leftmost pixel has passed his enemys Leftmost pixel?



johanvepa

Wait, I need to get to the bottom of this. It kills me to have something that should be so simple mess up  :-X

What, exactly, defines a characters x-location?

Is it the characters normal view or his current view?
And is it the largest frame that is used in the characters view, or frame 0 of the view, or what is it?

Does Change.View affect where player.x is?




MiteWiseacreLives!

Change view shouldn't normally move the x value, concerning a character it will be always the centre. Perhaps you need to get the size of the sprite and divide by 2. Look in the manual under graphic width

johanvepa

But that is what's so strange.


when testing this in a new game (created from template), the above integers and function works fine.

I just cannnot get the same thing to work in my game. It might be because cEgo has multiple views? cEgo has a normal walking view, but for this occasion, changes view with Change.View, into his "confrontation with cEnemy"-view.

Anyway, what happens is this; cEgo is a sprite 80 pixels wide (in his "confrontation" view). cEnemy is a sprite 28 pixels wide.
The function that [does something] and is placed in room_repexec is triggered just prior to when I would expect. The leftmost pixel of cEgo is three or four pixels away from the leftmost pixel of cEnemy. If I change cEgo's size to 60 pixels wide and set int cEgoLeftmost = player.x-30, then the problem is even greater; the function is triggered some 10-12 pixels prior to the two leftmost pixels meeting.

What can be causing this?


MiteWiseacreLives!

Are you trying to have them overlap then trigger the function? I would think a collision would be a left and a right side of two objects, or reversed.
Could try running the check in repeatedly_execute_always?
Maybe check for a blocking walkto command?

johanvepa

My deepest apologies. I have just discovered I was testing different size sprites in view 2 whereas the characters current view was view 4  (roll).

Meaning I have been on a wild goose chase all along. And all my own fault :P.

Again, apologies for wasting your time, all.

SMF spam blocked by CleanTalk