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

Author
Message
Mugen Wizardry
User Banned
Posted: 30th Nov 2010 20:40 Edited at: 30th Nov 2010 20:53
Hi all, I'm having a bit of a problem with boxes.

What I need to do is to be able to PERFECTLY center a box at ANY given size, and I also need to be able to control how thick the size of the box is.

I also need text to follow the box where ever it goes

Thanks for all of the help!

CHECK OUT SOME MUSIC FROM MY NEW TECHNO CD! TECHNOKINESIS
http://www.youtube.com/watch?v=4a8KedfgVv0
ALSO, CHECK OUT MY NEW TECHNO CD AT Amazon.com!
Indicium
18
Years of Service
User Offline
Joined: 26th May 2008
Location:
Posted: 30th Nov 2010 21:18
The object will be centered using position object assuming you haven't used any offset commands etc.

C0wbox
20
Years of Service
User Offline
Joined: 6th Jun 2006
Location: 0,50,-150
Posted: 30th Nov 2010 21:20 Edited at: 30th Nov 2010 21:21
@ Mugen Wizardry
Well lets address each problem as we go:

Quote: "center a box at ANY given size"

Lets say we're going to make a box which is 64x32 pixels.

And we want to centre it at the point BX,BY.

The code to do this would be:


If you want to change the size of the box then we can replace 64 and 32 with variables, SizeX and SizeY

The code would now look like this:


Quote: "control how thick the size of the box is"

To be able to control the dimensions of the box you can just change the variables SizeX and SizeY in the previous example. - The means of which you change these variables are up to you.

Quote: "I also need text to follow the box where ever it goes"

That's no harder than placing the box itself and the code would look something like this:


Now, you're going to have issues if you want to see that text because at the moment the box and the text are both being drawn as white so you won't be able to tell one from the other. But again, the method of which you make your text and colour it is up to you.

@ Mad Nightmare - Just saw your post after I posted mine:
Well there's a good example of a bad description, we both got different ends of the same stick there.

TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 30th Nov 2010 21:42
Well, C0wbox should know

TheComet

C0wbox
20
Years of Service
User Offline
Joined: 6th Jun 2006
Location: 0,50,-150
Posted: 30th Nov 2010 22:02
!!! That was really bad, but it made me smile.

Mugen Wizardry
User Banned
Posted: 30th Nov 2010 23:00
Lol!

CHECK OUT SOME MUSIC FROM MY NEW TECHNO CD! TECHNOKINESIS
http://www.youtube.com/watch?v=4a8KedfgVv0
ALSO, CHECK OUT MY NEW TECHNO CD AT Amazon.com!
Mugen Wizardry
User Banned
Posted: 30th Nov 2010 23:42
I tried your code, cowbox. But could only position it correctly if it wasnt centered in the middle of the screen.

I need to be able to use both screen width()/2,screen height()/2, and any integer as well.

But I like what u have done so far! Thanks again for the help!

CHECK OUT SOME MUSIC FROM MY NEW TECHNO CD! TECHNOKINESIS
http://www.youtube.com/watch?v=4a8KedfgVv0
ALSO, CHECK OUT MY NEW TECHNO CD AT Amazon.com!
Madscientist
16
Years of Service
User Offline
Joined: 23rd Aug 2009
Location: Between a rock and a hard place
Posted: 1st Dec 2010 03:26 Edited at: 1st Dec 2010 03:26
Well simply factor that in by simple addition to what C0wbox said.


My computer surpasses all the technologies of the day. What computer do I have?

Mugen Wizardry
User Banned
Posted: 1st Dec 2010 06:19
While that works, I would like to be able to control that with a variable.

This currently only works with one OR the other.

Width=100 //I want to keep this
Height=100 //I want to keep this
BX=10 //I want to change this
BY=10 //I want to change this

Box BX-(Width/2),BY-(Height/2),BX+(Width/2),BY+(Height/2)

Thanks guys!

CHECK OUT SOME MUSIC FROM MY NEW TECHNO CD! TECHNOKINESIS
http://www.youtube.com/watch?v=4a8KedfgVv0
ALSO, CHECK OUT MY NEW TECHNO CD AT Amazon.com!
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 1st Dec 2010 11:55
Yes, that code is right, so what is it you are doing that is stopping it working for you?

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
Mugen Wizardry
User Banned
Posted: 1st Dec 2010 15:48
Well, say for instance when I position it at 10,10 and make it the size of 100,100. For some reason, it cuts off part of the box.

CHECK OUT SOME MUSIC FROM MY NEW TECHNO CD! TECHNOKINESIS
http://www.youtube.com/watch?v=4a8KedfgVv0
ALSO, CHECK OUT MY NEW TECHNO CD AT Amazon.com!
TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 1st Dec 2010 16:48
That's because almost half of the box is not on the screen. Your box's corner coordinates would be the same as:

