|
Post by empardopo on May 12, 2024 19:28:03 GMT
Hola,
Tengo dos sprite (1 solo marco) en mi pantalla del tipo de patrulla horizontal. Ambos, se mueven muy rápido. ¿Es posible hacerlos más lentos?
Muchas gracias
Hi,
I have two sprite (1 only frame) in my screen of the type horizontal patrol. Both of them, are moving very fast. Is it possible to make them slower?
Thanks in advance
|
|
|
Post by flopping on May 12, 2024 21:10:58 GMT
Usa el comando ANIMATE con FAST, MEDIUM, SLOW y VERYSLOW.
You can use the command ANIMATE with FAST, MEDIUM, SLOW and VERYSLOW.
IF KEY RIGHT ANIMATE MEDIUM IF CANGORIGHT SPRITERIGHT ENDIF ENDIF
|
|
mas
Endorian Forest
![*](//storage.proboards.com/forum/images/stars/star.png) ![*](//storage.proboards.com/forum/images/stars/star.png)
Posts: 60
|
Post by mas on May 13, 2024 8:35:23 GMT
Hi Empardopo, are you actually trying to vary the speed they move left and right at? Probably I would setup a timing loop in main loop1 and trigger the sprites to move left or right on a certain part of the loop. In mainloop1 you'd have something like IF T > 25 LET T = 1 ELSE ADD 1 TO T ENDIF (to set up the timing loop) In your patrol sprites. Assuming you want them to advance every half a second. IF T = 12 LET SETTINGA = 1 ELSE LET SETTINGA = 0 ENDIF IF SETTINGA = 1 IF DIRECTION = LEFT IF CANGOLEFT SPRITELEFT ELSE LET DIRECTION = RIGHT EXIT ENDIF ELSE IF CANGORIGHT SPRITERIGHT ELSE LET DIRECTION = LEFT EXIT
ENDIF ENDIF You can obviously adjust the timing loop, or have the movement trigger on different parts of the loop. (I'm using SETTINGA here to indicate the sprite can move now) (Code always straight from my head and untested). Hope that helps. M
|
|
|
Post by empardopo on May 13, 2024 17:36:06 GMT
Hi Empardopo, are you actually trying to vary the speed they move left and right at? Probably I would setup a timing loop in main loop1 and trigger the sprites to move left or right on a certain part of the loop. In mainloop1 you'd have something like IF T > 25 LET T = 1 ELSE ADD 1 TO T ENDIF (to set up the timing loop) In your patrol sprites. Assuming you want them to advance every half a second. IF T = 12 LET SETTINGA = 1 ELSE LET SETTINGA = 0 ENDIF IF SETTINGA = 1 IF DIRECTION = LEFT IF CANGOLEFT SPRITELEFT ELSE LET DIRECTION = RIGHT EXIT ENDIF ELSE IF CANGORIGHT SPRITERIGHT ELSE LET DIRECTION = LEFT EXIT
ENDIF ENDIF You can obviously adjust the timing loop, or have the movement trigger on different parts of the loop. (I'm using SETTINGA here to indicate the sprite can move now) (Code always straight from my head and untested). Hope that helps. M Finally, I've solved my problem using your tip! Thanks! Main loop 1EVENT MAINLOOP1
ADD 1 TO T
IF T >= 25
SUBTRACT 25 FROM T
IF S > 0
SUBTRACT 1 FROM S
AT 0 19 DISPLAY SECONDS S
ELSE
KILL
ENDIF
ENDIF
IF B > 2
LET B = 1
ELSE
ADD 1 TO B
ENDIF
AT 0 14 DISPLAY B
IF KEY FIRE3
WHILE KEY FIRE3
ENDWHILE
WAITKEY
ENDIF Sprite Type 1
EVENT SPRITETYPE1
IF B = 2
LET SETTINGA = 1
ELSE
LET SETTINGA = 0
ENDIF
IF SETTINGA = 1
IF DIRECTION = LEFT
IF CANGOLEFT
SPRITELEFT
SUBTRACT 16 FROM X
IF CANGODOWN
LET DIRECTION = RIGHT
ENDIF
ADD 16 TO X
ELSE
LET DIRECTION = RIGHT
ENDIF
ELSE
IF CANGORIGHT
SPRITERIGHT
ADD 16 TO X
IF CANGODOWN
LET DIRECTION = LEFT
LET IMAGE = 1
LET FRAME = 0
ENDIF
SUBTRACT 16 FROM X
ELSE
LET DIRECTION = LEFT
LET IMAGE = 1
LET FRAME = 0
ENDIF
ENDIF
ENDIF
ANIMATE
IF COLLISION PLAYER
KILL
ENDIF
Thanks very much
|
|
|
Post by empardopo on May 13, 2024 17:37:50 GMT
Usa el comando ANIMATE con FAST, MEDIUM, SLOW y VERYSLOW. You can use the command ANIMATE with FAST, MEDIUM, SLOW and VERYSLOW. IF KEY RIGHT ANIMATE MEDIUM IF CANGORIGHT SPRITERIGHT ENDIF ENDIF Sorry, but using this the speed was the same. Thanks very much
|
|
|
Post by oss003 on May 13, 2024 20:06:25 GMT
ANIMATE just changes the animation speed. To adjust the moving speed jou have to have a counter and skip moving the sprite for a certain number of frames. This can be done with SETTINGA, something like this skips 2 frames:
EVENT SPRITETYPE1
ADD 1 TO SETTINGA
IF SETTINGA = 2 IF DIRECTION = LEFT IF CANGOLEFT SPRITELEFT SUBTRACT 16 FROM X IF CANGODOWN LET DIRECTION = RIGHT ENDIF ADD 16 TO X ELSE LET DIRECTION = RIGHT ENDIF ELSE IF CANGORIGHT SPRITERIGHT ADD 16 TO X IF CANGODOWN LET DIRECTION = LEFT LET IMAGE = 1 LET FRAME = 0 ENDIF SUBTRACT 16 FROM X ELSE LET DIRECTION = LEFT LET IMAGE = 1 LET FRAME = 0 ENDIF ENDIF LET SETTINGA 0 ENDIF
ANIMATE
IF COLLISION PLAYER KILL ENDIF
|
|
mas
Endorian Forest
![*](//storage.proboards.com/forum/images/stars/star.png) ![*](//storage.proboards.com/forum/images/stars/star.png)
Posts: 60
|
Post by mas on May 14, 2024 11:26:57 GMT
Glad you got there I like the other version though that Kees suggests above. In that you could trigger different speeds (possibly a "panic speed-up" trigger) In that code, it's just using SETTINGA in the individual sprite to count how much of a gap between steps. To have a panic - speed up (or slow down) you could set SETTINGB to hold how many cycles to wait before advancing -- this could lead to different speed baddies - probably initialise them with a DATA/READ based on the XY start location. But then you could have something like In the InitialiseSprite event IF TYPE = 1 LET SETTINGB = 25 ;; default would be move once a second ;; alternatively you could do a read / data / setup of different speeds for different baddies ENDIF
Then in the sprite event
ADD 1 TO SETTINGA IF SETTINGA > SETTINGB ;; all the movement stuff LET SETTINGA = 0 ENDIF IF S = 20 ; I see you're using S for seconds, so when less than 20 seconds SUBTRACT 12 FROM SETTINGB ENDIF IF S < 11 LET SETTINGB = 1 ENDIF
hope that makes sense - there are a lot of tweaks you can make to adjust it. With the code you posted - because you're using B to trigger the change, you're probably fine using just the SETTINGA setting as Kees suggests, which will free up B to be used for something else
M
|
|
|
Post by empardopo on May 15, 2024 19:12:58 GMT
Glad you got there I like the other version though that Kees suggests above. In that you could trigger different speeds (possibly a "panic speed-up" trigger) In that code, it's just using SETTINGA in the individual sprite to count how much of a gap between steps. To have a panic - speed up (or slow down) you could set SETTINGB to hold how many cycles to wait before advancing -- this could lead to different speed baddies - probably initialise them with a DATA/READ based on the XY start location. But then you could have something like In the InitialiseSprite event IF TYPE = 1 LET SETTINGB = 25 ;; default would be move once a second ;; alternatively you could do a read / data / setup of different speeds for different baddies ENDIF
Then in the sprite event
ADD 1 TO SETTINGA IF SETTINGA > SETTINGB ;; all the movement stuff LET SETTINGA = 0 ENDIF IF S = 20 ; I see you're using S for seconds, so when less than 20 seconds SUBTRACT 12 FROM SETTINGB ENDIF IF S < 11 LET SETTINGB = 1 ENDIF
hope that makes sense - there are a lot of tweaks you can make to adjust it. With the code you posted - because you're using B to trigger the change, you're probably fine using just the SETTINGA setting as Kees suggests, which will free up B to be used for something else
M
I've been with MPAGD for only a couple of days so I still don't understand this second code very well. I will go little by little. Thank you so much.
|
|
mas
Endorian Forest
![*](//storage.proboards.com/forum/images/stars/star.png) ![*](//storage.proboards.com/forum/images/stars/star.png)
Posts: 60
|
Post by mas on May 16, 2024 8:41:27 GMT
No worries at all. Always go at your own pace - it does look like you're picking things up fairly quickly which is good.
With the second code (Kees' code) the slow-down ticker had moved from being part of the timer loop to being attached to the spriteevent. (Sprites have a few variables that stay local to them, X,Y, SETTINGA, SETTINGB and DIRECTION being the most common).
By having the sprite increment SETTINGA and trigger its own movement delay means that that global variables (the A-Z single characters) would be freed for other things.
Once you have the spriteevent controlling its own speed, you can use a second variable (in my example the SETTINGB) to vary the delay based on certain conditions - such as nearing a time limit or an object behing held etc. You can also, later, start using DATA blocks to help give some sort of individuality to each of the movements of the patrol sprites (I believe minilop's tutorials cover this later on - using DATA blocks to change the behavious of sprites or control other aspects of the game is definitely a "game changer"
Good luck, you're doing well for having only used MPAGD for a few days. It is a simple enough system, but it can do quite powerful things and does allow for a lot of tinkering and extending.
M.
|
|
|
Post by oss003 on May 16, 2024 18:43:56 GMT
Ok, I added some remarks to make the code more readable. This code is executed for every sprite type 1 so every sprite type 1 has its own variable SETTINGA. Next code is executed every frame which is normally 25 times per second.
EVENT SPRITETYPE1
ADD 1 TO SETTINGA ; Increment spritevariable which acts as a framecounter
IF SETTINGA = 2 ; Check if 2 frames are skipped, if not then skip next code IF DIRECTION = LEFT ; Check if sprite is moving left IF CANGOLEFT ; Sprite is moving left, check if sprite can go 2 pixels left SPRITELEFT ; Yes, so move sprite 2 pixels left SUBTRACT 16 FROM X ; Check spriteposition 16 pixels to the left for end of platform IF CANGODOWN ; If there is no platform or wallblock downwards LET DIRECTION = RIGHT ; Then change direction ENDIF ADD 16 TO X ; Restore spriteposition to original position ELSE LET DIRECTION = RIGHT ; If sprite cannot go left, change direction to RIGHT ENDIF ELSE IF CANGORIGHT ; Sprite is moving right, check if sprite can go 2 pixels right SPRITERIGHT ; Yes, so move sprite 2 pixels right ADD 16 TO X ; Check spriteposition 16 pixels to the right for end of platform IF CANGODOWN ; If there is no platform or wallblock downwards LET DIRECTION = LEFT ; Then change direction LET IMAGE = 1 ; Change sprite image LET FRAME = 0 ; Reset animation to frame 0 ENDIF SUBTRACT 16 FROM X ; Restore spriteposition to original position ELSE LET DIRECTION = LEFT ; If sprite is moving left LET IMAGE = 1 ; Change sprite image?? Same image as moving right???? LET FRAME = 0 ; Reset animation to frame 0 ENDIF ENDIF LET SETTINGA 0 ; Reset spritevariable because the next 2 frames must be skipped ENDIF
ANIMATE
IF COLLISION PLAYER ; If sprite hits player KILL ; Kill sprite ENDIF
I made a remark because I think the code is not correct.
- LET IMAGE = 1 When changing the direction from RIGHT to LEFT, you change the sprite image to 1 This is also done when changing the direction from LEFT to RIGHT so the sprite image is the same for moving left and moving right. To be consistent, add lines LET IMAGE = 1 and LET FRAME = 0 also after the 2 lines LET DIRECTION = RIGHT If you have different images for left and right, change the according LET IMAGE lines.
|
|