3D grafikler ve gelişmiş animasyonlar yaratmak, tipik olarak HTML, CSS ve JavaScript'in temel yeteneklerinin ötesinde daha karmaşık araçlar ve kütüphaneler gerektirir. Örneğin, 3D grafikler için genellikle WebGL, Three.js veya Babylon.js gibi kütüphaneler kullanılır.
Aşağıda, Three.js ile basit bir 3D sahne ve HTML/CSS ile animasyonlu bir başlat butonu ile bir giriş menüsü demo tasarlayacağım. Bu sadece başlangıç düzeyinde olacak ve daha fazla geliştirme gerektirebilir:
Kaynak Dosyaları
İlk olarak, Three.js kütüphanesini projeye eklememiz gerekecek. Bunu bir CDN üzerinden yapabiliriz.
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script>
HTML
HTML yapımızı basit bir menü ve oynatma düğmesi ekleyerek düzenleyelim.
<!DOCTYPE html>
<html lang="tr">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>ANA KARAKTER</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div id="menu">
<h1 class="animated-title">ANA KARAKTER</h1>
<button id="startButton" class="animated-button" onclick="startGame()">Başlat</button>
</div>
<div id="3dScene"></div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script>
<script src="script.js"></script>
</body>
</html>
CSS
3D sahneyi ve animasyonları CSS ile tanımlayalım.
body, html {
margin: 0;
padding: 0;
overflow: hidden;
height: 100%;
font-family: 'Arial', sans-serif;
background-color: #1e1e24;
}
#menu {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
text-align: center;
z-index: 10;
color: #fff;
background-color: rgba(0, 0, 0, 0.5);
padding: 20px;
border-radius: 8px;
}
.animated-title {
font-size: 3em;
color: #ff6347;
animation: glow 1.5s ease-in-out infinite alternate;
}
.animated-button {
margin-top: 20px;
padding: 15px 30px;
border: none;
background-color: #ff6347;
color: white;
font-size: 1.2em;
cursor: pointer;
border-radius: 5px;
transition: transform 0.3s ease, background-color 0.3s ease;
}
.animated-button:hover {
background-color: #e5533d;
transform: scale(1.1);
}
#3dScene {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
@keyframes glow {
from { text-shadow: 0 0 10px #ff6347, 0 0 20px #ff6347, 0 0 30px #ff6347; }
to { text-shadow: 0 0 20px #ff8c69, 0 0 30px #ff8c69, 0 0 40px #ff8c69; }
}
JavaScript
Three.js ile basit bir 3D sahne ayarlayalım. Örnek olarak dönen bir küre ekleyeceğim.
function startGame() {
document.getElementById('menu').style.display = 'none';
init3DScene();
}
function init3DScene() {
const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
const renderer = new THREE.WebGLRenderer();
renderer.setSize(window.innerWidth, window.innerHeight);
document.getElementById('3dScene').appendChild(renderer.domElement);
const geometry = new THREE.SphereGeometry(1, 32, 32);
const material = new THREE.MeshBasicMaterial({ color: 0x7f8c8d, wireframe: true });
const sphere = new THREE.Mesh(geometry, material);
scene.add(sphere);
camera.position.z = 5;
function animate() {
requestAnimationFrame(animate);
sphere.rotation.x += 0.01;
sphere.rotation.y += 0.01;
renderer.render(scene, camera);
}
animate();
}
// Dinamik pencere boyutuna göre sahneyi güncelle
window.addEventListener('resize', function() {
const width = window.innerWidth;
const height = window.innerHeight;
renderer.setSize(width, height);
camera.aspect = width / height;
camera.updateProjectionMatrix();
});
Bu örnek, basit ve başlangıç düzeyinde bir 3D sahne ve menü tasarımıdır. Daha karmaşık 3D nesneler ve sahneler oluşturmak için Three.js'nin daha ileri düzey özelliklerini incelemekte fayda var. Ayrıca, daha iyi grafikler için 3D modelleme yazılımları (Blender, Maya vb.) kullanabilir ve burada oluşturulan modelleri Three.js sprite ve mesh'leri ile entegre edebilirsiniz.