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 / Is it possible to draw a sprite behind an image?

Author
Message
Da_Rhyno
15
Years of Service
User Offline
Joined: 25th May 2011
Location:
Posted: 27th Sep 2011 06:05
I'm currently making a map editor for my game, and I have an overlay image, which is the editor window itself with a pink (that is, RGB(255, 0, 255)) window in the center (the "canvas area"), which I set the COLOR KEY for so it would be transparent.

I can select images from the list of images I load up fine, but when I try to click on the canvas area (which is where you place pieces of the map), nothing is drawn there, when a sprite should appear for the map piece that was placed.

Does anyone have any ideas what could be going wrong here?

I included the project as a download in case anyone wants to take a gander at it... thanks!
Pincho Paxton
23
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 27th Sep 2011 11:50 Edited at: 27th Sep 2011 11:51
The editor window is an image. The map pieces work best as sprites, and then maybe paste them to the canvas area. Then to delete them you will need a blank tile square pasted over the top of any other pasted images. It should work fine, I've done that before.

Webber
15
Years of Service
User Offline
Joined: 27th May 2011
Location:
Posted: 27th Sep 2011 18:06
You need to create an array for the placement of the sprites.
And you can save the array into a text file in order to see if it is saving correctly.

I suggest a one dimensional array with string data consisting of
Image Number, X-Position, Y-Position, and any other data you need.
Then you need a way of translating the strings into numerical data, and then into drawing your level using the data, and pasting sprites.

Or you can create multiple one dimensional arrays with numerical data in them. That should work too, maybe even better.

The reason I suggest using one dimensional arrays, is because multidimensional arrays can be confusing, and are hard to keep organized, especially when your data is constantly changing.

To delete them you can simply erase the specific data in your array(s).

All of your sprite images should be pasted to the screen using the data in your array(s).

One more thing, you should make it so the data is only drawn when the user lets go of the mouse, in order to avoid creating multiple images in the same spot.

Good luck with your project.

I like games, and stuff.
Da_Rhyno
15
Years of Service
User Offline
Joined: 25th May 2011
Location:
Posted: 27th Sep 2011 18:39 Edited at: 27th Sep 2011 19:05
Well, guys... that's kind of what I'm doing... But for some reason the sprites aren't showing up on the canvas when I click, though the particular images are being selected.

EDIT: I tried changing the background image to a SPRITE and it's not even being drawn, so I put a SYNC in the "Normal_Window()" function, and it drew while there was another sync in the main loop, however it flashed maniacally. I took the SYNC out of the main loop, and it didn't draw the SPRITE at all...
Webber
15
Years of Service
User Offline
Joined: 27th May 2011
Location:
Posted: 27th Sep 2011 22:08
It is possible that the background is covering up your image.
When I use sprites I always turn the backsave off, and just paste them to the screen. It runs really fast that way.

Try this in your Draw_Canvas function



I like games, and stuff.
Da_Rhyno
15
Years of Service
User Offline
Joined: 25th May 2011
Location:
Posted: 27th Sep 2011 22:26 Edited at: 27th Sep 2011 22:30
I figured out that it didn't like the CLS in the Normal_Window() routine with the "DRAW SPRITES FIRST" command at the beginning... That kept the sprites covered up completely...

But it's still not even making sprites when I try clicking them to the canvas.

EDIT: Nvm... it wasn't drawing the sprites again unless I set the background as a sprite itself. The background image blocks everything.
Da_Rhyno
15
Years of Service
User Offline
Joined: 25th May 2011
Location:
Posted: 27th Sep 2011 22:57
Thanks for that help Webber! That did the trick!

I still don't understand what the backsave does and why I have to paste it for it to draw?
Webber
15
Years of Service
User Offline
Joined: 27th May 2011
Location:
Posted: 28th Sep 2011 00:10
The backsave makes it so the computer doesn't automatically handle
clearing the screen, and since you have an image in the background
clearing the screen, setting the backsave to 0 makes the program run faster.

Pasting your sprites, makes the images always show up in front.
And if you want your program to run even faster, since your pasting
the sprites you only need one sprite per image.

I like games, and stuff.
Da_Rhyno
15
Years of Service
User Offline
Joined: 25th May 2011
Location:
Posted: 28th Sep 2011 00:31
Thanks! There's only one object of concern to me now: Since the "PASTE SPRITE" will always make it show up in front, what happens when I use the keyboard keys to scroll along my canvas area? Will the pasted sprites show up in front of the editor area?
Da_Rhyno
15
Years of Service
User Offline
Joined: 25th May 2011
Location:
Posted: 28th Sep 2011 05:01 Edited at: 28th Sep 2011 05:08
Hmmm... For some reason the Text_Prompt() isn't working, it's driving me nuts...

