Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Confused with X & YByOffSet

Author
Message
MobileCreator
12
Years of Service
User Offline
Joined: 1st Jun 2011
Location: Ottawa - Canada
Posted: 5th Oct 2011 16:14
It seems straightforward, but I'm having problems understanding the concept based on what I'm seeing in my game.

I have a sprite with a size of 38x28. I set my sprite offset with

SetSpriteOffSet(sprite, 19, 14)


But when I want to get the current sprite position, using both GetSpriteXByOffSet and GetSpriteYByOffSet, the sprite seems off where it should be. Comparing the values returned above with the regular GetSriteX, the difference between the latter and the byOffset coordinates is about 5, instead of the usual 19.

That said, it seems my sprite offset is set a little to the left instead of exactly the middle.

I found the scale could affect the values to pass to the SetSpriteOffset, but I'm not setting the scale anywhere in my code, and even forcing the scale to 1 doesn't change a thing.

Any help will be appreciated.

Thanks

----------
Paulo
http://www.mobilecreators.com
XanthorXIII
AGK Gold Backer
12
Years of Service
User Offline
Joined: 13th May 2011
Location:
Posted: 5th Oct 2011 16:28
Are you using Virtual Resolution or Aspect Ratio?
MobileCreator
12
Years of Service
User Offline
Joined: 1st Jun 2011
Location: Ottawa - Canada
Posted: 5th Oct 2011 17:47
I'm using virtual resolution but I actually don't know why - Is aspect ratio better for that case?

My Virtual resolution is set to 768x1024 (iPad portrait) but my setup.agc dimensions are set to 768x900 (so I can see on my laptop monitor as well).

----------
Paulo
http://www.mobilecreators.com
Rich Dersheimer
AGK Developer
14
Years of Service
User Offline
Joined: 1st Jul 2009
Location: Inside the box
Posted: 5th Oct 2011 17:54 Edited at: 5th Oct 2011 17:58
If you were using a percentage based display, it would make a difference, but with a virtual resolution, it should not make a difference.

We could help more if we could see your code, or at least some example code that shows the problem.

Here is some code that shows the ByOffset working correctly...





Attachments

Login to view attachments
MobileCreator
12
Years of Service
User Offline
Joined: 1st Jun 2011
Location: Ottawa - Canada
Posted: 5th Oct 2011 18:33
Hi,

thanks for the answers so far.

This is the code where I create my sprite:



I forgot to mention my sprite is a sprite sheet, but I believe I'm doing the right thing here.

Here is the function to position the sprite.



And here is the place where I handle the ball movement.



(*) Although it is called ball, it is actually a rectangular shaped sprite 38x28.

Thanks again!

----------
Paulo
http://www.mobilecreators.com
Impetus73
12
Years of Service
User Offline
Joined: 28th Aug 2011
Location: Volda, Norway
Posted: 5th Oct 2011 21:42
Just a tip!

SetSpritePositionByOffset( bla,bla,bla) Will automatically offset to the center of the sprite, so no need to spend days calculating the center of your sprites with that old solar calculator on your desk, in the half dark light from your monitor, bashing and slamming it to make it work in the dim light.


----------------
AGK user - novice
Did Amiga / AMOS programming in the 90's, just started programming again with AGK.
Impetus73
12
Years of Service
User Offline
Joined: 28th Aug 2011
Location: Volda, Norway
Posted: 5th Oct 2011 21:50 Edited at: 5th Oct 2011 21:53
MobileCreator, that log() function... does it write events to a logfile? Ifso, its a brilliant way to debug a game. Now, why did I not think of that?, with me printing diag strings all over the game screen...

Rectangular ball... sound like a ball squarepants bob would love!

----------------
AGK user - novice
Did Amiga / AMOS programming in the 90's, just started programming again with AGK.
Rich Dersheimer
AGK Developer
14
Years of Service
User Offline
Joined: 1st Jul 2009
Location: Inside the box
Posted: 5th Oct 2011 22:23
Impetus73, you say
Quote: "SetSpritePositionByOffset( bla,bla,bla) Will automatically offset to the center of the sprite,"


but I don't think that is true. The help says

Quote: "This function always positions the sprite using its current offset. For example if the current offset is the center of the sprite this command will place the center of the sprite at the given coordinates."


and it has been my experience that the offset is used for the origin, NOT the center of the sprite. If you set the offset to the center, yes, it's positioned by the center. But if you set the offset to the bottom right corner, then it's positioned by that origin.

Impetus73
12
Years of Service
User Offline
Joined: 28th Aug 2011
Location: Volda, Norway
Posted: 5th Oct 2011 22:30 Edited at: 5th Oct 2011 22:34
Don't correct me if i'm right, but it does work!

Try to rem out the setspriteoffset commands in your code, and it still produce the same results.

EDIT:
Rich, I see your point.

yes, the current offset. I just pointed out that the DEFAULT sprite offset is at the center of the sprite, if no setsprite offset command is used on the sprites.

----------------
AGK user - novice
Did Amiga / AMOS programming in the 90's, just started programming again with AGK.
Rich Dersheimer
AGK Developer
14
Years of Service
User Offline
Joined: 1st Jul 2009
Location: Inside the box
Posted: 5th Oct 2011 22:36
Impetus73 - oh, I see what you are saying! If you want the offset to be the center, no need to actually set it.

We're on the same page now!

Impetus73
12
Years of Service
User Offline
Joined: 28th Aug 2011
Location: Volda, Norway
Posted: 5th Oct 2011 22:50 Edited at: 5th Oct 2011 22:52
Yes! (hope it's not the last page)

I would a list from the TGC team, stating all the default values for the command functions, so we don't need setting alot of un-needed commands.

----------------
AGK user - novice
Did Amiga / AMOS programming in the 90's, just started programming again with AGK.
MobileCreator
12
Years of Service
User Offline
Joined: 1st Jun 2011
Location: Ottawa - Canada
Posted: 5th Oct 2011 23:36
Hi,

Impetus73, the log function is to save to file and print on screen in a scrollable "window". I posted the sources here another day... I just didn't put a "Free Code" in the subject. The post is this one: http://forum.thegamecreators.com/?m=forum_view&t=189981&b=41

I'd love to get some feedback about it. Now back to my question:

So, if I want to *always* use the center of my sprite as my coordinates, I don't have to set anything, since it is the default. Is that correct?

Now, one thing that I don't understand is why GetSpriteXByOffSet() - GetSpriteX() is let's say 10 considering my sprite is 28 pixels wide and the offset is in the center of it. Shouldn't be the difference always 14?

Also, remember I'm not explicitly scaling my sprite.

Still lost here.

Thanks again!

----------
Paulo
http://www.mobilecreators.com
Impetus73
12
Years of Service
User Offline
Joined: 28th Aug 2011
Location: Volda, Norway
Posted: 6th Oct 2011 00:32 Edited at: 6th Oct 2011 00:34
darn, pressed F5 when i were going to post my reply, and all the text got F5kt... habbit from compiling, haha

Maybe the ball image is not in the center of the image, and the physic center is then used as default offset center?



----------------
AGK user - novice
Did Amiga / AMOS programming in the 90's, just started programming again with AGK.
XanthorXIII
AGK Gold Backer
12
Years of Service
User Offline
Joined: 13th May 2011
Location:
Posted: 6th Oct 2011 00:32
I thought your Sprite was 38x28 which would be 38 X by 28 Y.
MobileCreator
12
Years of Service
User Offline
Joined: 1st Jun 2011
Location: Ottawa - Canada
Posted: 6th Oct 2011 02:45
Yes, you're right. I wrote that last post without checking my code.

So in any case, considering 38 wide, the middle is 19. The difference between x and offset x is 19, but I get around 9.

I'll try to test the same sprite in a blank project I see what I have. I'm pretty sure it is my mistake, not an AppGameKit bug, but I still have no idea what I've done.

----------
Paulo
http://www.mobilecreators.com
XanthorXIII
AGK Gold Backer
12
Years of Service
User Offline
Joined: 13th May 2011
Location:
Posted: 12th Oct 2011 20:57
Sorry to dig up an old horse to beat on but say if I use SetSpritePositionByOffset(spr,x,y), have a sprite of 10x10. Then let's say I set the Sprite using the Offset function to a position of 19X, 19Y, would that mean that the X position of the Sprite would be a 14 and the Y position be at 14?
Thanks, just trying to get a feel of how this function works.
MobileCreator
12
Years of Service
User Offline
Joined: 1st Jun 2011
Location: Ottawa - Canada
Posted: 12th Oct 2011 21:47
This is true if you're setting the sprite offset right in the middle. As I learned in this thread, this is the default offset if you don't say explicitly otherwise.

There is a function called SetSpriteOffset that can be used to set the offset to another coordinate. So following your example, if I first call SetSpriteOffset(sprite, 2, 2) my sprite offset will be close to the upper left corner, and if I place it at 19x, 19y, the actual X and Y will be 17,17 instead.

Cheers

----------
Paulo
http://www.mobilecreators.com

Login to post a reply

Server time is: 2024-03-29 00:48:36
Your offset time is: 2024-03-29 00:48:36