Moving an object, Is this as fast as it gets?
BlitzPlus Forums/BlitzPlus Beginners Area/Moving an object, Is this as fast as it gets?
| ||
I need to be able to move a single object at 1 pixel resolution. I tried the following code but it runs at a crawl, not sure what I am doing wrong....... I will be using Imagescollide to get pixel perfect collision. Graphics 800,600,0,2 SetBuffer BackBuffer() xpos = 1 ypos = 1 Shape = CreateImage(100,60) ;Make Shape Graphic Oval 50,70,40,40,1 Oval 89,80,22,22,1 Oval 110,70,40,40,1 GrabImage shape,50,50 ;Main Loop Repeat Cls xpos=xpos+1 If xpos>679 Then xpos=1:ypos=ypos-1 If ypos<-360 Then End DrawImage shape,10+xpos,515+ypos Flip Until KeyDown(1) End Any ideas would be much appreciated. TIA Andy |
| ||
Move it more than 1 pixel at a time. |
| ||
Move it more than 1 pixel at a time. I cannot do that, because I need the one pixel resolution to check for collision. If you imagine an AI program doing a Jigsaw puzzle and having to fit the next piece perfectly into position, that is similar to the problem I need to resolve. If the computer moved it at more than one pixel it would miss being able to fit the part into place. I am not writing a Jigsaw program, its just the best way that I can explain what I am trying to acheive! Thanks Andy |
| ||
The best I can figure is to move the object multiple times in one frame, but doing all the needed checks before the next movement. This allows the program to check all the needed locations while the player sees a quickly (given your fps is high enough) moving object. |
| ||
I tried the following code but it runs at a crawl, not sure what I am doing wrong....... If you move it one pixel at a time, it's never going to be more than ~60 pixels a second or so (depending on your refresh rate), so it will take your sprite 17 seconds to move from one side of the screen to the other in 1024x768. The only way around that is to seperate your logic from your drawing routine, and call the movement logic more frequently than that you actually draw the updates to the screen. |
| ||
Thanks for the input. I don't actually need to see the part moving into position. Is there is a way to check its position to one pixel resolution as fast as possible without actually drawing it onto the screen?? The program only needs to show the object once the program has determined that the part has reached its correct location. Can I still use collision detection if the objects are not actually being drawn on screen??? Andy |
| ||
Yes. The collision system in Blitzplus is not actually associated with anything that's on the screen anyway. The collision system is more hypothetical, i.e. "Suppose I have image 1 at x1,y1, and image 2 at x2,y2, are they colliding? If not, I'll draw both images. If so, I'll draw an explosion". |