So I do not want to create separate sprites for each direction a mob is moving, I just want to use 1 sprite (strip) with all 4 directions for each mob with different possible image_number(s) for different mobs. This script works almost perfectly, it selects correctly the starting sprite of each direction but then doesn't animate or go on with the animation for the specific direction. Used with sprites with either 8, 12, 24 subimages in it. Please read or test the code for details, it has comments.
Please advise how to fix it or an example that works for any sprite movement animation, that selects automatically between subimages, etc.
Oops ignore the variable "ic" in the switch statements below it does nothing.
Code below:
//critter_anim();
// Sprite sequence: UP - LEFT - DOWN - RIGHT
//x0=x; y0=y; is set in oMob object's begin step
////////////////////////////////////
if (x0==0 && y0==0) {image_index=0;} //STILL START
////////////////////////////////////
if x<x0 //LEFT
{
switch (image_number) //for different strips with different number of subimages
{
case 8: image_index=0; ic=2; break;
case 12: image_index=3; ic=3; break;
case 24: image_index=6; ic=6; break;
}
from_left=1; from_right=0; from_up=0; from_down=0;
}
///////////////////////////////////
if x>x0 //RIGHT
{
switch (image_number)
{
case 8: image_index=0; ic=2; break;
case 12: image_index=9; ic=3; break;
case 24: image_index=18; ic=6; break;
}
from_left=0; from_right=1; from_up=0; from_down=0;
}
////////////////////////////////////
if y<y0 && x==x0 //UP
{
switch (image_number)
{
case 8: image_index=0; ic=2; break;
case 12: image_index=0; ic=3; break;
case 24: image_index=0; ic=6; break;
}
from_left=0; from_right=0; from_up=1; from_down=0;
}
////////////////////////////////////
if y>y0 && x==x0 //DOWN
{
switch (image_number)
{
case 8: image_index=0; ic=2; break;
case 12: image_index=6; ic=3; break;
case 24: image_index=12; ic=6; break;
}
from_left=0; from_right=0; from_up=0; from_down=1;
}
////////////////////////////////////
if x==x0 && y==y0 //SAME SPOT AS BEGIN STEP
{
if from_left==1 {image_index=0;}
if from_right==1 {image_index=0;}
if from_up==1 {image_index=0;}
if from_down==1 {image_index=0;}
if (from_left==0 && from_right==0 && from_up==0 && from_down==0) {image_index=0;}
}
Edited by Boysano, 29 August 2012 - 09:18 AM.











