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 / Text over a sprite and other stuff?

Author
Message
Giku_
14
Years of Service
User Offline
Joined: 14th Jan 2012
Location: The World
Posted: 18th Jan 2012 16:18
Hi guys sorry for my insistence but we need a lot of help to develop our work.

Q1) How can we print a text over a sprite?
Q2) How to move a sprite under a timer without freezes?
We need that to make an automated sidescroll:

Q3) SPRITE HIT won't work instead of SPRITE COLLISION.
But we need to check collision between visible pixels.
With sprite collision we retrieve 1 when we collide two sprites then with Sprite HIT we gain a permanent 0.
Giku_
14
Years of Service
User Offline
Joined: 14th Jan 2012
Location: The World
Posted: 18th Jan 2012 20:02
Q1) Solved!
Millenium7
21
Years of Service
User Offline
Joined: 13th Dec 2004
Location:
Posted: 18th Jan 2012 20:10
i'll answer the first one

I don't believe you can. However there is some good news
the text commands in dbpro are horrendously slow, seriously they will drag performance down so much its almost unbelievable. So we aren't losing much by getting rid of it

What you need is either d3dfunc or a2text, I found a2text suits my needs better as I don't need to initialise it all the time. Both of these work in that they actually create a whole bunch of sprites for each character in a font

Then what you do is...


this will create all the necessary character's into sprites, stored in an integer variable, the above code only creates all font sizes in steps of 2 up to 48 in the BOLD format. If you want more formats or styles create more variables, or simply modify the above

When you want to print text out you have a slightly different syntax
instead of



which imo is a massive pain in the ass always having to set 'ink' if you use different coloured text (it's also very slow)

you write



the first benefit is the removal of the ink command, now text can be set on an individual line by line basis without having to worry about resetting it. This also applies to the styling and size of the font, it's on a per line basis, not globally set

So the above code will print out "testing" in the verdana bold style at 12pt font. If you wanted a larger pt size, say 18, put in Verdana(18)

Simple enough?

The replacement for 'center text' is

Giku_
14
Years of Service
User Offline
Joined: 14th Jan 2012
Location: The World
Posted: 18th Jan 2012 20:48
Thanks for your help, luckly we have solved it in another way. We are waiting answers for other questions!
BMacZero
20
Years of Service
User Offline
Joined: 30th Dec 2005
Location: E:/ NA / USA
Posted: 19th Jan 2012 03:01
In your second question, do you mean that you want to move a sprite smoothly but in a framerate-independent fashion? In that case, you should store the velocity you want the sprite to move in pixel per second. Use comparisons with the timer command to measure how long it's been since the last time you moved the sprite, then move the sprite pixelspersecond * timerdifference / (1000 + 0.0).

For your third question, the term you want is pixel perfect collision. DBP doesn't support it natively, but if you do a search you'll find lots of options on the Code Snippets board to do it.

Giku_
14
Years of Service
User Offline
Joined: 14th Jan 2012
Location: The World
Posted: 19th Jan 2012 11:20
Thank you very much BMacZero (And just a little OT, you are very talented, i just saw your website, keep up the goodwork! )

What we need to do with timer is basically:
Move a sprite on the x axis until x reaches a deafault value, but with a smooth movement. So every 0.1 sec (for example) the sprite x will be increased by 0.55 until mmm...x = desktopwidht()/2.
But unfortunately when we use a command like this the game freezes.

any ideas?

For Q3) I will searh thanks.
BMacZero
20
Years of Service
User Offline
Joined: 30th Dec 2005
Location: E:/ NA / USA
Posted: 19th Jan 2012 18:30
Ah, I actually looked at your code this time and I see the problem. It's that while loop. As long as the sprite background offset is less than 500, the game won't leave that loop. It will just keep moving the sprite without doing anything else (like drawing it) until it's done. Try replacing while-endwhile with if-endif.

And thanks .

Giku_
14
Years of Service
User Offline
Joined: 14th Jan 2012
Location: The World
Posted: 19th Jan 2012 21:17
Thank you for your help. I will try your solution.
And what can you say to ma about scaling?

We are developing it in 1920x1080p but on other resolution it came out too big, is there a command to reduce resolution and objects scale toghether?
BMacZero
20
Years of Service
User Offline
Joined: 30th Dec 2005
Location: E:/ NA / USA
Posted: 20th Jan 2012 03:52
As far as I know there is no easy way to support multiple resolutions with 2D and sprites, unfortunately. 3D will automatically draw to whatever resolution you're using, but you'll have to account for smaller resolutions manually, probably by using size sprite or scale sprite on everything.

Burning Feet Man
18
Years of Service
User Offline
Joined: 4th Jan 2008
Location: Sydney, Australia
Posted: 20th Jan 2012 05:33
Hey Millenium7, I hadn't really used a2D text commands until after reading your post. They work like a treat!

Cheers,
BFM

Help build an online DarkBASIC Professional help archive.
DarkBasic Help Wikia
=PRoF=
23
Years of Service
User Offline
Joined: 17th Mar 2003
Location: Milton Keynes, UK
Posted: 20th Jan 2012 10:19 Edited at: 20th Jan 2012 10:26
@Giku_:
With scaling, I have found the best way to go about it is to draw all your 2D stuff your chosen resolution and then when displaying it work out what percentage the actual display height is and find out what percentage of the 2D resolution (The resolution you drew the 2D stuff in). This value I call the "ratio#".

You can then scale your sprites and text using this figure.

e.g Sprites drawn at a resolution of 1280 x 960, but displayed on a 640 x 480 would have a ratio# of 50% (or 0.5, but u get the idea), so the sprites get scaled by 50% using the scale sprite command.

Text which would be drawn at size 48 on the full size, would be drawn in 24 size on the 640 x 480 screen, so just change the text size to the new value.

I find it best to use the screen height rather than the screen width to make it easier to work with all standard and widescreen variants.

Hope that helps.

>Edit<
Reworded a couple of bits to clarify what I'm trying to say

>Edit2<
Y Size?? lol, clearly not enough Tea has been drunk this morning, I meant Height of course. lol

Giku_
14
Years of Service
User Offline
Joined: 14th Jan 2012
Location: The World
Posted: 20th Jan 2012 13:20
@=PRoF=
It is exactly what i am doing. But i need to fix 2D objects position too. I'm right?

Because i can scale them almost perfectly but the position it's the same, so i think i must find a mathematical model to apply to this situation, right?
=PRoF=
23
Years of Service
User Offline
Joined: 17th Mar 2003
Location: Milton Keynes, UK
Posted: 20th Jan 2012 14:33 Edited at: 20th Jan 2012 14:35
again, you scale the position by the ratio#. so a sprite at 100,100 at 1280 x 960 would be at 50,50 at 640 x 480, likewise for stuff on the right, a sprite positioned at screen width-100,0 would be at screen width-50 on the smaller resolution.

Millenium7
21
Years of Service
User Offline
Joined: 13th Dec 2004
Location:
Posted: 20th Jan 2012 17:04
and just to expand on what =PRoF= is saying. For the reason of keeping everything simple, it'd be best to write a function to handle all of this, instead of appending to all of your individual scale/position commands

Something along the lines of



this way you can replace 'paste sprite' with PosSprite and code the game as if it were made at 1920x1080, or whatever. And if someone chooses a different resolution well so be it, it'll position and scale sprites at the same relative position anyway
Giku_
14
Years of Service
User Offline
Joined: 14th Jan 2012
Location: The World
Posted: 22nd Jan 2012 13:53 Edited at: 22nd Jan 2012 14:11
Thanks for your tip, it helped a lot. But we have two issue.

The sprites don't spawn at the same x# position in every res and every res has a particolar value that we need to add to

to set the end of the level and so stopping the side scroll.
The strange thing is that value, hasn't any criterion.
For example
640x480


800x600


1024x768


1152x864


1280x720


1280x768


I got this number testing all the resolution, but they havent't a reasonal succession.

any helps?
Millenium7
21
Years of Service
User Offline
Joined: 13th Dec 2004
Location:
Posted: 22nd Jan 2012 14:05
i'm not quite sure what you mean by the last post and your code examples

Why are you manually checking offsets? If you look at my example above, it'll resize the sprites anyway so a 200x200 sprite at 1280x960 will be 100x100 at 640x480. And if it were positioned at 800x500 will then be positioned at 400x250

Everything relating to a sprites size/position in any way should be checked with your own user written function that accomodates resolution changes. So you don't end up manually appending anything, and it'll automatically handle any and all resolutions i.e. 1172x1021 will still be compatible
Giku_
14
Years of Service
User Offline
Joined: 14th Jan 2012
Location: The World
Posted: 22nd Jan 2012 23:27
Mate we made a video to clarify the situation:

http://youtu.be/Qe0lxwmo7lk

In the first test we can see the correct position of the box object.
In the second test we can see how setting the 800x600 resolution, the box is in a different position.
In the third video we can see how the level finishes too early insted of the fourth test (the one with the "non-reasonal succession value") where it works perfectly.

All the sprites are setted up and scaled as you made above.

Don't care about the square corners on the idle animation (still incomplete, we have also all new frames for that) we use it to mesure some distances.
Millenium7
21
Years of Service
User Offline
Joined: 13th Dec 2004
Location:
Posted: 23rd Jan 2012 03:08
ok I see your problem, but again you need to write a custom function. From the code's point of view everything should be in a percentage, not a fixed value. If you use my example above you should be able to figure something out. Your level boundaries can be specified with a fixed value, but must then be scaled accordingly and by a percentage.

Implementing it may be a little more difficult, depending on how you've written your code up to this point. But in the long run I think you'd be better off to start up a new project and play around with scaled percentages, get everything sorted there and get your theory down pat. Then go back and rewrite your code. Don't ever be thinking in pixel position, it needs to be percentage of screen/boundary/sprite/whatever

Login to post a reply

Server time is: 2026-07-09 20:54:31
Your offset time is: 2026-07-09 20:54:31