|
|
Re: where to find code for stopping sprites from playing midplay
[Re: ncc1701d]
#305866
01/17/10 22:29
01/17/10 22:29
|
Joined: Sep 2003
Posts: 5,900 Bielefeld, Germany
Pappenheimer
Senior Expert
|
Senior Expert
Joined: Sep 2003
Posts: 5,900
Bielefeld, Germany
|
In case you mean sprites with +(any number here) at the end of its name, these sprites' animations are played with 'frame' and 'next_frame' instructions that you can find in the manual.
EDIT: The Online Tutorial (link at the left upper side) gets a chapter on 'Using Sprites' where it is explained how to animate sprites
Last edited by Pappenheimer; 01/17/10 22:39.
|
|
|
Re: where to find code for stopping sprites from playing midplay
[Re: Pappenheimer]
#305872
01/18/10 00:53
01/18/10 00:53
|
Joined: Dec 2009
Posts: 71
ncc1701d
OP
Junior Member
|
OP
Junior Member
Joined: Dec 2009
Posts: 71
|
right...I saw those tutorials and they help to a point. I am just not sure how to approach the problem solving of stopping it in midplay. Frame and next frame seem understandable. So like say I press a key on keyboard to stop it from playing what might the function say? Whats the thinking programatically and logically. Just looking for suggestions on how to approach problem with code or just the thought process.
Idea being to have playing a sprite and then when you press a key it stops when you press the key whatever frame it is on at the time. I wouldnt know the frame number in advance to stop it on.
Last edited by ncc1701d; 01/18/10 01:35.
|
|
|
Re: where to find code for stopping sprites from playing midplay
[Re: ncc1701d]
#305876
01/18/10 02:15
01/18/10 02:15
|
Joined: Jul 2008
Posts: 1,178 England
MrGuest
Serious User
|
Serious User
Joined: Jul 2008
Posts: 1,178
England
|
hey, if you're using the code from the sound, use
//press F1 for sound
//press F2 for anim
#include <acknex.h>
#include <default.c>
BMAP* bmp_explo = "explo+8.bmp";
ENTITY* ent_explo;
SOUND* snd_wav = "sound.wav";
void start_loop_while_key(int key, SOUND* sound){
var snd_temp;
snd_temp = snd_loop(sound, 100, 0);
while(key_pressed(key)){ wait(1); }
snd_stop(snd_temp);
}
void start_anim_while_key(int key, ENTITY* ent){
while(key_pressed(key)){
ent_explo.frame += time_step;
ent_explo.frame %= 9;
wait(1);
}
}
function key_down(key){
switch(key){
case 59:
start_loop_while_key(59, snd_wav);
break;
case 60:
start_anim_while_key(60, ent_explo);
break;
}
}
function main(){
on_anykey = key_down;
level_load(NULL);
ent_explo = ent_create("explo+8.bmp", vector(100, 0, 0), NULL);
ent_explo.roll = 0.001;
}
hope this helps
|
|
|
Re: where to find code for stopping sprites from playing midplay
[Re: MrGuest]
#305879
01/18/10 03:12
01/18/10 03:12
|
Joined: Sep 2003
Posts: 5,900 Bielefeld, Germany
Pappenheimer
Senior Expert
|
Senior Expert
Joined: Sep 2003
Posts: 5,900
Bielefeld, Germany
|
action sprite_anim_loop()
{
var frame_anim_speed = 0.8;
while (1)
{
if(key_s){frame_anim_speed = 0;}// use key S to stop the animation
if(key_a){frame_anim_speed = 0.8;}// use key A to keep it on playing from the last frame
my.frame += frame_anim_speed * time_step;
if (my.frame >= 30) my.frame -= 29;
wait (1);
}
}
|
|
|
Re: where to find code for stopping sprites from playing midplay
[Re: ncc1701d]
#306137
01/20/10 00:05
01/20/10 00:05
|
Joined: Jul 2008
Posts: 1,178 England
MrGuest
Serious User
|
Serious User
Joined: Jul 2008
Posts: 1,178
England
|
hey with the code you've got there, i had no errors at all make sure you've got an image that's of 8 images in width example herethe .roll = 0.001 makes the image face the camera hope this helps
|
|
|
Re: where to find code for stopping sprites from playing midplay
[Re: ncc1701d]
#306239
01/20/10 16:51
01/20/10 16:51
|
Joined: Jul 2008
Posts: 1,178 England
MrGuest
Serious User
|
Serious User
Joined: Jul 2008
Posts: 1,178
England
|
hey, if you're going to be creating unlimited sprites, you're best off creating each sprite as a new entity, then removing it on key release
action act_sprite(ENTITY* ent, int key){
while(key_pressed(key)){
ent.frame += time_step;
ent_explo.frame %= 9;
debug_var(ent_explo.frame);
wait(1);
}
ent_remove(ent);
}
void start_anim_while_key(int key, ENTITY* ent){
ENTITY* ent = ent_create("explo+8.bmp", nullvector, NULL);
act_sprite(ent, key);
}
otherwise if you've a set amount of sprites, you're best setting them visible, then invisible after release
void start_anim_while_key(int key, ENTITY* ent){
ent.frame = 1; //reset if needed
reset(ent, INVISIBLE);
while(key_pressed(key)){
ent.frame += time_step;
ent_explo.frame %= 9;
debug_var(ent_explo.frame);
wait(1);
set(ent, INVISIBLE);
}
|
|
|
Re: where to find code for stopping sprites from playing midplay
[Re: MrGuest]
#306264
01/20/10 21:05
01/20/10 21:05
|
Joined: Dec 2009
Posts: 71
ncc1701d
OP
Junior Member
|
OP
Junior Member
Joined: Dec 2009
Posts: 71
|
if I add yours into mine. Either of the options you provide I get debug_var debug_var undeclared identifier. Here is what it looks like.
#include <acknex.h> #include <default.c> #include <atypes.h>
BMAP* bmp_explo = "explo+8.bmp"; ENTITY* ent_explo;
////////////////////////////////////////////////////// void start_anim_while_key(int key, ENTITY* ent) {
ent.frame = 1; //reset if needed reset(ent, INVISIBLE); while(key_pressed(key)){ ent.frame += time_step; ent_explo.frame %= 9; debug_var(ent_explo.frame);//debug_var undeclared identifier wait(1); set(ent, INVISIBLE); } ///////////////////////////////////////////////////////////////////////////
function key_down(key) //captures ALL key presses { switch(key) { case 60: start_anim_while_key(60, ent_explo); break; } }
function main() { on_anykey = key_down;//tell any key press to call this function level_load(NULL);// ent_explo = ent_create("explo+8.bmp", vector(100, 0, 0), NULL); ent_explo.roll = 0.001;
}
Last edited by ncc1701d; 01/22/10 01:58.
|
|
|
|