Slow Down Certain Frame
BlitzPlus Forums/BlitzPlus Beginners Area/Slow Down Certain Frame
| ||
I have a sprite with 2 frames. When I press space I want my pistol to fire. It does, but way too fast. I want frame 2 to last longer before it resets back to 1. I have tried a few methods, but none have worked. My latest attempt is listed below: Function Pistol() If waitforreset = True frameTimer=CreateTimer(60) WaitTimer(frameTimer) waitforreset = False Goto drawmorefirst EndIf pframe = 0 If KeyHit(57) Then pframe = 1 waitforreset = True EndIf .drawmorefirst DrawImage pistol,200,230,pframe End Function |
| ||
Well I wouldn't use Timers or Goto. When the key is pressed, set a counter to say 100. Have your drawimage draw frame 1 if the counter is say >80 and frame 2 if the counter is <= 80 and maybe nothing if 0. This will mean it stays on frame 1 for 20% of the time and frame2 for 80% if this is what you meant. Or just chance the split to 50/50 whatever. Then reduce the counter everytime the function is called (i.e. once every frame or fixed logic iteration). Also prevent fire from being pressed if counter>0. Say you had lots of frames and you wanted non regular timing on them, you could make an array with values for how long each frame is displayed (in frames/loop iterations) then when drawing compare the counter value with the values in the array to work out if the frame should change yet. Rather than looping through the array to check, you should just keep a track of the current frame and read the next frame's counter value from the array to compare against. I hope this makes sense as I haven't spent a long time spelling it out, sorry. |
| ||
Could you please show what you mean, with that code above? I never learned timers or anything under that category. |
| ||
I said I wouldn't use timer's because you were already using one! i.e frameTimer=CreateTimer(60) etc. I don't have time at the moment to write some code, but all you've got to do is make a continous loop that exit's when Esc is pressed. Then call all your functions in the loop (once per loop iteration) and make sure when fire is pressed you set a global var called FireCounter (or something) to say 100. Then decrease it by 1 each time the loop goes round. And decide which frame to draw based on the value of FireCounter, easy. Try it out. Maybe someone else will be able to make some code too. |
| ||
Here`s a psuedo code example, you should hopefully be able to work it out from this, if not just ask. If pistol fire delay = 0 Allow pistol to be fired Set the pistol fire delay to a value, say 10 so that we cannot fire again until this counter reaches 0 Else pistol fire delay is above 0 so subtract a value of one until we get to 0 again then we can fire another shot. Endif Hope this helps a little. Jason. |
| ||
This isn't helping me out at all. I have no idea what either are you are talking about. Look at my crappy code if you don't understand how new I am to this. I'll just keep trying random things until it works. Thanks anyway. |
| ||
ok, sorry... maybe just start with something simpler. Have you looked at the examples that come with BlitzPlus. Fiddle with those until you learn more :-) |
| ||
I don't have blitzplus. I only post here because it has more 2D threads than the 3D section does. |
| ||
are all the Blitz3D examples about 3D games then or are some nice simple 2D ones? |
| ||
Nah, mostly 3D ones. I just came up with a new idea though; although it won't work since I keep getting this "undefined label" error:Function Pistol() If KeyHit(57) Then pframe = 1 pistolresettimer = 50 EndIf If pistolresettimer > 0 Then Goto drawmmore pistolresettimer = pistolresettimer - 1 EndIf If pistolresettimer = 0 Then pframe = 0 EndIf .drawmore DrawImage pistol,200,230,pframe End Function |
| ||
2D in B+ is faster than 2D in B3d, afaik, and you can benefit from events and the option to easily make editor.. I'd consider the change.. and B+'s manual is really very good also. |
| ||
Undefined label because you have "drawmmore" with two ms! aha your code is more along the correct lines now. However you don't need the goto because that means it's missing the line out that reduces the timer. You need to reduce the timer each time the function is entered. |
| ||
There are heaps of 2D examples with Blitz 3D more than 3D examples I`d say. Like Grey Alien says have a play around with them you`ll learn a lot. Jason. |
| ||
@ CS_TBL: This is for a 3D program actually. I'm drawing the weapons onto the screen like the original DOOM. @ Grey Alien: I don't know what "ms" means, but I just found that error where I did the "goto" before minusing the timer which will make the timer useless. Don't know if they will fix anything, but I'll try it next time I have the code with me (which will be Wensday). |
| ||
you said you were getting "this "undefined label" error:" thats because you wrote "Goto drawmmore" and your label was called ".drawmore" it has only one M, drawmore has two Ms (M for mother!) |
| ||
Wow! Can't believed I missed that! Thanks a bunch :D Edit: Ok, well the program works now but nothing has changed. It's still working the same way it was before. I'm clueless. I really thought this would work, but it doesn't... |
| ||
post some more code and say again what you want it to do... |
| ||
I'm just creating a doom 1 for fun. Before posting my code, please realize that I already know how bad it is. This was a quick, small, project I started last week. The problem I have is that I can't get the pistol to slow down a bit when firing (frame 2).Graphics3D 640,480 SetBuffer BackBuffer() ;NOTE: I left Automidhandle out before centering HUD. I was too lazy to add it once I remembered. camera=CreateCamera() PositionEntity camera,0,1,0 light=CreateLight() RotateEntity light,90,0,0 ;load animated pistol Global pistol = LoadAnimImage("pistol.bmp",200,150,0,2) MaskImage pistol,0,0,0 Global pframe = 0 ;load HUD image Global HUD = LoadImage("hud.bmp") ;create terrain terrain=CreateTerrain(128) ;texture terrain grass_tex=LoadTexture( "grassground.bmp" ) EntityTexture terrain,grass_tex While Not KeyDown(1) Pistol() DrawHUD() If KeyDown( 205 )=True Then TurnEntity camera,0,-1.5,0 If KeyDown( 203 )=True Then TurnEntity camera,0,1.5,0 If KeyDown( 208 )=True Then MoveEntity camera,0,0,-0.07 If KeyDown( 200 )=True Then MoveEntity camera,0,0,0.07 Flip Cls RenderWorld Wend ;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;draws HUD Function DrawHUD() SetBuffer FrontBuffer() DrawImage hud,0,380 SetBuffer BackBuffer() End Function ;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;pistol Function Pistol() If KeyHit(57) Then pframe = 1 pistolresettimer = 50 EndIf If pistolresettimer > 0 Then pistolresettimer = pistolresettimer - 1 Goto drawmore EndIf If pistolresettimer = 0 Then pframe = 0 EndIf .drawmore DrawImage pistol,200,230,pframe End Function ;;;;;;;;;;;;;;;;;;;;;;;;;;;;; End |
| ||
I see the problem! Pframe and pistolresettimer are NOT global, there for they are created each time as local variabels in the pistol() function. At the top of your code put: Global pframe=0 Global pistolresettimer=0 that should do it tada! |
| ||
Ah thanks so much! Unfortunately I don't have it here with me right now. I'll post back later when I know it works :D |
| ||
cool, glad to be of assistance! :-) |