Author Topic: Help with a pcopy question  (Read 4150 times)

0 Members and 1 Guest are viewing this topic.

Offline robpugh0829

  • Newbie
  • Posts: 19
    • View Profile
Help with a pcopy question
« on: December 17, 2018, 11:01:28 am »
Hey all,
I'm not usually a game programmer, but I'm taking the plunge into doing some stuff with graphics and games type stuff, but I ran into a problem that I just can't seem to work out. Let's say I have 5 different sprites(png images) on the page and when one of them is clicked, it disappears. I can do everything up to the disappearing part. Actually, I can make it disappear, but they all disappear. I'm using pcopy _display, 1 then pcopy 1, _display (probably incorrectly). Do I need to draw them on seperate screens and then put them, which I did also try that too but again can't make them disappear correctly. If somebody could please give insight, I would appreciate it.

Thanks so much!

Have a great day all!

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: Help with a pcopy question
« Reply #1 on: December 17, 2018, 01:57:33 pm »
Hi robpugh0829
wellcome

about your question I have understood this:
5 sprites (PNG files) to put on the screen visible, clicking on an image it must disappear

you are using
Code: QB64: [Select]
  1. .....
  2. .....
  3.  

reading wiki  http://qb64.org/wiki/PCOPY
The PCOPY statement copies one source screen page to a destination page in memory
(run examples to see details of its behaviour9

so it seems good to copy a whole panel/canvas onto panel/canvas used as screen visible
and so if you use many different panels/canvases you overwrite each with the next one that you Pcopy on.

If you need to draw the sprites on separate screens and then put together onto visible screen you can use _PUTIMAGE

http://qb64.org/wiki/PUTIMAGE
together with _DEST and _SOURCE as showed in examples of _PUTIMAGE

I think this can solve your issue.

Waiting your feedback or more details....
Good Coding
Programming isn't difficult, only it's  consuming time and coffee

Offline robpugh0829

  • Newbie
  • Posts: 19
    • View Profile
Re: Help with a pcopy question
« Reply #2 on: December 17, 2018, 02:07:31 pm »
I've been messing with pcopy and I do make copies of the visible screen and then the other screens I make, but then when I go to make one disappear, I make them all disappear and I can't seem to figure out what I am doing wrong.

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: Help with a pcopy question
« Reply #3 on: December 17, 2018, 03:59:54 pm »
Hi
1. take the image from this link

https://www.google.it/imgres?imgurl=https%3A%2F%2Fhackadaycom.files.wordpress.com%2F2018%2F02%2Fqb64_logo1.png%3Fw%3D200&imgrefurl=https%3A%2F%2Fhackaday.com%2F2018%2F02%2F22%2Fquickbasic-lives-on-with-qb64%2F&docid=6AhQFaY-QXxeXM&tbnid=HTjLzwKaTJiZ9M%3A&vet=10ahUKEwiop6K70qffAhWNSxUIHQpwBUwQMwhtKCIwIg..i&w=200&h=180&client=opera&bih=627&biw=1326&q=qb64&ved=0ahUKEwiop6K70qffAhWNSxUIHQpwBUwQMwhtKCIwIg&iact=mrc&uact=8

 right click and save image as qb64_logo1.png in QB64 folder

2. open IDE QB64 and paste this code into it

Code: QB64: [Select]
  1. SCREEN _NEWIMAGE(800, 600, 32)
  2. DIM image AS LONG, ShowImage(1 TO 3) AS INTEGER
  3. image = _LOADIMAGE("qb64_logo1.png", 32)
  4. IF image > -1 THEN
  5.     PRINT "No image found"
  6.     ShowImage(1) = -1
  7.     ShowImage(2) = -1
  8.     ShowImage(3) = -1
  9.     WHILE 1
  10.         CLS , _RGB(33, 211, 61)
  11.         _PRINTSTRING (10, 400), "Press rightclick to QUIT"
  12.         IF ShowImage(1) = -1 THEN _PUTIMAGE (1, 1)-(40, 40), image ELSE CIRCLE (20, 20), 20, _RGB(255, 0, 0)
  13.         IF ShowImage(2) = -1 THEN _PUTIMAGE (60, 60)-(100, 100), image ELSE CIRCLE (80, 80), 20, _RGB(255, 0, 0)
  14.         IF ShowImage(3) = -1 THEN _PUTIMAGE (1, 160)-(40, 200), image ELSE CIRCLE (20, 180), 20, _RGB(255, 0, 0)
  15.         WHILE _MOUSEINPUT = -1
  16.             IF _MOUSEBUTTON(1) THEN switchImage
  17.             IF _MOUSEBUTTON(2) THEN END
  18.         WEND
  19.         _LIMIT 10
  20.     WEND
  21.  
  22. SUB switchImage
  23.     SHARED ShowImage() AS INTEGER
  24.         CASE 1 TO 40
  25.             SELECT CASE _MOUSEY
  26.                 CASE 1 TO 40
  27.                     ' first image on the topleft
  28.                     IF ShowImage(1) = -1 THEN ShowImage(1) = 0 ELSE ShowImage(1) = -1
  29.                 CASE 160 TO 200
  30.                     ' third image on the bottom left
  31.                     IF ShowImage(3) = -1 THEN ShowImage(3) = 0 ELSE ShowImage(3) = -1
  32.             END SELECT
  33.         CASE 60 TO 100
  34.             SELECT CASE _MOUSEY
  35.                 CASE 60 TO 100
  36.                     ' second image in the middle at right
  37.                     IF ShowImage(2) = -1 THEN ShowImage(2) = 0 ELSE ShowImage(2) = -1
  38.             END SELECT
  39.     END SELECT
  40.  
  41.  

3. press F5 and see if it is what you are searching

if so you don't need to use PCOPY
Programming isn't difficult, only it's  consuming time and coffee

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Help with a pcopy question
« Reply #4 on: December 17, 2018, 06:07:04 pm »
Maybe this help. This source use CLS for not-active images, but better is using _PUTIMAGE with original background stored before is image placed to this area. Or LINE, BF for 1 color background.

Code: QB64: [Select]
  1. TYPE image
  2.     img AS LONG
  3.     active AS _BYTE
  4.     x AS INTEGER
  5.     y AS INTEGER
  6. DIM i(4) AS image
  7.  
  8. FOR do_images = 0 TO 4
  9.     i(do_images).img = _NEWIMAGE(50, 50, 256)
  10.     i(do_images).active = 1
  11.     i(do_images).x = RND * 800
  12.     i(do_images).y = RND * 600
  13.     _DEST i(do_images).img
  14.     CLS , 50 + 4 * do_images
  15.  
  16. SCREEN _NEWIMAGE(800, 600, 256)
  17.     CLS
  18.     FOR show = 0 TO 4
  19.         IF i(show).active = 1 THEN _PUTIMAGE (i(show).x, i(show).y), i(show).img
  20.     NEXT
  21.  
  22.         IF _MOUSEX > i(i).x AND _MOUSEX < i(i).x + 50 AND _MOUSEY > i(i).y AND _MOUSEY < i(i).y + 50 THEN i(i).active = i(i).active * -1: _DELAY .3
  23.     END IF
  24.  
  25.     i = i + 1: IF i > 4 THEN i = 0
  26.     _DISPLAY
  27.  

Offline Cobalt

  • QB64 Developer
  • Forum Resident
  • Posts: 878
  • At 60 I become highly radioactive!
    • View Profile
Re: Help with a pcopy question
« Reply #5 on: December 17, 2018, 06:34:15 pm »
Any chance of seeing the code? It would help us help you find a solution to the problem.
Until then, while PCOPY was handy back in QB45 its not so useful now, as screen memory is simply emulated through QB64, its simpler now-a-days to use multiple layers made with _NEWIMAGE() then combining them with _PUTIMAGE while using _CLEARCOLOR to make things transparent.(like making BLACK transparent so you copy the sprites without erasing all the existing background).
Granted after becoming radioactive I only have a half-life!

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Help with a pcopy question
« Reply #6 on: December 18, 2018, 10:05:54 am »
Upgraded source, now use PCOPY + _PUTIMAGE, not CLS and show numbers to image areas.
add _CLEARCOLOR 0 before _DEST 0 to line 28 for transparency.


Code: QB64: [Select]
  1. TYPE image
  2.     img AS LONG 'here are your fotos
  3.     active AS _BYTE
  4.     x AS INTEGER
  5.     y AS INTEGER
  6. DIM i(4) AS image, not_active AS LONG
  7. not_active = _NEWIMAGE(50, 50, 256)
  8.  
  9.  
  10. FOR do_images = 0 TO 4
  11.     i(do_images).img = _NEWIMAGE(50, 50, 256) '      use here = _LOADIMAGE (....), image resolution can be solved placing images to specified NEWIMAGE using PUTIMAGE.
  12.     i(do_images).active = 1
  13.     i(do_images).x = RND * 800
  14.     i(do_images).y = RND * 600
  15.  
  16.     '------- use this not wit LOADIMAGE -------------
  17.     _DEST i(do_images).img
  18.     CLS , 50 + 4 * do_images
  19.     _PRINTMODE _KEEPBACKGROUND , i(do_images).img
  20.     _PRINTSTRING (16, 16), STR$(do_images + 1)
  21.     ' -----------------------------------------------
  22. _DEST not_active
  23. LINE (0, 0)-(49, 49), 2
  24. LINE (0, 0)-(49, 49), 2, B
  25. LINE (0, 49)-(49, 0), 2
  26.  
  27.  
  28. SCREEN _NEWIMAGE(800, 600, 32)
  29. FOR background = 0 TO 799
  30.     b = b + (512 / 800)
  31.     LINE (background, 0)-(background, 599), _RGB32(b, 255 - b, 127 + b), BF
  32.  
  33.  
  34.     PCOPY 1, _DISPLAY
  35.     FOR show = 0 TO 4
  36.         IF i(show).active = 1 THEN
  37.             _PUTIMAGE (i(show).x, i(show).y), i(show).img
  38.         ELSE
  39.             _PUTIMAGE (i(show).x, i(show).y), not_active
  40.         END IF
  41.     NEXT
  42.  
  43.     IF TIMER > delay THEN
  44.         IF _MOUSEBUTTON(1) THEN
  45.             IF _MOUSEX > i(i).x AND _MOUSEX < i(i).x + 50 AND _MOUSEY > i(i).y AND _MOUSEY < i(i).y + 50 THEN i(i).active = i(i).active * -1: delay = TIMER + .3
  46.         END IF
  47.     END IF
  48.     i = i + 1: IF i > 4 THEN i = 0
  49.     _DISPLAY
  50.  
  51.  
« Last Edit: December 18, 2018, 02:32:15 pm by Petr »

Offline robpugh0829

  • Newbie
  • Posts: 19
    • View Profile
Re: Help with a pcopy question
« Reply #7 on: December 18, 2018, 11:59:28 am »
Thanks for the help everybody. I haven't been able to try this yet due to work, but I plan on trying it this evening. I appreciate everyones help. This is the most helpful programming forum I have ever been on. Thanks everyone!

Offline Cobalt

  • QB64 Developer
  • Forum Resident
  • Posts: 878
  • At 60 I become highly radioactive!
    • View Profile
Re: Help with a pcopy question
« Reply #8 on: December 18, 2018, 08:33:28 pm »
Upgraded source, now use PCOPY + _PUTIMAGE, not CLS and show numbers to image areas.
add _CLEARCOLOR 0 before _DEST 0 to line 28 for transparency.

if your using a 32bit layer be sure to use:
_CLEARCOLOR _RGB32(0,0,0)
for black.
Granted after becoming radioactive I only have a half-life!

Offline robpugh0829

  • Newbie
  • Posts: 19
    • View Profile
Re: Help with a pcopy question
« Reply #9 on: December 19, 2018, 09:54:49 am »
Petr,
This helped greatly! Thank you so much! It works.

Have a very happy holiday season!