11-12-2013 08:42 AM
Hi all,
Being new to LabVIEW, I have been making a game to help me understand LabVIEW more. I have run into some issues, and am looking for some suggestions and/or help. I have a spaceship that moves and fires, but I cannot figure out how to fire the laser bullets that I have in picture controls. I would like to move them from off screen to the location of the ship, and then move them up one at a time until they hit something or are off screen. The problem I run into is getting the ship location out of the main loop. I have attached my files, but the pictures and sound may have to be reentered, as I do not know how to get them permanently in the code. Any suggestions on that topic are very welcome as well. Thanks in advance!
Kevin
11-12-2013 09:04 AM - edited 11-12-2013 09:05 AM
Kevin,
first of all, the good old "learn by play" approach. Nice to see it!
To give you some feedback on the overall application:
Regarding your original question, you might want to refer to Asteroids for some feed for thoughts.
Have fun,
Norbert
11-12-2013 09:27 AM - edited 11-12-2013 09:29 AM
Thanks for the feedback Norbert! I will have to look into those points more, but just reading through them they seemed like it would help my techniques. When you say keep an internal counter, how would I go about that? Just glancing at the asteroids game, I noticed they are using a picture control. Would there be a way to incorporate my textures and background in a picture control?
Thanks again,
Kevin
11-12-2013 09:30 AM
Kevin,
in general, yes. But it would be a load of work.
My goal in pointing you to asteroids is more the "administrative part" like positionhandling of the space ship, shots and targets.....
Please note that the Asteroid implementation is quite old, so many things are not "up to date". But it gives a deep inside on the underlaying algorithms required for that game and THAT is what you are looking for.
Norbert
11-12-2013 12:22 PM
When you say keep an internal counter, how would I go about that? Also I'm having trouble with the relative path not being able to find the files. The State Machine cleaned up the code quite a bit, and the project is forcing me to become much more organized. Could you link some more info or explain it yourself about the 2D Picture control textures? I don't really mind more work, as it will probably run faster and smoother than moving multiple picture rings around. If you know of anyway to increase the speed of the program or allow firing and moving at the same time that would be so helpful.
Bear with me,
Kevin
11-13-2013 03:16 AM
Kevin,
you are already familiar with shift registers. So add another one for the "number of shots fired" and deal with that (increase for each shot, reset to 0 during reload). Updating the element "Shots left" is also connected to this value as well.
Using the 2D Picture control requires you to create a complete image for each update, for instance by using "Draw Flattened Pixmap". As you can see, this VI requires a complete BMP to be passed into it. So essentially, your whole scene has to be merged to a single BMP, flattened and drawn to the picture indicator.
Moving picture rings around is a very simple, elegant way to remove the burden of computing a complete image for each update containing the ship, shots and targets.
On the other hand, if you have many shots displayed concurrently, creating a single bitmap repeatedly might be less effort than moving around 20+ picture rings..........
Norbert
11-13-2013 08:08 AM
Many years ago, I wrote a similar app for LabVIEW 6i (aka 6.0) using a knob control for the ship and other, smaller, controls for the asteroids and projectiles. It bogged down when I got to too many controls at once. I was using this on a 400MHz Celeron processor. So, I would definitely recommend you use a single picture control for your graphics. You can regenerate it at each frame with the updated positions of things. You can pregenerate your background as the starting point.
I was curious and opened the VI in LabVIEW 2013. It did not work. The reason was that the event structure was introduced in LabVIEW 6.1, so I used an old DLL-based keyboard query. The DLL code was written for Windows 98 and Windows 2000 and did not work correctly on Windows 7. It could be easily upgraded to an event structure, so I have posted it below for your amusement.
Repeat kudos for the learn-by-doing approach. It works well.
11-15-2013 03:23 PM
I see how a single picture box can help me with this, but I am still having issues with the path. Every time I try according to what I found online, LabVIEW cannot find the file. Also I was wondering if anyone could give me suggestions on unflattening my png file without losing my transparency. Everything I have found suggests that this is impossible or very difficult and involves alpha channels. I understand what alpha channels are, and I understand that LabVIEW is removing them when the picture data goes through the unflatten image vi. Any help would be greatly appreciated, and thanks for the help so far!
-Kevin
11-15-2013 03:55 PM
Hi kstrauch,
I put (A slightly different version of) the attached VI together a while ago to solve a similar problem, basically it just strips out the alpha channel from a png and then reinserts it after whatever modifications you need to do. You should be able to probe the image data in the block diagram to see what it looks like at each stage.
It's not the most elegant solution, and there are more than a few things that this won't work for- this was designed to preserve the border transparency of a template image on top of which some text and other images were overlaid and it won't work if you're trying to overlay transparencies or reshape the image, but might be enough to get you started or at least give you an idea of what operations are required to modify the alpha channel.
Hope that helps!
11-18-2013 08:03 AM
Thanks for the response 0utlaw, it helped me to understand what is going on with the alpha. However, for my application, I need the alpha still on, but the image unflattened. Is this possible? Another solution I can think of is to move the flattened image, but there is no cluster for location when drawing a flattened image. This solution seems to be easier, but I was wondering if this would even be possible.