This site requires JavaScript, please enable it in your browser!
Greenfoot back
Gingervitis
Gingervitis wrote ...

2015/6/19

Speed question

1
2
Gingervitis Gingervitis

2015/6/19

#
The speed of my game does not change at all and I'm not sure exactly why. Could there be a stack overflow occurring? I would supply my code but I have done so much it would be hard to find where any possible error could be at the moment.
danpost danpost

2015/6/19

#
By what mechanism of changing the speed are you experiencing this issue? Do you use 'Greenfoot.setSpeed' or 'Greenfoot.delay' anywhere, and if so, where (show the methods)? Do you use a lot of animations or image manipulations? Are you employing a scrolling system of any type? Any and all of these could be potential problems. However, no suggestions for improvement can be given without more information.
Gingervitis Gingervitis

2015/6/21

#
danpost wrote...
By what mechanism of changing the speed are you experiencing this issue? Do you use 'Greenfoot.setSpeed' or 'Greenfoot.delay' anywhere, and if so, where (show the methods)? Do you use a lot of animations or image manipulations? Are you employing a scrolling system of any type? Any and all of these could be potential problems. However, no suggestions for improvement can be given without more information.
I use a lot of animations in my game. At any given time at least one actor is being animated, if not more than one actor.
danpost danpost

2015/6/21

#
Gingervitis wrote...
I use a lot of animations in my game. At any given time at least one actor is being animated, if not more than one actor.
Make sure you 'setImage' the images only when changed (not every act). In other words, avoid something like this:
1
2
timer = (timer+1)%(frameCount*frameActs);
setImage(images[timer/frameActs]);
and use something like this:
1
2
timer = (timer+1)%(frameCount*frameActs);
if (timer%frameActs == 0) setImage(images[timer/frameActs]);
The 'if' condition on the last line allows the image to be set only when the frame is to be changed (so we are not continually setting the same image until the change occurs).
Gingervitis Gingervitis

2015/6/21

#
@danpost I'm a little confused with this code. My original code was:
1
setImage(imgs[i%16]);
Where 'i' increases when actors make contact. How do I implement the 'frame','frameCount' and 'frameActs' variables to this. I understand 'frameActs' would be 16 and 'frame' would be 'i' but I'm confused with 'frameCount'. What should its initial value be at and does that value ever change?
danpost danpost

2015/6/21

#
NVM. Let me re-think this about what you have shown.
Gingervitis Gingervitis

2015/6/21

#
Shouldn't the image always change for every time acted? With a delay wouldn't the image appear to 'lag' while changing?
danpost danpost

2015/6/21

#
Okay, yes. 'frameActs' is 16. 'i' is not 'frame'; but, instead 'i' is timer. The limit you set on 'i' is the product of the number of frames in your animation and 16, the number of acts per frame ('frameActs'). This is what I am showing in my line 1 with '%(frameCount*frameActs)', limiting the value of 'timer'.
danpost danpost

2015/6/21

#
Gingervitis wrote...
Shouldn't the image always change for every time acted? With a delay wouldn't the image appear to 'lag' while changing?
A scenario running at normal speed (speed slider near the middle) runs at somewhere between 50 and 60 acts per second. This is like three times or more faster than the eye is capable of picking up changes at. If you change the image every act cycle, all you would see would be a flickering blur of an image. Old motion picture projectors show frames at a rate of 24 frames per second, which produce a fluid motion to the eye. So allowing each frame to remain for 5 to 10 act cycles would smooth out the flicker.
Gingervitis Gingervitis

2015/6/21

#
Okay this is making a little more sense but what would 'frameCount' be if 'frameActs' is the number of images being used in the animation?
danpost danpost

2015/6/21

#
No. 'frameCount' is the number of images used in the animation, not 'frameActs' (which is the number of act cycles each frame persists for -- acts per frame).
Gingervitis Gingervitis

2015/6/21

#
danpost wrote...
No. 'frameCount' is the number of images used in the animation, not 'frameActs' (which is the number of act cycles each frame persists for -- acts per frame).
OHH! OK. then 'frameActs', with what you described above, would be between 5 and 10?
Gingervitis Gingervitis

2015/6/21

#
This is making the game really glitchy and not all animations are being shown. Here is my method where it is being animated. (I also have other actor being animated but I will change those class after one is working fine)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
public void act()
    {
        health(); 
        if(isAttacking()&&!round.isCompleted())
        {
            timer= (timer+1)%(16*10);
            if (timer%10 == 0) setImage(imgs[timer/16]);          
            if(timer==imgs.length-1)
                //timer=0;           
            damage();
        }
        else if(round.isCompleted())move(1);
 
        if(getX()>=1695)getWorld().removeObject(this);
 
        else if(isTouching(EnemyDamageField.class)){
            hb.subtract(1);
        }
        despawn();
    }
danpost danpost

2015/6/21

#
Gingervitis wrote...
OHH! OK. then 'frameActs', with what you described above, would be between 5 and 10?
You would give it a value that would give the best look to the animation. There still is the factor of your scenario speed. The greater the speed of the scenario, the greater value you would give 'frameActs'. This should not be too much of an issue provided you are not changing the scenario speed within the project itself.
danpost danpost

2015/6/21

#
Gingervitis wrote...
This is making the game really glitchy and not all animations are being shown. Here is my method where it is being animated. (I also have other actor being animated but I will change those class after one is working fine) < Code Omitted>
Change '16' on line 7 to '10'. Also, change line 8 to this:
1
if(timer == 0)
You may also want to set attacking to false when taking damage within the 'if' block of line 8.
There are more replies on the next page.
1
2