You are not logged in or registered. Please login or register to use the full functionality of this board...
SIGN IN Join Our Community For FREE


Stupid question...
08-20-2017, 05:45 AM
Post: #1
 (Print Post)
Stupid question...
I know, "How basic can a question get?", and it sounds so stupid asking it...

Can some please, as simple as possible, demonstrate how to display sprites that are stored on disc?

Again. I am sorry for wasting your time on such a trivial problem.

J

May your journey be free of incident.

Live long and prosper.
Find all posts by this user
Like Post
08-20-2017, 08:58 AM (This post was last modified: 08-20-2017 09:09 AM by bplus.)
Post: #2
 (Print Post)
RE: Stupid question...
Hi Johnno, 

I keep referring you to the Wiki here (see screen shots (I had to split 1 into 2)):
http://www.qb64.net/wiki/index.php/Keywo...-_By_usage

Do you have this bookmarked on your Browser yet? (And you can download a pdf.)

To me, whenever I have a "stupid" question this is where I start (or should).
This would give the layout of the land - the keywords used in the area of our question.
Learn the lingo so when someone starts explaining something you will know 10% of what they are talking about.

There is often a very good and very simple example located right in the Wiki Help.
I found one recently when checking into screen scrolling for scrolling a list!

Of course, you need someone like Walter to run down the keywords and say what you need what for... ;-))
(He recently did an excellent job with Sound, unfortunately it was in the FreeBasic section of the forum. I will link it to where you posted your question on sound. What a guy! I am.)

Now the next thing we need are a few Simple examples. Ones that don't demo 10 different things unrelated to subject.
If the demo also had self documenting variable names and just the right comments in just the right places... oh wait, I must be thinking of heaven.


Attached File(s) Image(s)
       

B += _
Find all posts by this user
Like Post
08-20-2017, 07:44 PM
Post: #3
 (Print Post)
RE: Stupid question...
You are absolutely correct. I should have gone to the wiki first. You are obviously detecting a 'pattern of behaviour' in my question asking. One day I may actually remember that I have asked these types of question before. *sigh* Thank you for reminding me and thank you for the information. Much appreciated.

ps: My dream is to work my way up to 10%.... My mind is like a sponge. It absorbs 100% of whatever information it is exposed to... My problem is recall... No mater how hard I squeeze the sponge, I'm lucky to get just a few drops... *sigh*  My apologies if I have caused you any frustration.

May your journey be free of incident.

Live long and prosper.
Find all posts by this user
Like Post
08-20-2017, 10:01 PM (This post was last modified: 08-21-2017 03:37 PM by Waltersmind.)
Post: #4
 (Print Post)
RE: Stupid question...
@bplus

Thanks Mark, and your are correct. I can help with the QB64 words if one needs help.

@johnno56

First of all, in my opinion, the only time I consider a question as being stupid is when the asker already knows the answer and is asking for the simple goal of being irritating.

Never apologize for wasting any of our time here. At least mine any way. I am here to help as much as I can, and hopefully others are to.

Now for the good stuff.

The first thing you need to do in QB64 is load the image you want to draw onto the screen, assuming you want to draw the entire image as a whole. You do this with:

ImageHandle& = _LOADIMAGE ("ImageName")

This will load the the desired image from disk and store it in memory. Image file types supported are: BMP, JPG, PNG, GIF, PNM, XPM, XCF, PCX, TIF, LBM, and TGA.

The variable that stores the image handle must be a signed LONG.

The _LOADIMAGE has a second parameter, but it is used to tell QB64 if the loaded image will be a software image or a hardware image, which isn't important in this topic at the moment as QB64 defaults the loaded image as a software image. Here is an example of its usage:

ImageHandle1& = _LOADIMAGE("RGB-Sub-Pixel-Color-Wheel-MAIN-WHEEL.png")

It is as easy as that.

Now for the fun part, drawing the image to screen. The following explanations and examples are assuming you are using the 32-bit screen modes (_NEWIMAGE(Width, Height, 32)). There are three ways to do it in QB64:

  1. The old BASIC way by using GET to load the image into a predefined array and then PUT to draw the array image on to the screen. This is a very archaic way and is no longer used in modern times, unless you want to use it for a couple of tricks it offers, which is beyond the scope of this topic at the moment.
  2. The easy way: Using _PUTIMAGE to draw the image to screen, which I will explain in a moment as it is a little detailed.
  3. Finally the more complex way: Using _MAPTRIANGLE, which I will not discuss for the sake of simplicity.


The easy way, by using the _PUTIMAGE, is quick and simple, and offers the ability to scale (or stretch) your image. Now this command can be written in many different forms to allow for various and different effects.

_PUTIMAGE

While this way is a bit confusing, it would help to know that what is going here behind the scenes. Since you can create and load many images in QB64, QB64 keeps track of the destination image (the one that gets drawn to) and a source image. The really cool thing is, you can redirect the source and destination images in QB64 with the _SOURCE and _DEST commands like:

_SOURCE ImageHandle&

and...

_DEST ImageHandle&

This is very useful when creating drawings on the screen procedurally. For example, look at my "Waltersmind's - Hauntingly Dreamy Clock with Swinging Pendulum - Version #3" demo located at http://www.thejoyfulprogrammer.com/qb64/...=16&pid=37, every part of the clock, as well as the filled circles being drawn behind the clock in real time, are draw in images created with the _NEWIMAGE(Width, Height) command. I simply created the new images, set the _DEST to point to a particular offscreen image and drew what I needed, and continued to process until all parts were drawn. Then I set the _DEST back to my main screen and started drawing all the images on top of each other to create the animated effect I wanted.

So if you use the simplest form of _PUTIMAGE, be sure to set at least the _SRC image to the image you wish to draw on the screen.

If you don't want to keep messing with the _SRC and _DEST commands, _PUTIMAGE has that covered. To do the same effect as the most basic form of the statement (fit source image to the entire destination image), you can define the source and destination images in the command like:

_PUTIMAGE , SourceImageHandle&, DestinationImageHandle&

Now, if you wanted to draw the source image at actual size, as well as defined location and not fit it to the destination image, you would use

_PUTIMAGE (DestinationX, DestinationY), SourceImageHandle&, DestimationImageHandle&

Since QB64 already defines the destination image (the SCREEN), you can shorten the previous command to:

_PUTIMAGE (DestinationX, DestinationY), SourceImageHandle&

I would like to note that QB64 allows you to draw the full-size image, or any stretched sized image, at any location on screen, slightly off screen where it is clipped, or completely off screen. This means you can use negative coordinates, or those that would draw parts or all the image off the screen. Here are some examples based on the previous examples in this post:

_PUTIMAGE (0, 0), ImageHandle1&
_PUTIMAGE (-100, 0), ImageHandle1&
_PUTIMAGE (-100, -100), ImageHandle1&
_PUTIMAGE (700, -100), ImageHandle1&

Now, let's say wanted to draw the source image to the destination image at a scaled size, you would use this form of the command:

_PUTIMAGE (DestXStart, DestYStart)-(DestXEnd, DestYEnd), SourceImageHandle&

or

_PUTIMAGE (DestXStart, DestYStart)-(DestXEnd, DestYEnd), SourceImageHandle&, DestinationImageHandle&

While there are other ways of using the _PUTIMAGE, I want to show you two more ways that are very important when dealing with sprite sheets.

Let's say you are creating an RPG game and you have a sprite sheet that has all the frames of a walking characters moving in a given direction. You can have a large sprite sheet with that same character walking in eight directions, but the concept is the same.

What we need to do is cut out a small section of the overall source image and display it on the screen at a given location. It could easily be the first frame of the sprite walking, but that is your decision to make.

_PUTIMAGE (DestX, DestY), SourceImageHandle&, DestinationImageHandle&, (SrcXStart, SrcYStart)-(SrcXEnd, SrcYEnd)

But let's say your character, or object needs to shrink to nothing like it is being sucked into a time vortex, or even a genie's lamp. When can manage that simple trick with:

_PUTIMAGE (DestXStart, DestYStart)-(DestXEnd, DestYEnd), SourceImageHandle&, DestintationImageHandle&, (SrcXStart, SrcYStart)-(SrcXEnd, SrcYEnd)

