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 / Looking for function

Author
Message
Andrzejef
14
Years of Service
User Offline
Joined: 26th Dec 2011
Location:
Posted: 10th May 2012 16:05
Hi again,
I'm in a need of a function/command/whatever which act in the same way as paste sprite one, but changes the x and y coordinates of the sprite. Could you lend me a hand?
Tkanks in advance.
Chris Tate
DBPro Master
17
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 10th May 2012 18:04
User defined functions enable you to create solutions which perform more than one action. You can move and paste your sprite using a function.



MrValentine
AGK Backer
15
Years of Service
User Offline
Joined: 5th Dec 2010
Playing: FFVII
Posted: 10th May 2012 18:51
CHris, do you mind explaining where

Quote: "iX, iY"


comes from I struggle with it...

the combination of the two characters...
maybe I know it already but just can not figure out the process right now...

thanks in advance...

and sorry for side tracking... though might also be helpful for future readers

Chris Tate
DBPro Master
17
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 10th May 2012 20:07
'i' in iX, iY is a prefix for 'integer'. I probably would have used fX#, fY#, for floats.

This is not necessary. It is a habit I use to avoid naming conflicts in my current project.

In the example above I would have normally avoid using x and y for global or root level variable names, but I did not take it that seriously this time.

The # and $ symbols can be used obviously to represent floats and strings, but names such as x# and name$ conflict with alot of coding which sit in sub routines that share the same scope.

When a naming conflict does occur in a project with 30-40 thousand lines of code, it is not a nice experience...

Using UDTs is another way to help; in this case I do not prefix the variables; but for this example a UDT would be over the top.

MrValentine
AGK Backer
15
Years of Service
User Offline
Joined: 5th Dec 2010
Playing: FFVII
Posted: 10th May 2012 20:12
thanks again I sort of got it

zeroSlave
17
Years of Service
User Offline
Joined: 13th Jun 2009
Location: Springfield
Posted: 10th May 2012 22:09 Edited at: 10th May 2012 23:34
MrValentine:

When creating the function, he is declaring new local variables for use inside the function:
iSpriteId
iX
iY

This way, when he calls the function: DisplaySprite(SpriteId, X, Y)

It passes the information from:
SpriteId to iSpriteId
X to iX
Y to iY
So that it can be used inside the function and not take global variables.

It could also be interpreted as:


Another example:




Everybody is a genius. But if you judge a fish by its ability to climb a tree, it will live its whole life believing that it is stupid.
MrValentine
AGK Backer
15
Years of Service
User Offline
Joined: 5th Dec 2010
Playing: FFVII
Posted: 11th May 2012 03:50
Thank you zeroSlave

Man I love this community

zeroSlave
17
Years of Service
User Offline
Joined: 13th Jun 2009
Location: Springfield
Posted: 11th May 2012 07:28
I didn't know if you were talking about the choice of name for the variables, or how they were used in a function like that. (I chose to understand it as the latter. ) Either way, I figured it would probably be helpful to someone.

Everybody is a genius. But if you judge a fish by its ability to climb a tree, it will live its whole life believing that it is stupid.
MrValentine
AGK Backer
15
Years of Service
User Offline
Joined: 5th Dec 2010
Playing: FFVII
Posted: 11th May 2012 07:52 Edited at: 11th May 2012 07:54
its ok, I will get it eventually but right now I got an irritating sound coming from the back of the house and it seems there is nothing I can do about it... I can simply not focus... time to call the council

EDIT

when will my feature request get made lol i > I

Neuro Fuzzy
19
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 11th May 2012 10:59
I think the problem you're having is that the "sprite" command not only creates a sprite, but also positions it. You don't need to use paste sprite at all!

Chris Tate
DBPro Master
17
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 11th May 2012 11:29
What Neuro Fuzzy says is true, you do not need to paste a sprite if it is visible. My suggestion is only necessary for manual drawing purposes or if you want to display the sprite in numerous locations without duplicating it.

Andrzejef
14
Years of Service
User Offline
Joined: 26th Dec 2011
Location:
Posted: 11th May 2012 14:49
OK, I'll just solve it in that way.



Many thanks for so much... responses
Have a nice day, though.
Chris Tate
DBPro Master
17
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 11th May 2012 22:50
No problem; but in your code snippet, you should not delete the sprite; that would be unnecessary. Only delete a sprite when you no longer need it. In your loop, you will always need your sprite for each engine loop frame, so deleting it is a waste of time.

Take it easy.

Andrzejef
14
Years of Service
User Offline
Joined: 26th Dec 2011
Location:
Posted: 14th May 2012 10:55
ok, then, thanks for advice.
But I still need to change the coordinates x and y of sprite and paste sprite command don't change it. And the way I made it is the only way I thought about and it's working. If I deleted command delete sprite, program would return that specified sprite already exist.
Pincho Paxton
23
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 14th May 2012 14:46
Quote: "If I deleted command delete sprite, program would return that specified sprite already exist."


If you don't know how the program works you are wasting your time. Best to write it yourself from scratch, because your solution is easy.

Andrzejef
14
Years of Service
User Offline
Joined: 26th Dec 2011
Location:
Posted: 14th May 2012 17:02
Quote: "If you don't know how the program works you are wasting your time. Best to write it yourself from scratch, because your solution is easy."

I WROTE it from scratch. I checked five times that paste sprite command don't changes the coordinates of sprite (x and y are slill the same).
But that's interesting what you are saying. I thought that sprites will act like images, and it returns error window when you create second image with same number as previous one. Well, that's good to know. Thanks again then.
Pincho Paxton
23
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 15th May 2012 00:24 Edited at: 15th May 2012 00:32
Well at least you got it working.

Login to post a reply

Server time is: 2026-07-22 00:35:48
Your offset time is: 2026-07-22 00:35:48