box -40,-40,60,60

And anything less than 0 goes off the screen, so in reality, you will only see a 60x60 box in the top left corner.

TheComet

Mugen Wizardry
User Banned
Posted: 1st Dec 2010 17:47
But I didnt put it at -40,-40,60,60

i put it at 10,10,100,100

CHECK OUT SOME MUSIC FROM MY NEW TECHNO CD! TECHNOKINESIS
http://www.youtube.com/watch?v=4a8KedfgVv0
ALSO, CHECK OUT MY NEW TECHNO CD AT Amazon.com!
Indicium
18
Years of Service
User Offline
Joined: 26th May 2008
Location:
Posted: 1st Dec 2010 18:31
You code centers a box of size 100x100 at 10,10...

Mugen Wizardry
User Banned
Posted: 1st Dec 2010 18:37
What I need to be able to do is if I position it at 10, 10, it is X=10+the size x of the box, and y=10+the size y of the box so that no matter what, it doesnt go out of boundary lines

CHECK OUT SOME MUSIC FROM MY NEW TECHNO CD! TECHNOKINESIS
http://www.youtube.com/watch?v=4a8KedfgVv0
ALSO, CHECK OUT MY NEW TECHNO CD AT Amazon.com!
C0wbox
20
Years of Service
User Offline
Joined: 6th Jun 2006
Location: 0,50,-150
Posted: 1st Dec 2010 18:47 Edited at: 1st Dec 2010 18:50
@ Mugen Wizardry
This is sorta reaching the stage where we could do with some kind of example, because no one really knows what you're asking.

I mean I'd code what I'm looking for in a simple 2D example, but I spose if you can't code the simplified 2D example to show us, we can't grasp what you need help with to help you code a simplified 2D example and oh god paradox dilemma.

Mugen Wizardry
User Banned
Posted: 1st Dec 2010 19:30 Edited at: 1st Dec 2010 19:35
Here's an example



As you can clearly see, if you hold down either the W/A/S/D keys or the arrow keys, and move the box, the box CANNOT escape the borders.

I would like to be able to the same thing without the keys.

So for instance, if I were to set BX to screen width()/2, and BY to screen height()/2, and Width and Height to 100,100, no matter WHAT size I make it, it will still remain exactly in the middle. And if I were to position it at a given coordinate, it would position at that coordinate + the size to give me the exact coordinates of the box.

CHECK OUT SOME MUSIC FROM MY NEW TECHNO CD! TECHNOKINESIS
http://www.youtube.com/watch?v=4a8KedfgVv0
ALSO, CHECK OUT MY NEW TECHNO CD AT Amazon.com!
Madscientist
16
Years of Service
User Offline
Joined: 23rd Aug 2009
Location: Between a rock and a hard place
Posted: 1st Dec 2010 23:54 Edited at: 1st Dec 2010 23:55
Wait so do you want to position the box by its center or top left corner because i'm still confused.
Anyways, here's both.
Top Corner:

Center:

Is that what you want????

My computer surpasses all the technologies of the day. What computer do I have?

Neco
18
Years of Service
User Offline
Joined: 13th Jul 2008
Location: Waterloo, Wisconsin USA
Posted: 3rd Dec 2010 02:34 Edited at: 3rd Dec 2010 02:40
It sounds like you just need to code a logical test to verify the position of the box and that it is within bounds, if it is not, correct it at that point.


That being said...some of your descriptions are kind of confusing..

On the one hand you want to be able to center the box, anywhere on the screen.... what does that mean?

Are you saying, regardless of what X / Y position a box is set to when created, you want the program to center it in the game screen? If so you don't need to do anything complicated.. just use the width / height math to set the value of the boxes X / Y position.


It may help if you do a quick story-board in paint, with some colored boxes. 1 representing the game window, and another representing a box centering problem, step by step.. (This is what it is doing, step by step -- this is what I want it to do, step by step, etc)

Mugen Wizardry
User Banned
Posted: 3rd Dec 2010 03:11
Thanks, Madscientist!

CHECK OUT SOME MUSIC FROM MY NEW TECHNO CD! TECHNOKINESIS
http://www.youtube.com/watch?v=4a8KedfgVv0
ALSO, CHECK OUT MY NEW TECHNO CD AT Amazon.com!
Madscientist
16
Years of Service
User Offline
Joined: 23rd Aug 2009
Location: Between a rock and a hard place
Posted: 3rd Dec 2010 20:33
But which one did you want.

My computer surpasses all the technologies of the day. What computer do I have?

Login to post a reply

Server time is: 2026-07-21 13:38:47
Your offset time is: 2026-07-21 13:38:47