test animation
This commit is contained in:
@@ -39,13 +39,13 @@ import Layout from "../../layouts/Layout.astro";
|
||||
let firstLayer, secondLayer, thirdLayer;
|
||||
let graphics;
|
||||
let isDrawing = false;
|
||||
|
||||
// let hideButton;
|
||||
|
||||
function preload() {
|
||||
this.load.svg('letterA', '/assets/letter/a.svg');
|
||||
this.load.svg('layer1', '/assets/letter/a_l1.svg');
|
||||
this.load.svg('layer2', '/assets/letter/a_l2.svg');
|
||||
this.load.svg('layer3', '/assets/letter/a_l3.svg');
|
||||
this.load.svg('letterA', '/assets/capital-letter/a.svg');
|
||||
this.load.svg('layer1', '/assets/capital-letter/a_l1.svg');
|
||||
this.load.svg('layer2', '/assets/capital-letter/a_l2.svg');
|
||||
this.load.svg('layer3', '/assets/capital-letter/a_l3.svg');
|
||||
this.load.audio('slantLeft', '/assets/audio/slant-left.mp3');
|
||||
this.load.audio('slantRight', '/assets/audio/slant-right.mp3');
|
||||
this.load.audio('slide', '/assets/audio/slide.mp3');
|
||||
@@ -57,37 +57,32 @@ import Layout from "../../layouts/Layout.astro";
|
||||
function create() {
|
||||
this.add.image(customWidth / 2 * 1.6 - 0.5, 50, 'topLogo');
|
||||
this.add.text(customWidth / 10, 20, "Letter : A", { font: '700 40px quicksand', fill: '#05b3a4', });
|
||||
|
||||
const firstScreen = this.add.image(customWidth / 2, customHeight / 2, 'letterA');
|
||||
firstScreen.setVisible(false);
|
||||
|
||||
let hideButton = this.add.text(customWidth / 2, customHeight / 1.1, "Hide", { font: '24px quicksand', fill: '#05b3a4' });
|
||||
hideButton.setInteractive().on('pointerdown', () => {
|
||||
isDemoButtonClicked = false;
|
||||
firstScreen.setVisible(false);
|
||||
hideButton.setVisible(false); // Hide the "Hide" button
|
||||
demoButton.setVisible(true); // Show the "Demo" button
|
||||
});
|
||||
hideButton.setVisible(false);
|
||||
let demoButton = this.add.text(customWidth / 2, customHeight / 1.1, "Demo", { font: '24px quicksand', fill: '#05b3a4' });
|
||||
demoButton.setInteractive().on('pointerdown', () => {
|
||||
firstScreen.setVisible(true);
|
||||
demoButton.setVisible(false); // Hide the "Demo" button
|
||||
hideButton.setVisible(true); // Show the "Hide" button
|
||||
});
|
||||
|
||||
|
||||
const screenCenterX = this.cameras.main.worldView.x + this.cameras.main.width / 2;
|
||||
const baseFontSize = 20;
|
||||
const responsiveFontSize = (window.innerWidth / 480) * baseFontSize;
|
||||
const descrptText = this.add.text(screenCenterX, 90, 'Let`s learn to write letter : A', { font: `${responsiveFontSize}px quicksand`, fill: '#7c4c23', fontWeight : 'bold'}).setOrigin(0.5);
|
||||
const descrptText = this.add.text(screenCenterX, 90, 'Let`s learn how to write letter : A', { font: `${responsiveFontSize}px quicksand`, fill: '#7c4c23', fontWeight : 'bold'}).setOrigin(0.5);
|
||||
|
||||
this.time.delayedCall(2000, () => {
|
||||
this.tweens.add({
|
||||
targets: firstScreen,
|
||||
alpha: 0,
|
||||
scaleX: 0.5,
|
||||
scaleY: 0.5,
|
||||
duration: 1000,
|
||||
onComplete: () => {
|
||||
firstScreen.setVisible(false);
|
||||
firstScreen.setScale(1);
|
||||
showLayersWithFadeIn.call(this);
|
||||
}
|
||||
});
|
||||
}, [], this);
|
||||
}
|
||||
function showLayersWithFadeIn() {
|
||||
this.tweens.add({
|
||||
targets: [firstLayer, secondLayer, thirdLayer],
|
||||
alpha: 1,
|
||||
duration: 1000, // Duration of the tween in milliseconds
|
||||
delay: 500, // Delay before the fade-in starts
|
||||
ease: 'Power2', // Easing function (e.g., 'Linear', 'Cubic', 'Elastic', etc.)
|
||||
});
|
||||
|
||||
let textX, textY;
|
||||
let textX, textY;
|
||||
|
||||
firstLayer = this.add.image(customWidth / 2, customHeight / 2, 'layer1');
|
||||
textX = isMobile ? customWidth / 3 : customWidth * 0.75;
|
||||
@@ -176,7 +171,11 @@ import Layout from "../../layouts/Layout.astro";
|
||||
graphics.lineTo(pointer.x, pointer.y);
|
||||
graphics.strokePath();
|
||||
});
|
||||
|
||||
}
|
||||
// function showLayersWithFadeIn() {
|
||||
|
||||
// }
|
||||
|
||||
function update() {
|
||||
// Update any game logic if needed
|
||||
|
||||
112
src/pages/tracing/test2.astro
Normal file
112
src/pages/tracing/test2.astro
Normal file
@@ -0,0 +1,112 @@
|
||||
---
|
||||
import Layout from "../../layouts/Layout.astro";
|
||||
---
|
||||
<Layout title="Guided Letter Tracing Game">
|
||||
<main>
|
||||
<div>
|
||||
</div>
|
||||
<script is:inline src="/assets/js/phaser_3.60.0.js"></script>
|
||||
</main>
|
||||
</Layout>
|
||||
<script is:inline>
|
||||
const config = {
|
||||
type: Phaser.AUTO,
|
||||
width: window.innerWidth,
|
||||
height: window.innerHeight,
|
||||
backgroundColor: 0xFFFFFF,
|
||||
scale: {
|
||||
mode: Phaser.Scale.FIT,
|
||||
autoCenter: Phaser.Scale.CENTER_HORIZONTALLY,
|
||||
},
|
||||
scene: {
|
||||
preload: preload,
|
||||
create: create,
|
||||
}
|
||||
};
|
||||
|
||||
const game = new Phaser.Game(config);
|
||||
const customWidth = window.innerWidth;
|
||||
const customHeight = window.innerHeight;
|
||||
|
||||
function preload() {
|
||||
// Preload your assets here
|
||||
this.load.image('letterA', '/assets/capital-letter/a.svg');
|
||||
this.load.svg('handPointer', '/assets/svg/hand.svg')
|
||||
// Load other assets as needed
|
||||
}
|
||||
|
||||
function create() {
|
||||
const firstLayer = this.add.image(customWidth / 2, customHeight / 2, 'letterA');
|
||||
const secondLayer = this.add.image(customWidth / 2, customHeight / 2, 'letterA');
|
||||
const thirdLayer = this.add.image(customWidth / 2, customHeight / 2, 'letterA');
|
||||
const ball = this.add.sprite(customWidth / 2, customHeight / 2, 'handPointer');
|
||||
// ball.setVisible(false);
|
||||
const startHeight = customHeight /2 - 140; // Starting y position
|
||||
const endHeight = 567; // Ending y position
|
||||
const startWidth = customWidth / 2 + 20;
|
||||
const endWidth = customWidth / 2 - 65;
|
||||
|
||||
// ball.setOrigin(0.5, 0.5);
|
||||
ball.setScale(0.5); // Adjust scale as needed
|
||||
|
||||
// Define the bounce animation
|
||||
this.tweens.add({
|
||||
targets: ball,
|
||||
x: {
|
||||
getStart: () => startWidth,
|
||||
getEnd: () => endWidth,
|
||||
}, // End x position
|
||||
y: {
|
||||
getStart: () => startHeight,
|
||||
getEnd: () => endHeight,
|
||||
},
|
||||
duration: 3000, // Duration of each bounce
|
||||
ease: 'Sine.easeInOut',
|
||||
yoyo: false,
|
||||
repeat: -1 // -1 means it will repeat indefinitely
|
||||
});
|
||||
|
||||
// Set initial visibility and alpha values
|
||||
firstLayer.setVisible(true);
|
||||
secondLayer.setVisible(false);
|
||||
thirdLayer.setVisible(false);
|
||||
firstLayer.setAlpha(1);
|
||||
secondLayer.setAlpha(0.5);
|
||||
thirdLayer.setAlpha(0.5);
|
||||
|
||||
firstLayer.setInteractive({ draggable: true });
|
||||
|
||||
firstLayer.on('drag', (pointer, dragX, dragY) => {
|
||||
// Dragging logic
|
||||
|
||||
// const pointerX = ( pointer.x = 394);
|
||||
// const pointerY = (pointer.y = 139);
|
||||
// if(pointerX && pointerY){
|
||||
// console.log("Its start Position")
|
||||
// }
|
||||
if (pointer.isDown) {
|
||||
firstLayer.setAlpha(1);
|
||||
secondLayer.setAlpha(0.5);
|
||||
thirdLayer.setAlpha(0.5);
|
||||
|
||||
// console.log('its drag start', pointer.x, pointer.y)
|
||||
}
|
||||
console.log(pointer.x, pointer.y)
|
||||
});
|
||||
|
||||
firstLayer.on('dragend', (pointer) => {
|
||||
// Drag end logic
|
||||
firstLayer.setAlpha(0.5);
|
||||
const pointerX = (pointer.x = 309);
|
||||
const pointerY = (pointer.y = 390);
|
||||
|
||||
if(pointerX && pointerY){
|
||||
console.log("Its End Position")
|
||||
}
|
||||
// console.log(pointer.x, pointer.y)
|
||||
|
||||
// Add any actions you want to perform when drag ends here 394 139 / 309 390
|
||||
});
|
||||
}
|
||||
|
||||
</script>
|
||||
0
src/pages/tracing/test3.astro
Normal file
0
src/pages/tracing/test3.astro
Normal file
@@ -1,49 +1,193 @@
|
||||
<script is:inline src="/assets/js/phaser_3.60.0.js"></script>
|
||||
---
|
||||
import Layout from "../../layouts/Layout.astro";
|
||||
---
|
||||
<Layout title="Guided Letter Tracing Game">
|
||||
<main>
|
||||
<div>
|
||||
</div>
|
||||
<script is:inline src="/assets/js/phaser_3.60.0.js"></script>
|
||||
</main>
|
||||
</Layout>
|
||||
<script is:inline>
|
||||
const config = {
|
||||
type: Phaser.AUTO,
|
||||
width: 800,
|
||||
height: 600,
|
||||
scene: {
|
||||
preload: preload,
|
||||
create: create,
|
||||
update: update
|
||||
const isMobile = window.innerWidth <= 768;
|
||||
const drawingZone = {
|
||||
x: isMobile ? 0 : window.innerWidth / 4,
|
||||
y: window.innerHeight / 4,
|
||||
width: isMobile ? window.innerWidth : window.innerWidth / 2,
|
||||
height: window.innerHeight / 2,
|
||||
};
|
||||
|
||||
const config = {
|
||||
type: Phaser.AUTO,
|
||||
width: window.innerWidth,
|
||||
height: window.innerHeight,
|
||||
backgroundColor: 0xFFFFFF,
|
||||
scale: {
|
||||
mode: Phaser.Scale.FIT,
|
||||
autoCenter: Phaser.Scale.CENTER_HORIZONTALLY,
|
||||
},
|
||||
scene: {
|
||||
preload: preload,
|
||||
create: create,
|
||||
update: update
|
||||
}
|
||||
};
|
||||
|
||||
const game = new Phaser.Game(config);
|
||||
const customWidth = window.innerWidth;
|
||||
const customHeight = window.innerHeight;
|
||||
let firstLayer, secondLayer, thirdLayer;
|
||||
let isDragging = false;
|
||||
let lineStartPosition = {x:0 , y:0};
|
||||
let draggingLine;
|
||||
|
||||
function preload() {
|
||||
this.load.svg('letterA', '/assets/letter/a.svg');
|
||||
this.load.svg('layer1', '/assets/letter/a_l1.svg');
|
||||
this.load.svg('layer2', '/assets/letter/a_l2.svg');
|
||||
this.load.svg('layer3', '/assets/letter/a_l3.svg');
|
||||
this.load.audio('slantLeft', '/assets/audio/slant-left.mp3');
|
||||
this.load.audio('slantRight', '/assets/audio/slant-right.mp3');
|
||||
this.load.audio('slide', '/assets/audio/slide.mp3');
|
||||
this.load.image('topLogo', '/assets/top_logo.png');
|
||||
this.load.svg('succesImage', '/assets/svg/tick.svg');
|
||||
}
|
||||
};
|
||||
|
||||
const game = new Phaser.Game(config);
|
||||
|
||||
let graphics;
|
||||
let isDrawing = false;
|
||||
|
||||
function preload() {
|
||||
// Preload any assets if needed
|
||||
}
|
||||
|
||||
function create() {
|
||||
graphics = this.add.graphics();
|
||||
graphics.lineStyle(20, 0x05b3a4, 1); // Set line style (width, color, alpha)
|
||||
|
||||
this.input.on('pointerdown', function (pointer) {
|
||||
isDrawing = true;
|
||||
graphics.moveTo(pointer.x, pointer.y);
|
||||
});
|
||||
|
||||
this.input.on('pointerup', function () {
|
||||
isDrawing = false;
|
||||
});
|
||||
|
||||
this.input.on('pointermove', function (pointer) {
|
||||
if (!isDrawing) return;
|
||||
|
||||
graphics.lineTo(pointer.x, pointer.y);
|
||||
graphics.strokePath();
|
||||
});
|
||||
}
|
||||
|
||||
function update() {
|
||||
// You can add any game logic or updates here
|
||||
}
|
||||
|
||||
|
||||
function create() {
|
||||
this.add.image(customWidth / 2 * 1.6 - 0.5, 50, 'topLogo');
|
||||
this.add.text(customWidth / 10, 20, "Letter : A", { font: '700 40px quicksand', fill: '#05b3a4', });
|
||||
const firstScreen = this.add.image(customWidth / 2, customHeight / 2, 'letterA');
|
||||
const screenCenterX = this.cameras.main.worldView.x + this.cameras.main.width / 2;
|
||||
const baseFontSize = 20;
|
||||
const responsiveFontSize = (window.innerWidth / 480) * baseFontSize;
|
||||
const descrptText = this.add.text(screenCenterX, 90, 'Let`s learn to write letter : A', { font: `${responsiveFontSize}px quicksand`, fill: '#7c4c23', fontWeight : 'bold'}).setOrigin(0.5);
|
||||
|
||||
this.time.delayedCall(2000, () => {
|
||||
this.tweens.add({
|
||||
targets: firstScreen,
|
||||
alpha: 0,
|
||||
scaleX: 0.5,
|
||||
scaleY: 0.5,
|
||||
duration: 1000,
|
||||
onComplete: () => {
|
||||
firstScreen.setVisible(false);
|
||||
firstScreen.setScale(1);
|
||||
showLayersWithFadeIn.call(this);
|
||||
}
|
||||
});
|
||||
}, [], this);
|
||||
|
||||
draggingLine = this.add.graphics();
|
||||
draggingLine.lineStyle(10, 0x05b3a4).setDepth(1.5); //o\\ 5 is the line width, 0xff0000 is the color (red)
|
||||
}
|
||||
function showLayersWithFadeIn() {
|
||||
this.tweens.add({
|
||||
targets: [firstLayer, secondLayer, thirdLayer],
|
||||
alpha: 1,
|
||||
duration: 1000, // Duration of the tween in milliseconds
|
||||
delay: 500, // Delay before the fade-in starts
|
||||
ease: 'Power2', // Easing function (e.g., 'Linear', 'Cubic', 'Elastic', etc.)
|
||||
});
|
||||
let textX, textY;
|
||||
|
||||
firstLayer = this.add.image(customWidth / 2, customHeight / 2, 'layer1');
|
||||
textX = isMobile ? customWidth / 3 : customWidth * 0.75;
|
||||
textY = isMobile ? customHeight / 5 : customHeight / 2;
|
||||
const firstTextLayer = this.add.text(textX, textY, '1. Slant Left', { font: '700 40px quicksand', fill: '#05b3a4'});
|
||||
const slantLeftAudio = this.sound.add('slantLeft');
|
||||
slantLeftAudio.play();
|
||||
firstLayer.setDepth(1);
|
||||
firstLayer.setAlpha(0.5);
|
||||
firstLayer.setInteractive({ draggable: true });
|
||||
|
||||
secondLayer = this.add.image(customWidth / 2, customHeight / 2, 'layer2');
|
||||
textX = isMobile ? customWidth / 3 : customWidth * 0.75;
|
||||
const secondTextLayer = this.add.text(textX, textY, '2. Slant Right', { font: '700 40px quicksand', fill: '#05b3a4'});
|
||||
const slantRightAudio = this.sound.add('slantRight');
|
||||
secondTextLayer.setVisible(false);
|
||||
secondLayer.setDepth(1);
|
||||
secondLayer.setAlpha(0.5);
|
||||
secondLayer.setInteractive({ draggable: true });
|
||||
secondLayer.setVisible(false);
|
||||
|
||||
thirdLayer = this.add.image(customWidth / 2, customHeight / 2, 'layer3');
|
||||
textX = isMobile ? customWidth / 3 : customWidth * 0.75;
|
||||
const thirdTextLayer = this.add.text(textX, textY, '3. Slide', { font: '700 40px quicksand', fill: '#05b3a4'});
|
||||
const slideAudio = this.sound.add('slide');
|
||||
thirdTextLayer.setVisible(false);
|
||||
thirdLayer.setDepth(1.1);
|
||||
// thirdLayer.setScale(1.15);
|
||||
thirdLayer.setAlpha(0.5);
|
||||
thirdLayer.setInteractive({ draggable: true });
|
||||
thirdLayer.setVisible(false);
|
||||
|
||||
firstLayer.on('drag', (pointer) => {
|
||||
if (pointer.isDown) {
|
||||
firstTextLayer.setVisible(false);
|
||||
secondTextLayer.setVisible(true);
|
||||
slantRightAudio.play();
|
||||
secondLayer.setVisible(true);
|
||||
firstLayer.setAlpha(1);
|
||||
secondLayer.setAlpha(0.5);
|
||||
thirdLayer.setAlpha(0.5);
|
||||
} else {
|
||||
firstLayer.setAlpha(0.5);
|
||||
}
|
||||
});
|
||||
|
||||
secondLayer.on('drag', (pointer) => {
|
||||
if (pointer.isDown) {
|
||||
secondTextLayer.setVisible(false);
|
||||
thirdTextLayer.setVisible(true);
|
||||
slideAudio.play();
|
||||
thirdLayer.setVisible(true);
|
||||
secondLayer.setAlpha(1);
|
||||
thirdLayer.setAlpha(0.5);
|
||||
} else {
|
||||
secondLayer.setAlpha(0.5);
|
||||
}
|
||||
});
|
||||
|
||||
thirdLayer.on('drag', (pointer) => {
|
||||
if (pointer.isDown) {
|
||||
thirdLayer.setAlpha(1);
|
||||
thirdTextLayer.setVisible(false);
|
||||
// const succesImage = this.add.image(customWidth / 2, customHeight / 2, 'succesImage').setDepth(2);
|
||||
// succesImage.setAlpha(0.2);
|
||||
// this.add.text(customWidth / 2, customHeight / 2, 'OK', { font: '700 40px quicksand', fill: '#05b3a4'}).setDepth(2);
|
||||
} else {
|
||||
thirdLayer.setAlpha(0.5);
|
||||
}
|
||||
});
|
||||
this.input.on('pointerdown', dragStart);
|
||||
this.input.on('pointerup', dragEnd);
|
||||
this.input.on('pointermove', drag);
|
||||
}
|
||||
|
||||
function dragStart(pointer) {
|
||||
if (pointer.isDown) {
|
||||
isDragging = true;
|
||||
lineStartPosition.x = pointer.x;
|
||||
lineStartPosition.y = pointer.y;
|
||||
}
|
||||
}
|
||||
|
||||
function drag(pointer) {
|
||||
if (isDragging) {
|
||||
// draggingLine.clear();
|
||||
draggingLine.beginPath();
|
||||
draggingLine.moveTo(lineStartPosition.x, lineStartPosition.y);
|
||||
draggingLine.lineTo(pointer.x, pointer.y);
|
||||
draggingLine.strokePath();
|
||||
}
|
||||
}
|
||||
|
||||
function dragEnd() {
|
||||
isDragging = false;
|
||||
}
|
||||
|
||||
function update() {
|
||||
// Update any game logic if needed
|
||||
}
|
||||
</script>
|
||||
@@ -37,9 +37,9 @@ import Layout from "../../layouts/Layout.astro";
|
||||
const customWidth = window.innerWidth;
|
||||
const customHeight = window.innerHeight;
|
||||
let firstLayer, secondLayer, thirdLayer;
|
||||
let graphics;
|
||||
let isDrawing = false;
|
||||
|
||||
let isDragging = false;
|
||||
let lineStartPosition = {x:0 , y:0};
|
||||
let draggingLine;
|
||||
|
||||
function preload() {
|
||||
this.load.svg('letterA', '/assets/letter/a.svg');
|
||||
@@ -77,6 +77,9 @@ import Layout from "../../layouts/Layout.astro";
|
||||
}
|
||||
});
|
||||
}, [], this);
|
||||
|
||||
draggingLine = this.add.graphics();
|
||||
draggingLine.lineStyle(10, 0x05b3a4).setDepth(1.5); //o\\ 5 is the line width, 0xff0000 is the color (red)
|
||||
}
|
||||
function showLayersWithFadeIn() {
|
||||
this.tweens.add({
|
||||
@@ -86,8 +89,7 @@ import Layout from "../../layouts/Layout.astro";
|
||||
delay: 500, // Delay before the fade-in starts
|
||||
ease: 'Power2', // Easing function (e.g., 'Linear', 'Cubic', 'Elastic', etc.)
|
||||
});
|
||||
|
||||
let textX, textY;
|
||||
let textX, textY;
|
||||
|
||||
firstLayer = this.add.image(customWidth / 2, customHeight / 2, 'layer1');
|
||||
textX = isMobile ? customWidth / 3 : customWidth * 0.75;
|
||||
@@ -158,24 +160,31 @@ import Layout from "../../layouts/Layout.astro";
|
||||
thirdLayer.setAlpha(0.5);
|
||||
}
|
||||
});
|
||||
graphics = this.add.graphics();
|
||||
graphics.lineStyle(15, 0x05b3a4, 2).setDepth(2); // Set line style (width, color, alpha)
|
||||
this.input.on('pointerdown', dragStart);
|
||||
this.input.on('pointerup', dragEnd);
|
||||
this.input.on('pointermove', drag);
|
||||
}
|
||||
|
||||
this.input.on('pointerdown', function (pointer) {
|
||||
isDrawing = true;
|
||||
graphics.moveTo(pointer.x, pointer.y);
|
||||
});
|
||||
function dragStart(pointer) {
|
||||
if (pointer.isDown) {
|
||||
isDragging = true;
|
||||
lineStartPosition.x = pointer.x;
|
||||
lineStartPosition.y = pointer.y;
|
||||
}
|
||||
}
|
||||
|
||||
this.input.on('pointerup', function () {
|
||||
isDrawing = false;
|
||||
});
|
||||
function drag(pointer) {
|
||||
if (isDragging) {
|
||||
// draggingLine.clear();
|
||||
draggingLine.beginPath();
|
||||
draggingLine.moveTo(lineStartPosition.x, lineStartPosition.y);
|
||||
draggingLine.lineTo(pointer.x, pointer.y);
|
||||
draggingLine.strokePath();
|
||||
}
|
||||
}
|
||||
|
||||
this.input.on('pointermove', function (pointer) {
|
||||
if (!isDrawing) return;
|
||||
|
||||
graphics.lineTo(pointer.x, pointer.y);
|
||||
graphics.strokePath();
|
||||
});
|
||||
function dragEnd() {
|
||||
isDragging = false;
|
||||
}
|
||||
|
||||
function update() {
|
||||
|
||||
Reference in New Issue
Block a user