Old 30th October 2007, 02:34   #1
Clancy
Junior Member
 
Join Date: Oct 2007
Posts: 34
Sprite movement howto?

Hi,

Sorry if this is in the wrong place: it doesn't seem to me to fit properly into any of the subforums. I also apologise in advance if this has been answered before: if it has I've been unable to find it via the forum FAQs, search or google

Looking at the discussions in the preset forum my problem is extremely basic, but that's where I am at the moment - I only discovered winamp visualizations a week ago and I've done no maths since high school, back in the mesozoic era.

I've made a few sprites of my own - very basic items to "drift across the screen every so often" and installed them using the examples in the default milk2_img.ini file.

I've made several successful modifications to the example files for things like sprite size, blendmode and direction of rotation, now I'm stuck on changing the direction it moves. The example file I'm trying to modify is this one:

[img04]
desc="cool: an 'osapien' drifts across the screen every so often."
img=textures\smalltiled_electric_nebula.jpg
init_1=blendmode = 3;
init_2=x = -100;
init_3=orig_y = 0.5;
code_1=time_to_reset = below(x,-0.5);
code_2=x = x*(1-time_to_reset) + time_to_reset*(1.5 + 0.01*rand(100) + 3);
code_3=orig_y = orig_y*(1-time_to_reset) + time_to_reset*(0.3 + 0.4*0.01*rand(100));
code_4=sx = sx*(1-time_to_reset) + time_to_reset*(0.25 + 0.4*0.01*rand(100));
code_5=sy = sx;
code_6=x = x - 0.008 + 0.0033*sin(time*1.371);
code_7=y = orig_y + 0.12*sin(time*1.9);


the resulting sprite drifts across the preset from right to left. I've got one that does that, now I'd like to change it so the sprite drifts across from left to right. It's not covered in milkdrop.html and milkdrop_preset_authoring.html is beyond me. I'd guess it's somewhere in the x values so I played around with a few things more or less at random (switching + for - and vice versa, cos for sin, moving the 1- around) which either did nothing or stopped the sprite appearing at all.

So could someone please tell me how to get the sprite in the above example to drift from left to right? and / or point me at an entry level howto?

Thanks in advance

C
Clancy is offline   Reply With Quote
Old 14th November 2007, 02:01   #2
Clancy
Junior Member
 
Join Date: Oct 2007
Posts: 34
A friend who's a programmer took a look at this for me and came up with a couple of solutions:

Quote:
I think the simplest thing to do is to replace all references to variable 'x' with 'x1' and then after those lines add a line which sets x = 1 - x1.


[img44]
desc=an image drifts across the screen every so often, left to right
img=sprites\dragon.tga
colorkey=0xFFFFFF
init_1=blendmode = 4;
init_2=x1 = -50;
init_3=orig_y = 0.5;
//init_4=flipx=1;
code_1=time_to_reset = below(x1,-0.5);
code_2=x1 = x1*(1-time_to_reset) + time_to_reset*(1.5 + 0.01*rand(100) + 3);
code_3=orig_y = orig_y*(1-time_to_reset) + time_to_reset*(0.3 + 0.4*0.01*rand(100));
// code_4=sx = sx*(1-time_to_reset) + time_to_reset*(0.25 + 0.4*0.01*rand(100));
code_4=sx = 0.15;
code_5=sy = sx;
code_6=x1 = x1 - 0.008 + 0.0033*sin(time*1.371);
code_7=y = orig_y + 0.12*sin(time*1.9);
code_8=x= 1-x1;
In this example the image takes a long time to start and comes through infrequently, much the way the default one does.

There is another way of doing it, which in the original example is frequent and regular but gives you an easy way of fiddling with the variables:

Quote:
Changing orig_x & final_x affects how frequently the images appear on the screen. Changing incr_x affects how fast the images cross the screen. Because it is just incrementing x for the same amount each frame it may not be as interesting as the other examples but it is easy to see the effects of changing the variables.

[img41]
desc="cool: an image drifts across the screen every so often."
img=C:\Users\Public\Pictures\Flying\20070715_14\P7140030.jpg
init_1=blendmode = 3;
init_2=orig_x= -0.1;
init_3=orig_y = 0.5;
init_4=incr_x = 0.005;
init_5=final_x=1.1;
init_6=count_x = 0;
code_1=time_to_reset = above(x,final_x);
code_2=orig_y = orig_y*(1-time_to_reset) + time_to_reset*(0.3 + 0.4*0.01*rand(100));
//code_4=sx = sx*(1-time_to_reset) + time_to_reset*(0.25 + 0.4*0.01*rand(100));
code_3=sx=0.15;
code_4=sy = sx;
code_5=y = orig_y + 0.12*sin(time*1.9);
code_6=count_x= (count_x * (1-time_to_reset)) + 1;
code_7=x=orig_x + (count_x * incr_x);
I fiddled with the second example a bit to slow it down and vary the time at which it appears. This one occasionally spawns 2 instances of the image which is fun (I'm using a dragon). What I ended up with is

[img03]
desc="cool: a dragon drifts across the screen every so often." - left to right
img=sprites\dragon.tga
colorkey=0xFFFFFF
init_1=blendmode = 4;
init_2=x = -100;
init_3=orig_y = 0.5;
code_1=time_to_reset = below(x,-0.5);
code_2=x = x*(1-time_to_reset) + time_to_reset*(1.5 + 0.01*rand(100) + 3);
code_3=orig_y = orig_y*(1-time_to_reset) + time_to_reset*(0.3 + 0.4*0.01*rand(100));
code_4=sx = 0.2;
code_5=sy = 0.2;
code_6=x = x - 0.008 + 0.0033*sin(time*1.371);
code_7=y = orig_y + 0.12*cos(time*1.9);
code_8=done=above(frame,2000);

Another option would be

Quote:
I haven't tried it but it looks like the change you made will result in the x positions being slightly different for each cycle i.e. the starting count will change when the cycle resets. Doing something similar with incr_x (i.e. introducing a random increment for each frame - not just on the reset) will make it vary the rate of progress across the x-axis. Could look nice or make people nauseous .
One could fiddle with this indefinitely, for the moment I'll leave it there.
Clancy is offline   Reply With Quote
Reply
Go Back   Winamp Forums > Visualizations > MilkDrop

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump