Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class spriteManip {
- constructor() {}
- function subSprite(element,style){
- let spriteW = 8;
- let spriteH = 8;
- let tokens = style.split(' ');
- let xPos = 0;
- let yPos = 0;
- let x = str.split(tokens,'px')[0];
- let y = str.split(tokens,'px')[0];
- xx = ['left','right','center'].indexOf(x);
- yy = ['top','bottom','middle'].indexOf(y);
- if((xx === -1) && (yy === -1))
- {[x,y]=[y,x];}
- xx = ['left','right','center'].indexOf(x);
- yy = ['top','bottom','middle'].indexOf(y);
- if((xx === -1) && (yy === -1))
- {return 0;}
- // Determine the x position in the sprite sheet
- if (x === 'left') {
- xPos = spriteW * 0;
- } else if (x === 'right') {
- xPos = spriteW * 2;
- } else if (x === 'center') {
- xPos = spriteW * 1;
- }
- // Determine the y position in the sprite sheet
- if (y === 'top') {
- yPos = spriteH * 0;
- } else if (y === 'bottom') {
- yPos = spriteH * 2;
- } else if (y === 'middle') {
- yPos = spriteH * 1;
- }
- // Set the background position of the element
- element.style.backgroundPosition = `${xPos}px ${yPos}px`;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement