icon move

New to Gambas? Post your questions here. No question is too silly or too simple.
User avatar
BruceSteers
Posts: 1589
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: icon move

Post by BruceSteers »

cliofused wrote: Wednesday 24th April 2024 1:25pm I am using the Bicycle icon from stock

but can not find the path to it.

It says" icon:/32/bicycle" on PictureBox Picture column.

Confused@Cliofuse :geek:
It's Stock. Stock class uses a mix of the system icons and some built in gambas ones.
the icon:/ path links internally to gb.form.stock icons and is not a real path.

bicycle is a gambas icon i think so it's built into gb.form.stock
if you do not have the source code you can get them from the gambas repository here..
https://gitlab.com/gambas/gambas/-/tree ... ock/gambas
If at first you don't succeed , try doing something differently.
BruceS
cliofused
Posts: 9
Joined: Tuesday 23rd April 2024 11:09am

Re: icon move

Post by cliofused »

Feck ok

Thanks :shock:
cliofused
Posts: 9
Joined: Tuesday 23rd April 2024 11:09am

Re: icon move

Post by cliofused »

So I am new to Gambas and PC programming still trying to understand what i am doing.

I found this on Wikipedia and want to know from the experts when you move an icon around the screen is this what you basically doing.

A film – also called a movie, motion picture, moving picture, picture, photoplay or (slang) flick – is a work of visual art that simulates experiences and otherwise communicates ideas, stories, perceptions, feelings, beauty, or atmosphere -through the use of__[[[ moving images]]]____. These images are generally accompanied by sound and, more rarely, other sensory stimulations.[1] The word "cinema", short for cinematography, is often used to refer to filmmaking and the film industry, and the art form that is the result of it.

I put the part between brackets that interested me.
It is like you draw a ball across the card by using many cards with the ball in different position then it appears to move.

please correct me if i am wrong, still trying to understand Paint.move :shock:

I hope it will help other beginners to game programming with Gambas.
User avatar
BruceSteers
Posts: 1589
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: icon move

Post by BruceSteers »

Well technically a movie is not so much "moving images" as it is a series of still images shown in rapid succession.

So no. I would not consider making/storing a ton of pictures with a ball in a different place to show as a movie.

If i wanted to animate a ball moving on a background i would do it like this...

Have a background image and a ball image.
Then use either a DrawingArea or a PictureBox picture and Paint the background image and then paint the ball on it at the required position.
The code to move the ball position and repaint the image would have to be in a timer event that called the image to refresh and not the Draw event as you have seen the refresh event can trigger without your instructions.

And there is no such command as Paint.Move() ??
Paint.MoveTo() is just a positioning command. it's like instructing the pen to come off the paper then move to another place to start writing.
After the Paint.MoveTo() instruction you will then use something like Paint.LineTo() to draw a line from that position.

Unless you are talking about the Control.Move() function a PictureBox or a DrawingArea has? In that case that is for moving the control (not its contents) the same as Button.Move() Form.Move() it moves the whole object and does not do anything to it's contents.

Maybe try reading the gambas wiki rather than wikipedia.
https://gambaswiki.org/wiki/comp/gb.qt4/paint

And sorry to be a pain but please be more precise in your wording. You clearly did not mean Paint.Move() as that command does not exist so what exactly do you mean?
i can only guess if you are not completely accurate/precise.

It's going to be a learning process for you, i was coding with gambas for 5 years or so before i made my first graphical game.
If you are new to gambas and new to programming then maybe jumping straight into making a game is a bit ambitious. there is a hell of a lot of work and time involved in making a functional game.

I started making my Blockski+ game early January, it took about a month to get it ready to post here but it was very WIP and full of bugs as you can see if you read the topic. https://forum.gambas.one/viewtopic.php?t=1696 after 1 month of coding it still had a long way to go.

it's still not completely finished and has a bug or 2.

You will get there though if you keep at it.
lots of experimenting, lots of debugging, lots of re-writing code as you find better ways to do things.
you may be better off posting code that you have that does not work for you. we can better understand what mistakes you are making by examining your code.

But i say again, read the gambas wiki https://gambaswiki.org/wiki/ then read it some more. then re-read it. especially Paint.class if you are going to use it. forget wikipedia, that knows nothing about gambas programming.
If at first you don't succeed , try doing something differently.
BruceS
User avatar
BruceSteers
Posts: 1589
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: icon move

Post by BruceSteers »

Maybe this will help get you started....

It has a DrawingArea

It selects a random desktop background image to use as the background

then it loads the gambas bug pic as the sprite.

When you click the image it starts the timer that each time it triggers it moves the bugs X position to the right and the Y towards the mouse.
The Timer event moves the bug position aPicPos[0] and aPicPos[1] then triggers a DrawingArea1.Refresh

The DrawingArea1_Draw() event paints the background and then the bug on top in the desired place.

It's not much code...


' Gambas class file

Private hBG As Picture
Private hBugPic As Picture
Private aPicPos As Integer[] = [100, 100]

Private MoveTimer As New Timer As "MoveTimer"

Public Sub Form_Open()

  Randomize
  MoveTimer.Delay = 10

  hBugPic = Picture["icon:/32/bug"]  ' bug picture

  ' now select a random background picture
  Dim aFiles As String[] = RDir("/usr/share/backgrounds/", "*.jpg")
  Dim sFile As String = "/usr/share/backgrounds" &/ aFiles[Rand(0, aFiles.Max)]
  hBG = Picture[sFile].Stretch(DrawingArea1.W, DrawingArea1.H)  ' load the picture and stretch it to fit the drawing area

  
End

Public Sub DrawingArea1_Draw()

  Paint.DrawPicture(hBG, 0, 0, Last.W, Last.H) ' draw background
  Paint.DrawPicture(hBugPic.Image.Colorize(Color.Black).Picture, aPicPos[0] + 3, aPicPos[1] + 3, hBugPic.W, hBugPic.H) ' draw a bug shadow
  Paint.DrawPicture(hBugPic, aPicPos[0], aPicPos[1], hBugPic.W, hBugPic.H) ' draw the bug

End

Public Sub DrawingArea1_MouseUp()

  MoveTimer.Enabled = Not MoveTimer.Enabled  ' toggle the timer on or off

End

Public Sub MoveTimer_Timer()
  
  aPicPos[0] += 2  ' move left 2 pixels
  If aPicPos[0] > DrawingArea1.W - 16 Then aPicPos[0] = 16  ' if we are far right move to the left

  If aPicPos[1] + 16 < Mouse.ScreenY - DrawingArea1.ScreenY Then Inc aPicPos[1] Else Dec aPicPos[1]  ' make it head towards the mouse

  DrawingArea1.Refresh
  
End



Have fun :)
Attachments
_aa-0.1.tar.gz
(53.54 KiB) Downloaded 5 times
If at first you don't succeed , try doing something differently.
BruceS
cliofused
Posts: 9
Joined: Tuesday 23rd April 2024 11:09am

Re: icon move

Post by cliofused »

Yes that worked
Thank you @BruceSteers
Post Reply