mircscripting.info Forum Index mircscripting.info
#mIRCscripting Forum
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

PicWins 1: Animations

 
Post new topic   Reply to topic    mircscripting.info Forum Index -> Tutorials
View previous topic :: View next topic  
Author Message
BlueThen2
Quite Active


Joined: 11 Jun 2008
Posts: 22

PostPosted: Tue Oct 28, 2008 5:13 pm    Post subject: PicWins 1: Animations Reply with quote

If you want to have a simple dot falling from the top to bottom of the window, here's how you do it:
Understanding XY
The X-Axis Y-Axis on your computer probably doesn't work out quite like how they taught you in school. Of course, X is left and right, Y is up and down. Typically, in school, they teach you that:
Code:
Y
5
4
3
2
1
0 1 2 3 4 5 X


But in mIRC, and on your monitor, the Y-Axis is upside down. Like so:
Code:
0 1 2 3 4 5 X
1       |
2       |
3 - - -o
4
5
Y

Whenever determining a point on the XY axis, you should always know that it's (X,Y). X always goes first, just think of it in alphabetical order. The point on the chart above should be at (4,3)


Open the Windows
Start out by opening one or two windows (depends on how you want to buffer), with the second window being hidden (-h). I usually do 400 x 400, but you can try other sizes if you wish. Try and get into the habit of using -d, so the window is a popup and an actual size.
Code:
window -pd @myanimation -1 -1 400 400
window -hpd @myanimation.buffer -1 -1 400 400
-p is necessary, it tells mIRC that the window is a Picture Window, giving you the ability to draw on it.

Set the Variables
After opening the window(s), you're going to want to keep track of all the objects you're going to draw onto them. So start out with
Code:
set %MA.X 200
and
Code:
set %MA.Y 0

MA stands for "My Animation" I usually use the project's name in all my variables, hashtables, etc, just to stay organized and to keep it from interfering with other scripts.

Create the Frames
Now for the frames. You can't do while or goto loops for this without an outside DLL that enables you to do so. Despite the fact that they are faster, they can freeze up your mIRC. So that means you're going to have to use an alias loop.
Code:
 alias -l ma.frame {
.timer 1 0 ma.frame
}
The reason it has .timer 1 0 ma.frame, rather than just ma.frame to loop, is because you can't really use the same alias inside its own command. Also, the . is to silence the timer, so it doesn't echo "Timer has been initiated/halted" a million times. The -l in alias -l ma.frame stands for "Local," it means that the alias can't be used outside of the script. You can unset this if you want to for debugging purposes. It's not really necessary, unless you think that the alias can get in the way of some other commands.

Draw the Picture
Each frame, you're going to have to draw the background and the object wherever designated.
Code:
 alias -l ma.frame {
clear @MyAnimation.buffer
drawfill @MyAnimation.buffer 0 0 1 1
drawdot @MyAnimation.Buffer 1 20 %ma.x %ma.y
drawcopy @MyAnimation.Buffer 0 0 400 400 @MyAnimation 0 0 400 400
.timer 1 0 ma.frame
}
In this segment of code, the buffer is cleared every frame, the background is colored white, and the dot is drawn on black. I also added drawcopy. That's the buffer, if you were to have it clear the main window and start redrawing on it, your animation would end out blinking when played. But with the buffer, there is no blinking because you're simply placing the next frame right over the previous one all at once after it's been drawn out. Another way to buffer is to have one window and use -n when drawing out all your stuff. When you're done drawing, use /draw to buffer.

Animate the Animation
If you've ever animated before, you'll know before hand that it's not all that easy. Every frame is going to involve moving objects moving just a "wee" bit each frame, so everyone can actually see it moving. In each frame, you're going to have to increase the Y position of the dot, just by 2 pixels.
Code:
alias -l ma.frame {
inc %ma.y 2
clear @MyAnimation.buffer
drawfill @MyAnimation.buffer 0 0 1 1
drawdot @MyAnimation.Buffer 1 20 %ma.x %ma.y
drawcopy @MyAnimation.Buffer 0 0 400 400 @MyAnimation 0 0 400 400
.timer 1 0 ma.frame
}



Cleaning Things Up
We're not done yet. If we stop now, we're going to get some errors when running the animation multiple times, you're also going to leave back a lot of junk that you might not want. If you remember in the beginning of the tutorial, we opened up two windows. A hidden one for the buffer, and a visible one to hold the animation. Closing the main window isn't going to close the hidden one. So you're going to have to close the hidden one whenever the main window is closed.
Code:
on *:Close:@myanimation: {
window -c @myanimation.buffer
}

We also set 2 variables for the script, which we're going to need to unset. You can either use unset %ma.x %ma.y, or unset %ma.*. I find that using the second is a lot easier, especially when you have a lot of variables to handle during the animation.
Code:
on *:Close:@myanimation: {
window -c @myanimation.buffer
unset %ma.*
}

When we close the main window, we're probably going to get an error that looks a lot like this: "/drawcopy: invalid window." That's telling us that we're trying to draw on a window that doesn't exist. So we're going to need to find out a way to stop the animation from drawing if the window isn't there.
In the frame alias, we're going to put if ($window(@myanimation)) { right after the alias creation, and add another bracket after the timer to close it.

Example
So here's the full code for the example animation:
Code:
alias ma {
  window -pd @myanimation -1 -1 400 400
  window -hpd @myanimation.buffer -1 -1 400 400
  ;Opens the windows. -p for "Picture Window," -d for "Desktop Window" (popup), and -h for "Hidden"
  set %MA.X 200
  set %MA.Y 0
  ;Sets the variables for the position of the object
  ma.frame
  ;Starts the animation
}
alias -l ma.frame {
  if ($window(@myanimation)) {
  ;checks if the window exists.
    inc %ma.y 2
    ;Increases the Y position of the object
    clear @MyAnimation.buffer
    ;Clears the buffer.
    drawfill @MyAnimation.buffer 0 0 1 1
    ;Colors the background white.
    drawdot @MyAnimation.Buffer 1 20 %ma.x %ma.y
    ;Draws on the black dot.
    drawcopy @MyAnimation.Buffer 0 0 400 400 @MyAnimation 0 0 400 400
    ;Buffers.
    .timer 1 0 ma.frame
    ;Restarts the frame
  }
}
on *:Close:@myanimation: {
  window -c @myanimation.buffer
  ;Closes the buffer.
  unset %ma.*
  ;Unsets all the script variables.
}

When you run the animation, a dot should appear at the top and scroll down past the bottom.

FPS Synchronization
The animation should run differently for most machines. Despite the fact that you have it set to move at a constant 2 pixels per frame, the dot might move faster or slower when tested on different computers. This is because the frame isn't looped at a set rate, so you're going to need FPS(Frames Per Second) Synchronization. A tutorial for that can be found at http://picwin.scriptsdb.org/viewcontent.php?id=25

Experiment
This may seem extremely simple now, or hard, but this is a basic example and tutorial to start you off. I suggest you try experimenting with different animations and projects, and learn some techniques on your own. Feel free to take this example code, edit, add, delete some stuff in it to create some of your own effects.


Written by BlueThen on October 28, 2008.
www.BlueThen.com
At this moment, BlueThen.com is down due to some issues with my host and his website. However, BlueThen.com should be back up in good time.
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    mircscripting.info Forum Index -> Tutorials All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group