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.

Dark GDK / Please Help 2D question

Author
Message
Poof Master
14
Years of Service
User Offline
Joined: 14th Jan 2010
Location:
Posted: 4th Feb 2010 01:22
Okay so here is my problem:

dbSpriteWidth and height are supposed to return the value of whatever the given sprite is. The problem is when I use it in this function it doesn't work:



I have tried to set the variable equal to dbSpriteWidth and height but the value of that varible is either 0 or -1 when I use the window watcher.

The weird thing is when I use the function dbSpriteOffset like so:



the value of dbSpriteWidth and height are then equal to the actual value of the sprite I made. (which is 90)

Here's the full code I commented the points where I am trying to use dbSpriteWidth and Height and commented on there values at those points in program.



So not to sure whats going on anyone have an idea?
WH8
15
Years of Service
User Offline
Joined: 17th Mar 2009
Location:
Posted: 4th Feb 2010 06:22 Edited at: 4th Feb 2010 06:27
I am not 100% certain of the problem, but it looks like you are calling dbSpriteWidth() and dbSpriteHeight() for a sprite that does not exist yet? The reason the two functions "work" at dbOffsetSprite() is because you just created sprite number 1 right before using those two functions, while at the first location where the two functions do not "work", sprite number 1 does not exist yet. From what I can see, this is the probem. Sprite number 2 looks like it is also experiencing the same problem. I am guessing you are getting 0 or -1 from those two functions because you are asking them to give you the width or the height of a sprite that does not yet exist.
Poof Master
14
Years of Service
User Offline
Joined: 14th Jan 2010
Location:
Posted: 4th Feb 2010 07:37
Yeah I guess dbSpriteWidth and Height are based off the function dbSprite() so I was calling that function in my main loop but I wasn't calling it above. The one thing about that then is it okay for me to call that function in two different places. I say this because of how things are initialized:

this is in my main loop:



The position is initialized in this loop so in order for my sprite to have the same position as the 2d physics box I had to call dbSprite in this loop rather than up in the main entry point.

So is there any harm in calling that function in both places cause this is how I have it now:



Is there a better way or am I just going to have to call it twice?
WH8
15
Years of Service
User Offline
Joined: 17th Mar 2009
Location:
Posted: 5th Feb 2010 04:15 Edited at: 5th Feb 2010 04:31
Remember that you create a sprite using dbSprite(). No sprite is created with dbLoadImage(). All dbLoadImage() does is put a picture into memory so that later on in your program that picture can be "used". Until dbSprite() is called, the sprite does not exist. Trying to find the width and height of a non-existing sprite will not give the width and height of the sprite that you want to exist. In other words, you MUST use dbSprite() for your sprites 1 and 2 before trying to find their widths or heights with dbSpriteWidth() and dbSpriteHeight().

You can call dbSprite() for any sprite as many times as you like. dbSprite() is not only used to create sprites, but to reposition existing sprites as well. If you want to change the image of a sprite, you might need to use dbSetSpriteImage().

There is a documentation on some of the Dark GDK functions that you can find roughly in: C:\Program Files\The Game Creators\Dark GDK\Documentation.
Poof Master
14
Years of Service
User Offline
Joined: 14th Jan 2010
Location:
Posted: 6th Feb 2010 07:19
Yeah I understand now. Thanks for the help I guess my next task is to put all that code into a class so I can just call an initialize and update function for any new boxes I want to create but anyway thanks for the explanation.

Login to post a reply

Server time is: 2024-11-20 05:26:17
Your offset time is: 2024-11-20 05:26:17