Help needed with multiple sprites!
Author |
Message |
Emmie
|
Posted: Wed Jun 06, 2007 10:28 am Post subject: Help needed with multiple sprites! |
|
|
I have one sprite which the user controls and a monster sprite which is supposed to move on its own. They are completely different sprites but when the user moves their sprite, the monster sprite keeps thinking that it's being freed. The same basic code is being used for both of them so I'm not sure why the monster won't work. I think that the monster thinks the Sprite.Free is meant for it when it is meant for the user controlled sprite? Here is some of my code:
Turing: |
var numFrames : int := Pic.Frames ("kirby_right1.bmp")
var numFrames2 : int := Pic.Frames ("bear_left1.bmp")
var pics : array 1 .. numFrames of int
var pics2 : array 1 .. numFrames2 of int
var delayTime, delayTime2 : int
% Load the picture
Pic.FileNewFrames ("kirby_right1.bmp", pics, delayTime )
Pic.FileNewFrames ("bear_left1.bmp", pics2, delayTime2 )
% Create the sprite
var sprite : int
var bearsprite : int
sprite := Sprite.New (pics (1))
bearsprite := Sprite.New (pics2 (1))
process monster
if monsterstrt then
loop
delay (150)
Sprite.Free (bearsprite )
Pic.FileNewFrames ("bear_left" + intstr (ml ) + ".bmp", pics2, delayTime2 )
bearsprite := Sprite.New (pics2 (1))
Sprite.SetPosition (bearsprite, xm, ym , false)
Sprite.Show (bearsprite )
ml:=ml+ 1
if ml > 2 then
ml:= 1
end if
end loop
end if
end monster
loop
Sprite.SetPosition (sprite, xk, yk, false)
Sprite.Show (sprite )
monsterstrt:= true
fork monster
%^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
getch (userinput )
if chars (KEY_LEFT_ARROW) then
left:= true
right:= false
if safe_movel then
xk := xk - 10
end if
Sprite.Free (sprite )
Pic.FileNewFrames ("kirby_left" + intstr (l ) + ".bmp", pics, delayTime )
sprite := Sprite.New (pics (1))
Sprite.Show (sprite )
l:=l+ 1
if l > 6 then
l:= 1
end if
safe_mover := true
end if
|
Thanks guys! |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Mazer
|
Posted: Wed Jun 06, 2007 12:39 pm Post subject: RE:Help needed with multiple sprites! |
|
|
I'm having difficult trying to figure out just what the hell you're trying to do without causing myself pain. Some advice:
1) Use code tags (and make sure your code is indented). This makes people more willing to read your code.
2) Never create sprites in a loop like that. Create it ONCE at the beginning and use the same one inside the loop.
3) It's considered bad to use processes. I get the impression that you don't give a crap about programming "properly" so I'm not going to waste time talking about why; just know that most people who would help you will likely suggest that you not use them. |
|
|
|
|
|
Emmie
|
Posted: Thu Jun 07, 2007 8:18 am Post subject: Re: Help needed with multiple sprites! |
|
|
Thanks for number two. I didn't realize I had created my sprite inside the loop. I know it is bad to use processes, I've seen multiple people on this board give that advice. I'm just not sure how I can get the same "fork" effect without a process. And I do "give a crap about programming properly", this is just very rough. I'm trying to get the basics before I clean everything up. There is absolutely no need to be rude about it. |
|
|
|
|
|
|
|