Gamestudio Links
Zorro Links
Newest Posts
loading historical data 1st time
by AndrewAMD. 04/14/23 12:54
Trade at bar open
by juanex. 04/13/23 19:43
Bug in Highpass2 filter
by rki. 04/13/23 09:54
Adding Limit Orders For IB
by scatters. 04/11/23 16:16
FisherN
by rki. 04/11/23 08:38
AUM Magazine
Latest Screens
SHADOW (2014)
DEAD TASTE
Tactics of World War I
Hecknex World
Who's Online Now
2 registered members (Quad, AndrewAMD), 1,007 guests, and 6 spiders.
Key: Admin, Global Mod, Mod
Newest Members
rki, FranzIII, indonesiae, The_Judge, storrealba
18919 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
where to find code for stopping sprites from playing midplay? #305862
01/17/10 21:58
01/17/10 21:58
Joined: Dec 2009
Posts: 71
N
ncc1701d Offline OP
Junior Member
ncc1701d  Offline OP
Junior Member
N

Joined: Dec 2009
Posts: 71
Hi all,
currently you can use code like

"snd_stop" to stop sounds in middle of their playing.
What types of code can be used to stop sprites from playing in midplay? media_stop doesnt seem the like the solution from what I read. What type of code should I look for in manual to assist me?
thanks

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 Offline
Senior Expert
Pappenheimer  Offline
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
N
ncc1701d Offline OP
Junior Member
ncc1701d  Offline OP
Junior Member
N

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
M
MrGuest Offline
Serious User
MrGuest  Offline
Serious User
M

Joined: Jul 2008
Posts: 1,178
England
hey, if you're using the code from the sound, use
Code:
//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 Offline
Senior Expert
Pappenheimer  Offline
Senior Expert

Joined: Sep 2003
Posts: 5,900
Bielefeld, Germany
Code:
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: MrGuest] #306034
01/19/10 07:20
01/19/10 07:20
Joined: Dec 2009
Posts: 71
N
ncc1701d Offline OP
Junior Member
ncc1701d  Offline OP
Junior Member
N

Joined: Dec 2009
Posts: 71
I tryed this below having removed the sound parts assuming it should work without the sound part. ...but the acknex engine crashes all the time I try to run it. I am also not sure what the ent_explo.roll line at the end is supposed to be doing?
Should what I have worked? I do have the bmp in my directory and I have also tryed it with .tga but still crashes.



#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)
{
while(key_pressed(key))
{
ent_explo.frame += time_step;
ent_explo.frame %= 9;//dont exceed the number of frames

wait(1);
}
}


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;

}

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
M
MrGuest Offline
Serious User
MrGuest  Offline
Serious User
M

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 here

the .roll = 0.001 makes the image face the camera

hope this helps

Re: where to find code for stopping sprites from playing midplay [Re: MrGuest] #306166
01/20/10 09:17
01/20/10 09:17
Joined: Dec 2009
Posts: 71
N
ncc1701d Offline OP
Junior Member
ncc1701d  Offline OP
Junior Member
N

Joined: Dec 2009
Posts: 71
ok my bad. My .c file had to many characters in it. I renamed it and everything worked. I have to watch that.
One thing I noticed though is after I let up on the key is the sprite is still there. The intent was to have it disapear like the sound did. I guess my poor choice of words. The sprite has to vanish not just stop upon release of key. Given what I want to do, would you recommned I experiment with flags INVISIBLE and SHOW to do what I want? I have tryed that already with close but no cigar results. Maybe you have a suggestion for alternative or is INVIS etc the right direction to move.
thanks for your help so far.

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
M
MrGuest Offline
Serious User
MrGuest  Offline
Serious User
M

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
Code:
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
Code:
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
N
ncc1701d Offline OP
Junior Member
ncc1701d  Offline OP
Junior Member
N

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.
Page 1 of 2 1 2

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1