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 / Problem with sprite location.

Author
Message
Isocadia
15
Years of Service
User Offline
Joined: 24th Jul 2009
Location:
Posted: 11th Oct 2009 20:44 Edited at: 11th Oct 2009 21:00
So I'm putting different screen resolutions in my game. But to do so, I figured out that I could not give absolute positions to my sprites, but relative positions to my screenwidth and height. But now I got this problem, were it does not place my welcome text at the correct height. So here is my code.



What the outcome of Screenheight should be is 711, but when I use it in my game, it appears alot higher ( see attachment ).

So am I doing something wrong in my calculations, or is there something wrong with my commands, for the X coordinates are correct.

Isocadia

PS: The standard screen resolution is 1280 by 1024.

EDIT: It also looks like resizing it from screen properties also fails. Very wierd.

EDIT EDIT: Figured out what my problem is. Its just that my calculations don't work. But does anyone know how to resize a sprite so that it takes the same amount of space on the screen, even when changing screen resolution.

Attachments

Login to view attachments
Chamill
16
Years of Service
User Offline
Joined: 29th Sep 2008
Location:
Posted: 11th Oct 2009 21:59
dbStretchSprite( ID , screenwidth/Mainscreenwidth, screenheight/Mainscreenheight );
This should do.

Chamillion

You can only get smarter by playing a smarter opponent.
Ultimate_H
15
Years of Service
User Offline
Joined: 11th Mar 2009
Location: A place that is neither here nor there
Posted: 11th Oct 2009 22:13
If I am reading it right, what you want is the sprite to pretty much scale proportionally with the screen resolution. Personally, I would use the command:

dbSizeSprite("spriteID", "xsize", "ysize")

putting the actual screen width and height in there(or a proportion of it(e.g. dbScreenHeight()/2)) and position the sprite according to the size as well also using a proportion(if it isn't the size of the screen).

sdrawkcab nettirw erutangis a
Scottie Dog
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location:
Posted: 12th Oct 2009 10:21
dbWrapValue is great for controlling rotation. It keeps things within the range of 0 and 360.

1024 / 1.14 = 711

dbWrapValue(711) = 711 - 360 = 351
Isocadia
15
Years of Service
User Offline
Joined: 24th Jul 2009
Location:
Posted: 12th Oct 2009 17:09 Edited at: 12th Oct 2009 18:21
Well, I sorta completly made my calculations suck. But right now I'm trying to base my entire screen on the 1280 x 1024 resolution. And by stretching ( thanks to Chamillion for pointing out that command ) make sure that everything resizes correctly.

Il say if everything is working ( or not ).

Isocadia

Edit : Well, I just can't figure out how to make sprites get to the proper position when you resize the screen.

Edit Edit : Well, now I tried to apply the stretch to my cursor, but he doesn't like it. For he disappeared. Here is the code you need:



I made an external int of the prop, for all my images need to be rescaled. Because of that I make the prop just before making the cursor.

Isocadia
Mireben
16
Years of Service
User Offline
Joined: 5th Aug 2008
Location:
Posted: 12th Oct 2009 21:34
Is that the complete code? Because it looks like you never make a sprite out of those two images. They are loaded as images, then you try to stretch and display them as sprites. At last a dbSprite call is missing for both. And maybe dbHideSprite as well, if you want to paste them with dbPasteSprite later.
Isocadia
15
Years of Service
User Offline
Joined: 24th Jul 2009
Location:
Posted: 13th Oct 2009 17:16 Edited at: 13th Oct 2009 17:28
Haha, what I did to use the stretch is use dbPasteSprite instead of dbSprite, but forgot to add dbSprite when loading them xD. Thanks for you help.

And does anyone know how to reposition your sprites relative to the screen changement??

Isocadia

PS: Thank you all for helping me.

Edit: Well, I hit a very wierd problem, my cursor is behind my sprites instead of above it. How can I solve this??
Ultimate_H
15
Years of Service
User Offline
Joined: 11th Mar 2009
Location: A place that is neither here nor there
Posted: 13th Oct 2009 20:18
Havent tried this myself, but you may be able to do something like this:



The key with this method is to always have the position variables dependent on a proportion of the screen width/height.

The not-so-ultimate Ultimate_H
Isocadia
15
Years of Service
User Offline
Joined: 24th Jul 2009
Location:
Posted: 13th Oct 2009 20:52 Edited at: 13th Oct 2009 21:00
I will try do do something with them, maybe even write a class function so that everything happens with 1 command. But is there a difference between using floats or ints for this??

Isocadia

Edit: Well, to make it applyable to all my sprite at once, I made this:



only that x / ( y/z ) gives me an error, so do I need to calculate m=y/z first and then do x/ m or is there a way to make it first calculate y/z and only then divide x by m?? Hope this is a bit clear.
Ultimate_H
15
Years of Service
User Offline
Joined: 11th Mar 2009
Location: A place that is neither here nor there
Posted: 13th Oct 2009 21:12
the difference in using floats compared to ints in something like this is that it will be much more accurate positioning, and you don't just all of a sudden jump to positions.

I think you forgot to place the parameter parenthesis on dbScreenWidth() and dbSpritePositionX(), and that may be what's giving you the error. x/(y/z) should work if they are base variables, so return's should be fine as well.

The not-so-ultimate Ultimate_H
Isocadia
15
Years of Service
User Offline
Joined: 24th Jul 2009
Location:
Posted: 14th Oct 2009 20:54 Edited at: 14th Oct 2009 21:22
Well, just for fun I decided to make a function of it that could just be called, exept that at the sprite location ( x and Y ) it gives 295 and 711 ( the start position ) instead of 444 and something else. Here is my code so far:



And here is were I call it:



What it should do is divide the screen props were the image was made for ( 1280 x 1024 ) with the new screen props ( 800 x 600 ) it gives the factor of which the screen reduces. Then I divide the sprite position ( lets say the X, thats 295 ) by the reducing of the screen ( 1.6 ) and that should give me 184.375. But the sprite is located at its original 295. So what is going wrong when calculating??

Thanks for all the help you guys already gave me and for sticking with me till here.

Isocadia
Mireben
16
Years of Service
User Offline
Joined: 5th Aug 2008
Location:
Posted: 14th Oct 2009 22:29 Edited at: 14th Oct 2009 22:30
If you divide an integer with an integer, the result is integer, even if you store the result in a float.



IsoWidth: integer. dbScreenWidth: integer.
Result: 1280 / 800 = 1 and not 1.6.

Convert at least one of the values to float:



Same problem with the first two lines in the function. If you want to force them to floats, append a decimal part to the divider:

Isocadia
15
Years of Service
User Offline
Joined: 24th Jul 2009
Location:
Posted: 15th Oct 2009 16:22
Thank you so much, that did it.

Isocadia

Login to post a reply

Server time is: 2024-10-01 14:24:39
Your offset time is: 2024-10-01 14:24:39