Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.

# Another Small basic question

### #1 teatrap

teatrap

• Members
• 121 posts
• OFFLINE
•
• Gender:Male
• Local time:02:21 PM

Posted 20 November 2013 - 08:16 PM

I know another, but I'm guessing this is super simple to anyone who's aufait with this stuff:

This produces a ball that move from one side of the screen, hits a rectangle and moves back. But there are a couple of thing's that I don't really get and that aren't explained in the tutorial. Highlighted in bold:

1 - If I change the duration of the first animate Operation the ball stops before it hit's the rectangle, I don't understand why this would happen? If the duration is set to around 700ms or higher it stops before hitting the rectangle. (490is the duration given by the tutorial) If i set the duration lower than 490 it still hits the rectangle

2 - in this IF command it say's (Shapes.GetLeft(Sball) - yet it's the right edge of the ball that hit's the rectangle...?

Just find these thing's a bit confusing and it'd be great to have someone with a bit of know explain them

here's the code :

Shapes.Move(Sball, 0, 340)

x = 450

GraphicsWindow.DrawRectangle(550, 0, 80, 450)

GraphicsWindow.BrushColor = "Purple"

GraphicsWindow.FillRectangle(550, 0, 80, 450)

Shapes.Animate(Sball, x, 40, 490)

Program.Delay(500)

If (Shapes.GetLeft(Sball) = x) Then

Shapes.Animate(Sball, 0, 340, 500)

EndIf

thanks

Operating system_Windows 8.1 Pro with Media Center (9600)
CPU_Intel® Core™ i7-4700MQ CPU @ 2.40GHz
Motherboard_Hewlett-Packard (1966)
RAM_12063mb
Hard Drive_931gb (HGST HTS541010A9E680)
Graphics card_Intel® HD Graphics 4600
Sound card_IDT High Definition Audio CODEC

### #2 Sirawit

Sirawit

Bleepin' Brony

• Malware Response Team
• 4,161 posts
• OFFLINE
•
• Gender:Male
• Location:Thailand
• Local time:08:21 PM

Posted 21 November 2013 - 09:27 AM

1. The key of the question is this line:

Program.Delay(500)

Delay must be 10 miliseconds ahead of the duration because if it is faster the if statement will be done even when the animation still running, which cause the animation to stop and the ball goes back without reaching the rectangle.

(This is why the execise gives you 490 as default.) If you want duration 700 ms then you need to set it 710 ms etc.

2. (Shapes.GetLeft(Sball) measures x-cooordinates of Sball, this if statement check that the ball already reach the rectangle or not by measures it's left co-ord then check with x variable (x co-ord value) that it is the final co-ord or not, if yes, the ball goes back.

Thank you. Hope you understand and get well with the exercises!

Edited by Sirawit, 21 November 2013 - 09:28 AM.

If I don't reply back to you in 2 days, feel free to send me a PM.

“You’re lying… just like you were lying to me before. You have to hate me. I’ve been the worst daughter in the world… you should hate me.”

“But I don’t, Nyx. Because, Nyx, I’m your mother, and a mother will always love her daughter, no matter what.” -Past sins by Pen stroke.

#### 0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users