Animation and idle pose
BlitzMax Forums/BlitzMax Beginners Area/Animation and idle pose
| ||
ok the idea is that i click with the mouse and this code moves a image called block towards the target one pixel at a time cheaking one pixel ahead before moving. before i move the character (indy) i store his postion as old_x and old_y, and the next time round the loop if the old xy is the same as the new xy i would like it to draw the idle indy image. this code doesnt work ? it displays the idle pos but when i move left it just keeps playing the walk left anim even when he stops. also i can think of a way to have the idle image face the way indy was traveling last. If old_x = block_xpos And old_y = block_ypos DrawImage(indy_r,block_xpos,block_ypos) Else If old_x > block_xpos DrawImage(indy_wl,block_xpos,block_ypos,frame) If MilliSecs() >tmr + anim_speed tmr = MilliSecs() frame = frame +1 If frame = 6 Then frame =0 EndIf EndIf EndIf EndIf ResetCollisions() 'move up If block_ypos > ytarget If ImagesCollide(block,block_xpos,block_ypos-1,0,walkable_area,40,40,0)= 0 old_y = block_ypos block_ypos:- 1 EndIf EndIf ResetCollisions() 'move down If block_ypos < ytarget If ImagesCollide(block,block_xpos,block_ypos+1,0,walkable_area,40,40,0)= 0 old_y = block_ypos block_ypos:+ 1 EndIf EndIf ResetCollisions() 'move left If block_xpos > xtarget If ImagesCollide(block,block_xpos-1,block_ypos,0,walkable_area,40,40,0)= 0 old_x = block_xpos block_xpos:- 1 EndIf EndIf ResetCollisions() 'move right If block_xpos < xtarget If ImagesCollide(block,block_xpos+1,block_ypos,0,walkable_area,40,40,0)= 0 old_x = block_xpos block_xpos:+ 1 EndIf EndIf ResetCollisions() |
| ||
<edit> Scrub all that. <edit> Scrub again... You might want to move your old_x=block_xpos assign to the end of your first block so you don't have to do 5-6 times. Same with your resetcollisions. You code is poorly laid out but I can't see where the problem is from it. This does what you want (in simple terms) and might help but, even if you don't use OO, you need to check into functional programming. SuperStrict Graphics 800,600 Local old_x:Int Local old_y:Int Local block_xpos:Int=400 Local block_ypos:Int=500 While Not KeyHit(KEY_ESCAPE) Cls If old_y=block_ypos And old_x=block_xpos DrawOval block_xpos-4,block_ypos-4,8,4 Else DrawOval block_xpos-4,block_ypos-4,8,8 EndIf old_y=block_ypos old_x=block_xpos If KeyDown(KEY_UP) block_ypos:-1 Flip Wend |
| ||
is indy_r the idle image, and is it a single image or does it consist of frames ( idle animation )? what is it that doesn't work? it doesn't display the idle image, the blocks don't move? would it be possible to zip up the source and resources and post a link? i'd like to take a look at the complete code and play with it to see if i can uderstand what you mean. if not i understand. Edit: hmmm had to walk away for a few mins when i was typing this and by the time i finally posted tonyg had already respond. i'd still like to have a play with the source and resources if possible though. |
| ||
TonyG: Thanks, but my code works by moving a character towards the point where the mouse was clicked so i can use if keydown etc. plus cls would get rid of the background? I know i need to learn more about how my code is layed out. i will put all the update character code in a function when i know it works. KingNothing: ok ill pack it up when i get back home and post a link. |
| ||
(link removed! source for finish game will be released to anyone that wants it when finished) this is just my test of animation and collision plus the need media |
| ||
but my code works by moving a character towards the point where the mouse was clicked so i can use if keydown etc Yes, I know. I wasn't replacing your code but showing that your ideas does work. plus cls would get rid of the background? It would. If you're redrawing every tile each time anyway then you don't need the cls. Again, I wasn't giving you an answer.What is it you're looking for? Pointers in the right direction, a fix for this particular problem or some code? Anyway, move your assignment of old_x and old_y up your code... |
| ||
first of all sorry it took so long, right after my last post i ended up playing some gta for a very long time. ok i think i have what your looking for now, it was relatively easy. i just took a few min to study your code and see what you were trying to do and how you were trying to do it. after a few more min i came up with what i think/hope you were asking for. i only changed a small percentage of your code slightly but you'll notice whats different, i stayed as close to your style as i could. i remarked what i added as '*******New*****. anyway here's the new code i hope that helps ya out. as a side note: i'm gonna have to agree with tony. doing small simple programs like that is one thing. but when you get into making larger programs, it'll be hell to read and follow. you need to structure your code. start by just using functions and then later on get into using types with methods and functions, you'll do your self a huge favour. i know from expierence, when i first started coding thats exactly how i did it. its a very bad habbit and the longer one codes with out structure the harder it is to break that habbit. |
| ||
thanks thats spot on! yes i agree with both of you i need to start using structure, Part of this was that i havent used blitzmax before, I didnt really understand how everything works. i should have read the sloan book all the way through but the compo dead line is sunday and i want to get something in by then,even if it is a couple of screens and a puzzle demo. KingNothing thanks again for taking the time to do this! Now ive just got to squeeze the scaling in ;OP |
| ||
np, glad i could help |