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.

DarkBASIC Professional Discussion / Retrieving absolute X and Y co-ords for a sprite

Author
Message
bodmcn
15
Years of Service
User Offline
Joined: 6th Oct 2010
Location:
Posted: 23rd Oct 2010 06:51
The SPRITE X() command only seems to return the values as given by the SPRITE command; once ROTATE'd around an OFFSET there does not seem to be a way to get the post processed X and Y co-ords of a sprite.

I can get the OFFSET X and Y and the ANGLE, but not the co-ords where the sprite is currently residing.

Could anyone let me know if there is a way of getting the definitive screen co-ords for where a sprite is displayed?
CocaCola
16
Years of Service
User Offline
Joined: 23rd Mar 2010
Location: CocaCola.x CocaCola.y CocaCola.z
Posted: 23rd Oct 2010 07:07 Edited at: 23rd Oct 2010 07:08
Quote: "Could anyone let me know if there is a way of getting the definitive screen co-ords for where a sprite is displayed? "

Well I use dark GDK but I used to use dbPro so ill give it a shot.



that SHOULD work. or something like that

Always program as if the person maintaining your program is a psychopath that knows where you live
bodmcn
15
Years of Service
User Offline
Joined: 6th Oct 2010
Location:
Posted: 23rd Oct 2010 07:12
From using the SPRITE X(), as I mentioned above, it only returns the co-ords from the SPRITE command. The output does not change after the a rotation has been performed from an offset.

I would like to find out what the actual co-ords of the sprite are after performing the offset rotation.

Thanks,
gbark
20
Years of Service
User Offline
Joined: 14th Oct 2005
Location: US - Virginia
Posted: 23rd Oct 2010 08:58
When the sprites are drawn, their location on the screen is determined by their position and then their orientation and offset. What that means is, the SPRITE X() and SPRITE Y() commands are returning the position of the sprite's "origin".

There are no built-in commands to return the actual "screen position" of the sprite, but you can get those values yourself by using the same math that the sprites themselves use.

Try something like:
x = sprite x(1) + cos(angle)*offset
y = sprite y(1) + sin(angle)*offset
bodmcn
15
Years of Service
User Offline
Joined: 6th Oct 2010
Location:
Posted: 23rd Oct 2010 12:00
Thanks for that, but it would appear that the whole reason for having these commands in the first place is so you don't have to do the maths; otherwise I'd just calculate it and position it with the SPRITE command.

It does seem that a lot of things in Dark Basic provide the initial means, but not the ability for them to be utilised in practise; nor does it seem to have the completeness of a language like C to implement viable alternatives.

I must be getting grumpy in my old age... I do appreciate the response.
bodmcn
15
Years of Service
User Offline
Joined: 6th Oct 2010
Location:
Posted: 23rd Oct 2010 14:22
Ok - have converted over to the method of calculating the position and storing the co-ords.

Thanks again for the formula - geometry was never my strong point and it worked like a charm.

gbark
20
Years of Service
User Offline
Joined: 14th Oct 2005
Location: US - Virginia
Posted: 23rd Oct 2010 22:15
Glad you got it working.

Quote: "It does seem that a lot of things in Dark Basic provide the initial means, but not the ability for them to be utilised in practise; nor does it seem to have the completeness of a language like C to implement viable alternatives."


Well that's sort of true - I consider what DBPro provides to be just a sort of "starting point" for handling all the nitty-gritty behind the scenes stuff. Handling the DirectX libraries, initializing the world, drawing sprites and objects, etc., are not the kind of stuff I'm interested in doing myself. DBPro exists to do all that stuff for me.

As for fully utilizing those in an actual game - Like you said, that's left up to the programmer to do.

Have you looked at DarkGDK yet though? If you're feeling limited by the BASIC syntax of the language, DarkGDK is a wrapper of all the DBPro functions that you can use in C++. Might be worth checking into if you prefer C++ to BASIC (and all that implies, like Object Oriented Programming).
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 24th Oct 2010 16:28
Quote: "Thanks for that, but it would appear that the whole reason for having these commands in the first place is so you don't have to do the maths;"

Not so - there's no way for TGC to have a command for absolutely every combination of things that everyone might want. Then we'd have people still spotting combinations of things that TGC didn't think of, while simultaneously complaining that there are too many commands and functions and that they can't find anything.

Quote: "nor does it seem to have the completeness of a language like C to implement viable alternatives"

Except that you did appear to get the 'viable alternative' you were looking for...


What is aimed for is to provide enough commands and functions for you to use to provide for yourself what TGC didn't provide.

If you spot a hole in the command set (Hint: This isn't one), then point it out and it's got a good chance of being added to the command set, as long as it doesn't break existing functionality.

Utility plug-ins (26-JUL-2010)
I'm applying terms of use that require you to wear a red nose and honk a horn whenever you use the Internet
bodmcn
15
Years of Service
User Offline
Joined: 6th Oct 2010
Location:
Posted: 25th Oct 2010 04:04
Fair call - apologies for applied grumpiness.

I just hoped that I would be able to get the language to pass me the actual co-ords of a sprite at where it was being displayed on the screen; it would certainly be a good facility to have.

The language stuff was mainly about not being able to pass a user-defined type by reference, return it from a function or assign it to allocated memory (which could be construed as more or less variances of the same thing); from the forum I got the tip of using global arrays as a work around. So a lot of it is getting used to the language and the tips and tricks for allowing generic functions to be written for user defined objects.

All of this is just waffle though to admit that I was wrong in getting grumpy in the response.
Frank C
16
Years of Service
User Offline
Joined: 3rd Jul 2010
Location: Houston TX
Posted: 25th Oct 2010 15:21
If you get the Advanced Sprites plugin, I believe that it includes a command that will give you exactly what you want.

Login to post a reply

Server time is: 2026-07-22 04:37:14
Your offset time is: 2026-07-22 04:37:14