EDIT: Also, how can I check to see if someone let go of the mouse button?
Webber
15
Years of Service
User Offline
Joined: 27th May 2011
Location:
Posted: 28th Sep 2011 07:51
The sprites will probably show up over the editor.
There are two solutions that I can think of that will fix this.
As long as the transparency effect is working on your editor image, just paste the editor image last.
Or you can make the entire screen the editor, and make buttons, gizmos, display settings, what not, anything for your editing tools, only appear/disappear when you press a certain button, possibly the right mouse button.

Basically, only the last sprite/image pasted will show up on top.



The text prompt was working before.
What's not working about it?
It's just not good enough, I knew it.
If I get some time, I'll make some code to replace the input command, I think I can even make it so you can cut and paste text into it.


Check if someone let go of the mouse button



I like games, and stuff.
Da_Rhyno
15
Years of Service
User Offline
Joined: 25th May 2011
Location:
Posted: 28th Sep 2011 08:01
Thanks! I figured out another way a little while ago that works OK:



As far as the input is concerned... It doesn't like me much, to say the least. I made another thread for it to keep subjects separated: http://forum.thegamecreators.com/?m=forum_view&t=189824&b=7
Webber
15
Years of Service
User Offline
Joined: 27th May 2011
Location:
Posted: 28th Sep 2011 08:08
I'm still not sure what is wrong with your Text_Prompt, but I got that better then input function working. There is one problem with cutting and pasting text though, if you paste something with multiple lines of text, it will create multiple lines of text.
So don't copy and paste anything with more then one line of text.

I might be able to fix it with ASCII characters, but I don't think it's that important.



I like games, and stuff.
Da_Rhyno
15
Years of Service
User Offline
Joined: 25th May 2011
Location:
Posted: 28th Sep 2011 08:38 Edited at: 28th Sep 2011 08:39
Well, I didn't cut and paste anything. And you mean it worked for you? Like it actually pulled up a file successfully?

Also, thanks for the code! I'll implement it tomorrow when I wake up.
Pincho Paxton
23
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 28th Sep 2011 18:02 Edited at: 28th Sep 2011 18:03
Don't use wait on the mouse click. Do this...



IF mouseclick() = 1
Repeat
Until mouseclick() = 0
// Do stuff

ENDIF

Webber
15
Years of Service
User Offline
Joined: 27th May 2011
Location:
Posted: 28th Sep 2011 20:04
I'm gonna have to agree with Pincho Paxton on that one, using wait can cause problems, and don't think that the sleep command is better, it does the same thing.

For example, if you hold onto the mouse too long, it will draw extra sprites that you don't need.
And if you click more then once within your wait time period, it won't draw your other sprites.

The code I showed you, does not freeze the program up at all, for example.
If you clicked on the mouse, and then you move the mouse outside of the editor, you have the ability to stop the program from drawing over there.

If you decide to use Pincho Paxtons code I suggest that you put the //Do stuff before the repeat until loop.

That way it will place your new sprite as soon as the mouse is clicked so you can avoid placing your sprites in unusual places.

I like games, and stuff.
Webber
15
Years of Service
User Offline
Joined: 27th May 2011
Location:
Posted: 28th Sep 2011 21:06 Edited at: 28th Sep 2011 21:11
I fixed some glitches in the function, it works much better now.
Now if you want to load an image, just locate the image, right click it, then click on properties, Security, and cut and paste the Object name into the new input command.

Your images might not be loading because your just not spelling the file names correctly.



Don't tell anybody, but this is my first time ever actually using functions.

I like games, and stuff.
Da_Rhyno
15
Years of Service
User Offline
Joined: 25th May 2011
Location:
Posted: 29th Sep 2011 03:44 Edited at: 29th Sep 2011 05:00
I doublechecked the names, and the names were good. It's weird. Thanks guys! I'll fix my code.

EDIT: I tried the mouse code you supplied, Webber, it didn't register the "IF MouseClick() = 0 AND MouseClicked = 1" for some reason.
Webber
15
Years of Service
User Offline
Joined: 27th May 2011
Location:
Posted: 29th Sep 2011 18:39
Since your using functions you might have to declare MouseClicked as a global for it to work.

I like games, and stuff.
Da_Rhyno
15
Years of Service
User Offline
Joined: 25th May 2011
Location:
Posted: 29th Sep 2011 19:18
Okay, thanks! Will try that.

Login to post a reply

Server time is: 2026-07-11 04:30:39
Your offset time is: 2026-07-11 04:30:39