Problems with picture commands
Author |
Message |
Jeffmagma
|
Posted: Sat Dec 12, 2015 11:05 am Post subject: Problems with picture commands |
|
|
What is it you are trying to achieve?
Create a car from top view
What is the problem you are having?
I get an error that says Illegal picture ID number '0'. (Probable cause: picture was not successfully created)
It was working the first time I tried it, and when it rotated, the left side would be cut off
Describe what you have tried to solve this problem
I've tried searching these forums for the same error, but they were mostly caused by loading an image from file
Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
(I haven't figured out how to make the car go towards the angle it's facing yet, if someone could help me with that too?)
Turing: | setscreen ("offscreenonly")
var acceleration, angle, car1, carR, x, y : int
angle := 0
x := 300
y := 300
drawfillbox (0, 0, 50, 100, black)
car1 := Pic.New (0, 0, 50, 100)
cls
var chars : array char of boolean
proc drawcar (x, y, angle : int)
carR := Pic.Rotate (car1, angle, 25, 50)
Pic.Draw (carR, x, y, picMerge)
Pic.Free (carR )
View.Update
cls
end drawcar
loop
Input.KeyDown (chars )
locate (1, 1)
if chars (KEY_UP_ARROW) then
y + = 1
elsif chars (KEY_RIGHT_ARROW) then
angle + = 1
elsif chars (KEY_LEFT_ARROW) then
angle - = 1
elsif chars (KEY_DOWN_ARROW) then
y - = 1
else
acceleration := 0
end if
drawcar (x, y, angle )
end loop
|
Please specify what version of Turing you are using
OpenTuring 1.0.1 |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Jeffmagma
|
Posted: Sat Dec 12, 2015 11:42 am Post subject: Re: Problems with picture commands |
|
|
I found out why the picture wasn't creating properly:
Does anybody know why the left half of the "car" is getting cut off, and how to make the car go towards the angle its facing?
EDIT: The RAM usage was actually NOT what was causing it to not work, i just needed to restart OpenTuring, but does anyone know why its using so much memory?
The program wasn't running when i took the screenshot |
|
|
|
|
|
Insectoid
|
Posted: Sat Dec 12, 2015 12:45 pm Post subject: RE:Problems with picture commands |
|
|
Every time you call Pic.Rotate, Turing creates a new image, but it doesn't delete the old ones. Turing can only hold a few hundred images at once (I don't remember the exact number). 'Illegal Picture ID 0' means your picture failed to load. In this case, it is because you have Pic.Rotate inside a loop, so Turing kept creating new images, and hit the maximum number of them. Since you had to many images, the new image failed to load, and that's where your error came from.
You can solve this in a number of ways. Pic.Free (picID) will delete an image from RAM. When you don't need an image any more, just Pic.Free it and you'll have space for a new one.
However, Pic.Free and Pic.Rotate are pretty slow and can make your program lag, so it might be better for you to pre-generate all rotations of your image before the game begins and store them in an array. This way you don't have to keep making new images, just pick the right one from the list you already created. Of course, this will keep a lot of images in RAM at once. Maybe you don't need one for every degree in a circle. Maybe every 3rd or 5th degree is close enough. |
|
|
|
|
|
Jeffmagma
|
Posted: Sat Dec 12, 2015 1:11 pm Post subject: RE:Problems with picture commands |
|
|
Every time I Pic.Rotate, I Pic.Free though... also for the memory problem when the program runs, it goes up at a steady pace of about 0.3 MB/s but if it not running, it stays completely the same (doesn't go down at all) |
|
|
|
|
|
Insectoid
|
Posted: Sat Dec 12, 2015 6:48 pm Post subject: RE:Problems with picture commands |
|
|
Oh, I didn't see that. Woops. It could be a bug in OpenTuring. Try it out on Turing 4.1 (available at the top of this page) and see if you still get the error. I can't find any issues with the code itself. |
|
|
|
|
|
|
|