While there are other syntax's of _PUTIMAGE in QB64, I will not discuss them here so you can discover them on your own. I have showed so powerful features of _PUTIMAGE, but I will not leave you empty handed. Attached you will find a *.ZIP file that contains a demo which uses _PUTIMAGE in the various ways I mentioned in this post. Download it, check it out, learn something, and have fun.

I have added a background image, I title image, and a UFO image. The first one I designed for Zombie Adventures near the end of when I was working on it. The second one is the title image I used in it (slightly modified). The third is a UFO image I created for a couple of hardware accelerated demos I posted on this forum in the past.

Here are some screenshots:

               


Walter Whitman
The Joyful Programmer


Attached File(s)
.zip  TJP - PUTIMAGE TEST v1.zip (Size: 86.24 KB / Downloads: 3)

My goal is to bring joy, excitement, fun and education to all computer programming hobbyists, tinkerers, and amateurs. I also enjoy helping and working with those who aspire at becoming masters of their craft.
Find all posts by this user
Like Post
08-21-2017, 02:11 PM
Post: #5
 (Print Post)
RE: Stupid question...
"We aren't in Kansas anymore."

Yeah, when I scanned the list of keywords, I found _LOADIMAGE and _PUTIMAGE to be the most likely need. Then I looked at _PUTIMAGE and have to quote Dorothy on here arrival to Oz.

"Destination? please..." to quote my ship's autopilot.

B += _
Find all posts by this user
Like Post
08-21-2017, 04:55 PM
Post: #6
 (Print Post)
RE: Stupid question...
Thanks guys. Used

handle& = _loadimage()
_putimage(x,y),handle&

Worked like a charm...

May your journey be free of incident.

Live long and prosper.
Find all posts by this user
Like Post
08-21-2017, 11:39 PM
Post: #7
 (Print Post)
RE: Stupid question...
Johnno56,

You are very welcome. Let me know if you need to know anything else.


Walter Whitman
The Joyful Programmer

My goal is to bring joy, excitement, fun and education to all computer programming hobbyists, tinkerers, and amateurs. I also enjoy helping and working with those who aspire at becoming masters of their craft.
Find all posts by this user
Like Post



Forum Jump:


User(s) browsing this thread: 1 Guest(s)




QB64 Member Project - Martin Fractals version one
QB64 Member Project - Blokus
QB64 Member Project - Color Rotating Text
QB64 Member Project - Kings Court
QB64 Member Project - Spiro Roses
QB64 Member Project - Martin Fractals version three
QB64 Member Project - Score 4
QB64 Member Project - Full Color LED Sign
QB64 Member Project - Bowditch curve
QB64 Member Project - Color Triangles
QB64 Member Project - Spinning Color Wheel
QB64 Member Project - Connect Four
QB64 Member Project - Kobolts Monopoly
QB64 Member Project - Red Scrolling LED Sign
QB64 Member Project - Qubic
QB64 Member Project - ARB Checkers
QB64 Member Project - Pivot version two
QB64 Member Project - Point Blank
QB64 Member Project - Rubix's Magic
QB64 Member Project - Algeria Weather
QB64 Member Project - RGB Color Wheel
QB64 Member Project - Martin Fractals version four
QB64 Member Project - Splatter
QB64 Member Project - Exit
QB64 Member Project - Othello
QB64 Member Project - Inside Moves
QB64 Member Project - Rotating Background
QB64 Member Project - Domain
QB64 Member Project - MAPTRIANGLE
QB64 Member Project - Foursight
QB64 Member Project - Pivet version one
QB64 Member Project - OpenGL Triangles
QB64 Member Project - Kings Valley verion one
QB64 Member Project - Dakapo
QB64 Member Project - Overboard
QB64 Member Project - Touche
QB64 Member Project - Line Thickness
QB64 Member Project - Kings Vallery version two
QB64 Member Project - Isolation
QB64 Member Project - Quarto
QB64 Member Project - Swirl
QB64 Member Project - Dreamy Clock
QB64 Member Project - Sabotage
QB64 Member Project - 9 Board
QB64 Member Project - Basic Dithering
QB64 Member Project - Amazon
QB64 Member Project - Input
QB64 Member Project - Martin Fractals version two
QB64 Member Project - STxAxTIC 3D World