201 lines
5.6 KiB
JavaScript
201 lines
5.6 KiB
JavaScript
// VIDEO KARAKTER - TEST CODE
|
|
// Uporabi video kot texture za player sprite
|
|
|
|
// METODA 1: VIDEO SPRITE KOT KARAKTER (ENOSTAVNO)
|
|
// ================================================
|
|
|
|
// V GameScene.js preload():
|
|
preload() {
|
|
// Load video
|
|
this.load.video('player_video', 'assets/videos/[IME_TVOJEGA_VIDEA].mp4');
|
|
}
|
|
|
|
// V GameScene.js create() - NAMESTO obstoječega playerja:
|
|
create() {
|
|
// ... existing code ...
|
|
|
|
// VIDEO PLAYER (namesto sprite)
|
|
const playerX = 400;
|
|
const playerY = 300;
|
|
|
|
// Create video
|
|
this.playerVideo = this.add.video(playerX, playerY, 'player_video');
|
|
this.playerVideo.setOrigin(0.5, 1); // Bottom center
|
|
this.playerVideo.setScale(0.5); // Adjust size
|
|
this.playerVideo.setDepth(100);
|
|
this.playerVideo.play(true); // Loop
|
|
|
|
// Store position for movement
|
|
this.playerPos = { x: 20, y: 20 }; // Grid position
|
|
|
|
// Camera follow video
|
|
this.cameras.main.startFollow(this.playerVideo);
|
|
}
|
|
|
|
// V GameScene.js update() - MOVEMENT:
|
|
update(time, delta) {
|
|
if (!this.playerVideo) return;
|
|
|
|
// WASD movement
|
|
const speed = 2;
|
|
let moved = false;
|
|
|
|
if (this.cursors.left.isDown || this.input.keyboard.addKey('A').isDown) {
|
|
this.playerPos.x -= speed * (delta / 16);
|
|
moved = true;
|
|
}
|
|
if (this.cursors.right.isDown || this.input.keyboard.addKey('D').isDown) {
|
|
this.playerPos.x += speed * (delta / 16);
|
|
moved = true;
|
|
}
|
|
if (this.cursors.up.isDown || this.input.keyboard.addKey('W').isDown) {
|
|
this.playerPos.y -= speed * (delta / 16);
|
|
moved = true;
|
|
}
|
|
if (this.cursors.down.isDown || this.input.keyboard.addKey('S').isDown) {
|
|
this.playerPos.y += speed * (delta / 16);
|
|
moved = true;
|
|
}
|
|
|
|
// Update video position (isometric)
|
|
if (moved) {
|
|
const screenPos = this.iso.toScreen(this.playerPos.x, this.playerPos.y);
|
|
this.playerVideo.setPosition(screenPos.x, screenPos.y);
|
|
}
|
|
}
|
|
|
|
// ================================================
|
|
// METODA 2: VIDEO TEXTURE (ADVANCED)
|
|
// ================================================
|
|
|
|
// V create():
|
|
create() {
|
|
// Create video (hidden)
|
|
const video = this.add.video(0, 0, 'player_video');
|
|
video.setVisible(false);
|
|
video.play(true);
|
|
|
|
// Create sprite using video as texture
|
|
this.player = this.add.sprite(400, 300, video);
|
|
this.player.setOrigin(0.5, 1);
|
|
this.player.setScale(0.5);
|
|
this.player.setDepth(100);
|
|
|
|
// Camera follow
|
|
this.cameras.main.startFollow(this.player);
|
|
}
|
|
|
|
// ================================================
|
|
// METODA 3: VIDEO + PHYSICS (COLLISION)
|
|
// ================================================
|
|
|
|
// V create():
|
|
create() {
|
|
// Create video player
|
|
this.playerVideo = this.add.video(400, 300, 'player_video');
|
|
this.playerVideo.setOrigin(0.5, 1);
|
|
this.playerVideo.setScale(0.5);
|
|
this.playerVideo.setDepth(100);
|
|
this.playerVideo.play(true);
|
|
|
|
// Add physics (for collision)
|
|
this.physics.add.existing(this.playerVideo);
|
|
this.playerVideo.body.setCollideWorldBounds(true);
|
|
|
|
// Camera follow
|
|
this.cameras.main.startFollow(this.playerVideo);
|
|
}
|
|
|
|
// V update() - Physics movement:
|
|
update(time, delta) {
|
|
if (!this.playerVideo) return;
|
|
|
|
const speed = 200;
|
|
|
|
// Reset velocity
|
|
this.playerVideo.body.setVelocity(0);
|
|
|
|
// WASD movement
|
|
if (this.cursors.left.isDown) {
|
|
this.playerVideo.body.setVelocityX(-speed);
|
|
}
|
|
if (this.cursors.right.isDown) {
|
|
this.playerVideo.body.setVelocityX(speed);
|
|
}
|
|
if (this.cursors.up.isDown) {
|
|
this.playerVideo.body.setVelocityY(-speed);
|
|
}
|
|
if (this.cursors.down.isDown) {
|
|
this.playerVideo.body.setVelocityY(speed);
|
|
}
|
|
}
|
|
|
|
// ================================================
|
|
// QUICK TEST (NAJHITREJŠI NAČIN)
|
|
// ================================================
|
|
|
|
// V GameScene.js create() - DODAJ NA KONEC:
|
|
// TEST: Video player
|
|
const testVideo = this.add.video(
|
|
this.cameras.main.centerX,
|
|
this.cameras.main.centerY,
|
|
'player_video'
|
|
);
|
|
testVideo.setOrigin(0.5);
|
|
testVideo.setScale(0.5); // Adjust size
|
|
testVideo.setDepth(1000); // Above everything
|
|
testVideo.play(true); // Loop
|
|
|
|
// Move with arrow keys
|
|
this.input.keyboard.on('keydown', (event) => {
|
|
const speed = 10;
|
|
if (event.key === 'ArrowLeft') testVideo.x -= speed;
|
|
if (event.key === 'ArrowRight') testVideo.x += speed;
|
|
if (event.key === 'ArrowUp') testVideo.y -= speed;
|
|
if (event.key === 'ArrowDown') testVideo.y += speed;
|
|
});
|
|
|
|
console.log('🎬 Video player test ready! Use arrow keys to move.');
|
|
|
|
// ================================================
|
|
// TIPS:
|
|
// ================================================
|
|
|
|
// 1. Video size:
|
|
testVideo.setDisplaySize(64, 64); // Fixed size
|
|
testVideo.setScale(0.5); // Scale
|
|
|
|
// 2. Video loop:
|
|
testVideo.setLoop(true); // Loop
|
|
testVideo.setLoop(false); // Play once
|
|
|
|
// 3. Video speed:
|
|
testVideo.setPlaybackRate(1.5); // 1.5x speed
|
|
testVideo.setPlaybackRate(0.5); // 0.5x speed
|
|
|
|
// 4. Video flip:
|
|
testVideo.setFlipX(true); // Flip horizontally
|
|
testVideo.setFlipY(true); // Flip vertically
|
|
|
|
// 5. Video alpha:
|
|
testVideo.setAlpha(0.8); // Semi-transparent
|
|
|
|
// 6. Video tint:
|
|
testVideo.setTint(0xff0000); // Red tint
|
|
|
|
// ================================================
|
|
// ZAMENJAJ IME VIDEA:
|
|
// ================================================
|
|
// 'player_video' -> ime tvojega MP4 filea (brez .mp4)
|
|
// Primer: če je file 'character.mp4', uporabi 'character'
|
|
|
|
// ================================================
|
|
// TESTING:
|
|
// ================================================
|
|
// 1. Zaženi igro
|
|
// 2. Vidiš video kot karakter
|
|
// 3. Premikaj z arrow keys ali WASD
|
|
// 4. Video se loopa
|
|
|
|
console.log('🎬 Video character test code ready!');
|