I want to create a video player from another stack and set autoplay.
I have created the object "player" in stack 1. To create a player in stack 2, I click on a button.
This is the code in the button:
set the filename of player "Player" of card "object" to "myurl"
copy player "Player" of card "object" to stack "stack2"
This code is working. But the player doesn't autoplay.
You just need to start the player after copying it.
set the filename of player "Player" of card "object" to "myurl"
copy player "Player" of card "object" to stack "stack2"
put the number of players of card "object" of stack "stack2" into myNumberOfPlayers
start player myNumberOfPlayers of card "object" of stack "stack2"
Sometimes it may be a good idea to send the play command after finishing the handler:
set the filename of player "Player" of card "object" to "myurl"
copy player "Player" of card "object" to stack "stack2"
put the number of players of card "object" of stack "stack2" into myNumberOfPlayers
send "startPlayer myNumberOfPlayer" to me in 0 millisecs
on startPlayer thePlayerNumber
start player thePlayerNumber of cd "object" of stack "stack2"
end startPlayer
It might also be a good idea to set the filename after copying it:
copy player "Player" of card "object" to stack "stack2"
put the number of players of card "object" of stack "stack2" into myNumberOfPlayers
set the filename of player myNumberOfPlayer of card "object" of stack "stack2" to "myurl"
send "startPlayer myNumberOfPlayer" to me in 0 millisecs
on startPlayer thePlayerNumber
start player thePlayerNumber of card "object" of stack "stack2"
end startPlayer
If you want to start playing the player control automatically when the card opens, just put the start player command into an openCard handler in the card script of card "object" of stack "stack2":
on openCard
put the number of players into myNumberOfPlayers
if myNumberOfPlayers > 0 then
start player myNumberOfPlayers
end if
end openCard
Related
I'm making a tower defense game in bevy and I'm having problems with placing a tower. So basically I want to make it so that when you click one of the buttons (each one spawns a different tower) an asset/sprite of the tower should follow your mouse and when the mouse is clicked AGAIN it should spawn the tower.
Currently my program registers the button click, but it goes into 2 ifs so when the button is clicked it automatically spawns a tower somewhere (not even below the button) without waiting for the user to click again. So the Interaction::Clicked only checks if the button was clicked, but doesn't grab the mouse click event, it only reads it so therefore if the mouse is clicked for a longer period of time (human click) the code will go into the second if and spawn the tower (I don't know why it spawns it where it is on the picture below). How can I fix this? Picture:
Towers spawning in some random place. First button spawns them at around (200, 0, 0)
Code:
fn tower_button_interaction(
mut commands: Commands,
windows: Res<Windows>,
mouse: Res<Input<MouseButton>>,
assets: Res<GameAssets>,
interaction: Query<(&Interaction, &TowerType), Changed<Interaction>>
) {
let window = windows.get_primary().unwrap();
for (interaction, tower_type) in &interaction {
match interaction {
Interaction::Clicked => {
info!("Spawning: {tower_type} wizard");
// Upon clicking the mouse, spawn the selected tower on the map
if mouse.just_pressed(MouseButton::Left) {
if let Some(position) = window.cursor_position() {
spawn_tower(&mut commands, *tower_type, &assets, position.extend(0.));
}
}
}
Interaction::Hovered => {}
Interaction::None => {}
}
}
}
I also tried changing the if mouse.just_pressed(MouseButton::Left) to if matches!(interaction, Interaction::Clicked), but the same thing happened.
i have made a cannon shooting game for two player, the aim is to break the castle down and then try to land the cannon ball onto the opponent but the problem is idk how to write code to show who has won the game when the game is over and all i know is that the code will need to written in the game over section & I am new to code as well
void CMyGame::OnUpdate()
{
if (m_mode == MODE_SHOOT)
{
/////////////////////////////////////////////////
// this code will only be executed while shooting
// TODO: 1. Add the gravitation
m_ball.Accelerate(0, -8);
// TODO: 2. Check if cannon hit? game over?
if (m_ball.HitTest(m_cannons[1 - m_turn]))
{
GameOver();
}
// TODO: 3. Check if the ball is outside the screen. Test the following cases:
// - ball to the left of the screen
if (m_ball.GetX() < 0)
NextTurn();
// - ball to the right of the screen (screen width = 800)
if (m_ball.GetX() > 800)
NextTurn();
// - ball below the screen
if (m_ball.GetY() < 0)
NextTurn();
// TODO: 4. Check if the ball hit the castle?
for each (CSprite * pSprite in m_castle)
{
if (m_ball.HitTest(pSprite))
NextTurn();
}
}
// Check if the castle has taken damage
for (CSprite* pSprite : m_castle)
{
if (m_ball.HitTest(pSprite))
pSprite->Delete();
}
m_castle.delete_if(deleted);
// Update the ball's position
m_ball.Update(GetTime());
the part i need help on is how to write code that will show who has won the game
// called when Game is Over
void CMyGame::OnGameOver()
{
m_cannons[1 - m_turn]->SetImage("fire");
m_mode = MODE_GAMEOVER;
}
Hard to say without seeing the rest of your code and info on how your game works, but you can follow something like this:
Assuming you can check when a cannon lands somewhere and can track the % hit points of each player (which I believe you can do considering you have gravity planned in your given code):
Write a function which is called each time a cannon ball lands, check if the ball has dealt the final blow on the opponent's character. From what you say, you probably do not need to do this check until the castle has been broken down. So something along the lines of if(!castleBroken) {return;} at the start of the function would only check the opponent's HP if the castle is broken (again, assuming that the opponent can only take damage if the castle is broken). Here, castleBroken is a bool which starts as false and becomes true when the cannon has broken the opponent's castle.
This is a similar idea to a Tic-Tac-Toe game I wrote in the past, where after each move, I would check the board state. If the game was over, the game over screen would be printed with the winner declared, or in some cases, a draw.
I'm new to gdscript trying make 2D platformer game in godot3,I'm able to instance a fire scene when the Player node enters the area2D which is im using as field of vision but the scene only instantiate once.How do we keep instancing the fire scene till the player is within the field of vision (Area2D)?
My GDscript :
#monster.gd
func _on_field_of_detection_body_entered(body):#signal passed from Area2D
if body.name == "Player": # When field of detection detect the player it load the fire.tscn scene.
var fir = fire.instance()
fir.set_global_position($fireposition.get_global_position())
get_parent().add_child(fir)
This is a jwplayer case. I have a website with music album pages. Right now I have a jwplayer playing a playlist and works fine, but I want to have a table listing all the songs by track number and a play icon that plays the song on the first of each line. So far I managed to create a play icon that plays the full playlist but no luck on how to create as many icons as the number of songs and that each plays a different song from the playlist.
This is a representation of what I want to do
play icon (song 1) | track number | title song 1 | duration
play icon (song 2) | track number | title song 2 | duration
The current code I have is this, which creates a single play icon that plays the playlist. This code, by the way is pretty awesome as it plays next song automatically and controls the pause/play of the main player. This website runs on joomla.
<script>
var playerInstance = jwplayer('container');
playerInstance.setup({
playlist: [{
//DYNAMICALLY GENERATED PLAYLIST
<?php
$album_id = $this->item->id;
// Get default database object
$db = JFactory::getDbo();
// Get a new JDatabaseQuery object
$query = $db->getQuery(true);
$query = 'SELECT position, name, length, filename FROM XXX WHERE `album_id` = ' . $db->quote( (int) $album_id ) . ' ORDER BY `num` ASC LIMIT 0 , 30';
$db->setQuery($query);
$results = $db -> loadAssocList();
foreach($results as $row){
echo "file: \"/". htmlentities($row['filename']). "\", ";
echo "title: \"". htmlentities($row['name']). "\"";
echo "},{";
}
?> }]
//END DYNAMICALLY GENERATED PLAYLIST
controls: false
});
playerInstance.on('play', function() {
document.getElementById("videoPlayPause").style.backgroundPosition = "-263px -70px";
});
playerInstance.on('pause', function() {
document.getElementById("videoPlayPause").style.backgroundPosition = "-287px -70px";
});
</script>
<br/>
<div class="videoPlayerControls playing" id="videoPlayerControls">
<button id="videoPlayPause" onclick="playerInstance.play();" onmouseout="if(playerInstance.getState() == "IDLE" || playerInstance.getState() == "PAUSED"){document.getElementById("videoPlayPause").style.backgroundPosition = "-62px 0";} if(playerInstance.getState() == "PLAYING"){document.getElementById("videoPlayPause").style.backgroundPosition = "-62px -50px";}" onmouseover="if(playerInstance.getState() == "PLAYING"){document.getElementById("videoPlayPause").style.backgroundPosition = "-263px -70px";}if(playerInstance.getState() == "IDLE" || playerInstance.getState() == "PAUSED"){document.getElementById("videoPlayPause").style.backgroundPosition = "-287px -70px";}" type="button">Play/Pause</button>
Anyone has done something like this?
In JavaScript, you just need to load the URL of the file you want to play into the player, like this.
<script>
jwplayer('yourPlayerDivId').setup({
file: 'track1.mp4'
});
</script>
Given you have a loaded playlist, you can access (play) any item in the playlist directly using the playerInstance.playlistItem(index) method.
This starts playback of the playlist item at the specified index - bearing in mind that the first item in the playlist would have an index of 0.
You should therefore be able to attach a click event to each corresponding 'Play Icon' which calls this method with an incremented index in order to access the associated playlist item.
BTW: Since JW7 the playerInstance.getState() reports the state as a lowercase string...
I want to set width and height of my video player.
Here my code.
put the text of fld "txt_width" into w_value
put the text of fld "txt_height" into h_value
set the width of player ID idplayer of stack stackname to w_value
set the height of player ID idplayer of stack stackname to h_value
And I set autoplay on opencard.Before autoplay video.Width and Height is working.After opencard and video play.Width and Height of video is resize to original.
How do I do ?
Try setting the lockLocation of the player object to true to stop the player resizing automatically;
set the lockLocation of player id idPlayer to true