minor adjustments
This commit is contained in:
@@ -1,117 +0,0 @@
|
||||
/*
|
||||
# _____ ____ ___
|
||||
# | \/ ____| |___|
|
||||
# | | | \ | |
|
||||
#-----------------------------------------------------------------------
|
||||
# Copyright 2022-2023, tyra - https://github.com/h4570/tyra
|
||||
# Licensed under Apache License 2.0
|
||||
# Guido Diego Quispe Robles
|
||||
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
|
||||
*/
|
||||
|
||||
#include "fontSprite.hpp"
|
||||
|
||||
namespace Tyra{
|
||||
|
||||
const int charSize = 96;
|
||||
|
||||
const int font_char[charSize]{
|
||||
' ', '!', '"', ' ', '$', '%', ' ', '´', '(', ')', ' ', '+', ',', '-', '.', '/',
|
||||
'0', '1', '2', '3', '4', '5', '6', '2', '8', '9', ':', ';', '“', '=', '”', '?',
|
||||
' ', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
|
||||
'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', ' ', ' ', ' ', ' ', ' ',
|
||||
' ', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
|
||||
'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '[', '♪', ']', '~', ' '
|
||||
};
|
||||
|
||||
const int font_charWidth[charSize] {
|
||||
0, 1, 3, 0, 5, 9, 0, 9, 3, 3, 0, 5, 2, 2, 1, 4,
|
||||
4, 2, 4, 4, 5, 4, 4, 4, 4, 4, 1, 2, 4, 5, 4, 4,
|
||||
0, 6, 5, 5, 5, 4, 4, 5, 5, 1, 4, 5, 4, 7, 5, 5,
|
||||
5, 5, 5, 5, 5, 5, 6, 7, 5, 5, 4, 0, 0, 0, 0, 0,
|
||||
0, 5, 4, 4, 4, 4, 3, 4, 4, 1, 2, 4, 1, 7, 4, 4,
|
||||
4, 4, 3, 4, 3, 4, 5, 7, 4, 4, 4, 2, 5, 2, 6, 0,
|
||||
};
|
||||
|
||||
Font::Font(){ }
|
||||
|
||||
|
||||
void Font::LoadFont(TextureRepository& repository, Renderer2D* renderer){
|
||||
renderer2D = renderer;
|
||||
|
||||
float height = 16.0F;
|
||||
float width = 16.0F;
|
||||
|
||||
all_font.mode = MODE_REPEAT;
|
||||
all_font.size = Vec2(255,127);
|
||||
|
||||
auto filepath = FileUtils::fromCwd("earthbound-Font.png");
|
||||
auto* texture = repository.add(filepath);
|
||||
texture->addLink(all_font.id);
|
||||
|
||||
int column = 0;
|
||||
int arrow = 0;
|
||||
|
||||
for(int i=0; i < 96; i++){
|
||||
font[i].id = all_font.id;
|
||||
font[i].mode = MODE_REPEAT;
|
||||
font[i].size = Vec2(width,height);
|
||||
font[i].offset = Vec2(width*column,height*arrow);
|
||||
column++;
|
||||
if(column == 16){
|
||||
arrow++;
|
||||
column = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Font::FreeFont(TextureRepository& repository){
|
||||
repository.freeBySprite(all_font);
|
||||
for(int i=0;i<96;i++){ repository.freeBySprite(font[i]); }
|
||||
}
|
||||
|
||||
void Font::DrawText(const char* text, int x, int y, Color color){
|
||||
DrawText(std::string(text),x,y,color);
|
||||
}
|
||||
|
||||
void Font::DrawText(const std::string& text, int x, int y, Color color){
|
||||
int sizeText = text.size();
|
||||
|
||||
int offsetY = 0;
|
||||
int offsetX = 0;
|
||||
|
||||
Sprite spr_font;
|
||||
int pos_font;
|
||||
|
||||
for (int i = 0; i < sizeText; i++)
|
||||
{
|
||||
pos_font = text[i];
|
||||
spr_font = font[0];
|
||||
|
||||
for(int j=0; j < charSize; j++){
|
||||
if(pos_font == font_char[j]){
|
||||
pos_font = j;
|
||||
spr_font = font[j];
|
||||
spr_font.color = color;
|
||||
spr_font.position = Vec2(x + offsetX, y + offsetY);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (pos_font == '\n')
|
||||
{
|
||||
offsetY += 18;
|
||||
offsetX = 0.0f;
|
||||
}else{
|
||||
if ((pos_font != ' ') && (pos_font != '\t')){
|
||||
renderer2D->render(spr_font);
|
||||
offsetX += font_charWidth[pos_font] + 2;
|
||||
}else{
|
||||
offsetX += 2;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Tyra
|
||||
@@ -0,0 +1,109 @@
|
||||
/*
|
||||
# _____ ____ ___
|
||||
# | \/ ____| |___|
|
||||
# | | | \ | |
|
||||
#-----------------------------------------------------------------------
|
||||
# Copyright 2022-2023, tyra - https://github.com/h4570/tyra
|
||||
# Licensed under Apache License 2.0
|
||||
# Guido Diego Quispe Robles
|
||||
*/
|
||||
|
||||
#include "font_sprite.hpp"
|
||||
|
||||
namespace Tyra {
|
||||
|
||||
const int Font::chars[FONT_CHAR_SIZE]{
|
||||
' ', '!', '"', ' ', '$', '%', ' ', '{', '(', ')', ' ', '+', ',', '-',
|
||||
'.', '/', '0', '1', '2', '3', '4', '5', '6', '2', '8', '9', ':', ';',
|
||||
'<', '=', '>', '?', ' ', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I',
|
||||
'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
|
||||
'X', 'Y', 'Z', ' ', ' ', ' ', ' ', ' ', ' ', 'a', 'b', 'c', 'd', 'e',
|
||||
'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's',
|
||||
't', 'u', 'v', 'w', 'x', 'y', 'z', '[', '}', ']', '~', ' '};
|
||||
|
||||
const int Font::charWidths[FONT_CHAR_SIZE]{
|
||||
0, 1, 3, 0, 5, 9, 0, 9, 3, 3, 0, 5, 2, 2, 1, 4, 4, 2, 4, 4, 5, 4, 4, 4,
|
||||
4, 4, 1, 2, 4, 5, 4, 4, 0, 6, 5, 5, 5, 4, 4, 5, 5, 1, 4, 5, 4, 7, 5, 5,
|
||||
5, 5, 5, 5, 5, 5, 6, 7, 5, 5, 4, 0, 0, 0, 0, 0, 0, 5, 4, 4, 4, 4, 3, 4,
|
||||
4, 1, 2, 4, 1, 7, 4, 4, 4, 4, 3, 4, 3, 4, 5, 7, 4, 4, 4, 2, 5, 2, 6, 0,
|
||||
};
|
||||
|
||||
Font::Font() {}
|
||||
|
||||
void Font::load(TextureRepository& repository, Renderer2D* renderer) {
|
||||
renderer2D = renderer;
|
||||
|
||||
float height = 16.0F;
|
||||
float width = 16.0F;
|
||||
|
||||
allFont.mode = MODE_REPEAT;
|
||||
allFont.size = Vec2(255, 127);
|
||||
|
||||
auto filepath = FileUtils::fromCwd("earthbound-Font.png");
|
||||
auto* texture = repository.add(filepath);
|
||||
texture->addLink(allFont.id);
|
||||
|
||||
int column = 0;
|
||||
int arrow = 0;
|
||||
|
||||
for (int i = 0; i < FONT_CHAR_SIZE; i++) {
|
||||
font[i].id = allFont.id;
|
||||
font[i].mode = MODE_REPEAT;
|
||||
font[i].size = Vec2(width, height);
|
||||
font[i].offset = Vec2(width * column, height * arrow);
|
||||
column++;
|
||||
|
||||
if (column == 16) {
|
||||
arrow++;
|
||||
column = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Font::free(TextureRepository& repository) {
|
||||
repository.freeBySprite(allFont);
|
||||
for (int i = 0; i < FONT_CHAR_SIZE; i++) {
|
||||
repository.freeBySprite(font[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void Font::drawText(const char* text, const int& x, const int& y, Color color) {
|
||||
drawText(std::string(text), x, y, color);
|
||||
}
|
||||
|
||||
void Font::drawText(const std::string& text, const int& x, const int& y,
|
||||
Color color) {
|
||||
int sizeText = text.size();
|
||||
|
||||
int offsetY = 0;
|
||||
int offsetX = 0;
|
||||
|
||||
for (int i = 0; i < sizeText; i++) {
|
||||
int fontPos = text[i];
|
||||
Sprite fontSpr = font[0];
|
||||
|
||||
for (int j = 0; j < FONT_CHAR_SIZE; j++) {
|
||||
if (fontPos == chars[j]) {
|
||||
fontPos = j;
|
||||
fontSpr = font[j];
|
||||
fontSpr.color = color;
|
||||
fontSpr.position = Vec2(x + offsetX, y + offsetY);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (fontPos == '\n') {
|
||||
offsetY += 18;
|
||||
offsetX = 0.0f;
|
||||
} else {
|
||||
if ((fontPos != ' ') && (fontPos != '\t')) {
|
||||
renderer2D->render(fontSpr);
|
||||
offsetX += charWidths[fontPos] + 2;
|
||||
} else {
|
||||
offsetX += 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Tyra
|
||||
@@ -6,7 +6,6 @@
|
||||
# Copyright 2022-2023, tyra - https://github.com/h4570/tyra
|
||||
# Licensed under Apache License 2.0
|
||||
# Guido Diego Quispe Robles
|
||||
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
|
||||
*/
|
||||
|
||||
#include "engine.hpp"
|
||||
@@ -15,7 +14,8 @@
|
||||
/**
|
||||
* In this tutorial we will learn:
|
||||
* - How works the offset of the sprite
|
||||
* - how works the texture mapping
|
||||
* - How works the texture mapping
|
||||
* - How to write text (font)
|
||||
*/
|
||||
|
||||
int main() {
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
# Copyright 2022-2023, tyra - https://github.com/h4570/tyra
|
||||
# Licensed under Apache License 2.0
|
||||
# Guido Diego Quispe Robles
|
||||
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
|
||||
*/
|
||||
|
||||
#include <tyra>
|
||||
@@ -14,21 +13,23 @@
|
||||
|
||||
namespace Tyra {
|
||||
|
||||
Tutorial10::Tutorial10(Engine* t_engine) : engine(t_engine), pad(&t_engine->pad){ }
|
||||
Tutorial10::Tutorial10(Engine* t_engine)
|
||||
: padTimer(0), engine(t_engine), pad(&t_engine->pad) {}
|
||||
|
||||
Tutorial10::~Tutorial10() {
|
||||
engine->renderer.getTextureRepository().freeBySprite(sprite);
|
||||
engine->renderer.getTextureRepository().freeBySprite(spriteFlip);
|
||||
engine->renderer.getTextureRepository().freeBySprite(spriteScale);
|
||||
engine->renderer.getTextureRepository().freeBySprite(spriteStrech);
|
||||
font.FreeFont(engine->renderer.getTextureRepository());
|
||||
engine->renderer.getTextureRepository().freeBySprite(spriteStretch);
|
||||
font.free(engine->renderer.getTextureRepository());
|
||||
}
|
||||
|
||||
void Tutorial10::init() {
|
||||
engine->renderer.setClearScreenColor(Color(32.0F, 32.0F, 32.0F));
|
||||
|
||||
/** Load all the sprites of the sprite sheet. */
|
||||
font.LoadFont(engine->renderer.getTextureRepository(),&engine->renderer.renderer2D);
|
||||
font.load(engine->renderer.getTextureRepository(),
|
||||
&engine->renderer.renderer2D);
|
||||
|
||||
/** Sprite contains rectangle information. */
|
||||
loadSprite();
|
||||
@@ -40,129 +41,150 @@ void Tutorial10::init() {
|
||||
textureFilter = TyraNearest;
|
||||
|
||||
engine->renderer.core.renderer2D.setTextureMappingType(textureFilter);
|
||||
|
||||
}
|
||||
|
||||
void Tutorial10::loop() {
|
||||
auto& renderer = engine->renderer;
|
||||
|
||||
/** Change the texture filtering of the texture.
|
||||
*
|
||||
*
|
||||
* The options are:
|
||||
* TyraNearest (Point Sampling):
|
||||
* uses the color of the texel closest to the pixel center for the pixel color.
|
||||
*
|
||||
* uses the color of the texel closest to the pixel center for the pixel
|
||||
* color.
|
||||
*
|
||||
* TyraLinear (Bilinear Sampling):
|
||||
* the four nearest texels to the pixel center are sampled
|
||||
* and their colors are combined by weighted average according to distance.
|
||||
*
|
||||
*
|
||||
* By default it is linear.
|
||||
*/
|
||||
*/
|
||||
|
||||
renderer.core.renderer2D.setTextureMappingType(textureFilter);
|
||||
|
||||
if(engine->pad.getClicked().Cross){
|
||||
textureFilter = TyraNearest;
|
||||
}else if(engine->pad.getClicked().Circle){
|
||||
textureFilter = TyraLinear;
|
||||
}
|
||||
|
||||
static int timer = 0;
|
||||
handlePad();
|
||||
|
||||
/** Move the offset of the sprites.
|
||||
*
|
||||
* The offset of the sprite need to be equal or greater to zero
|
||||
* or a graphical error occurs.
|
||||
*
|
||||
* And the sum of the sprite size and the offset must be less than 1024
|
||||
* or a graphical error occurs.
|
||||
*
|
||||
* Sum with repeat mode:
|
||||
* Max = sprite.size + sprite.offset.
|
||||
*
|
||||
* Sum with strecth mode:
|
||||
* Max = original size of the image + sprite.offset.
|
||||
*
|
||||
* If it continues moving past these values
|
||||
* in a moment it will return to normal but
|
||||
* the error will be repeated with another value.
|
||||
*/
|
||||
|
||||
if(timer <= 0){
|
||||
if(pad->getLeftJoyPad().v <= 100){ //up
|
||||
sprite.offset -= Vec2(0,16);
|
||||
spriteFlip.offset -= Vec2(0,16);
|
||||
spriteScale.offset -= Vec2(0,16);
|
||||
spriteStrech.offset -= Vec2(0,16); timer = 20;
|
||||
printf("offset: %f,%f\n",sprite.offset.x,sprite.offset.y);
|
||||
}else if(pad->getLeftJoyPad().v >= 200 ){ //down
|
||||
sprite.offset += Vec2(0,16);
|
||||
spriteFlip.offset += Vec2(0,16);
|
||||
spriteScale.offset += Vec2(0,16);
|
||||
spriteStrech.offset += Vec2(0,16); timer = 20;
|
||||
printf("offset: %f,%f\n",sprite.offset.x,sprite.offset.y);
|
||||
}
|
||||
|
||||
if (pad->getLeftJoyPad().h <= 100) { // left
|
||||
sprite.offset -= Vec2(16,0);
|
||||
spriteFlip.offset -= Vec2(16,0);
|
||||
spriteScale.offset -= Vec2(16,0);
|
||||
spriteStrech.offset -= Vec2(16,0); timer = 20;
|
||||
printf("offset: %f,%f\n",sprite.offset.x,sprite.offset.y);
|
||||
} else if (pad->getLeftJoyPad().h >= 200 ) { //right
|
||||
sprite.offset += Vec2(16,0);
|
||||
spriteFlip.offset += Vec2(16,0);
|
||||
spriteScale.offset += Vec2(16,0);
|
||||
spriteStrech.offset += Vec2(16,0); timer = 20;
|
||||
printf("offset: %f,%f\n",sprite.offset.x,sprite.offset.y);
|
||||
}
|
||||
|
||||
}else{
|
||||
timer--;
|
||||
}
|
||||
|
||||
/** Begin frame will clear our screen. */
|
||||
renderer.beginFrame();
|
||||
|
||||
/** Render sprite. */
|
||||
renderer.renderer2D.render(sprite);
|
||||
renderer.core.renderer2D.setTextureMappingType(TyraLinear);
|
||||
renderer.renderer2D.render(spriteFlip);
|
||||
renderer.renderer2D.render(spriteFlip);
|
||||
renderer.core.renderer2D.setTextureMappingType(textureFilter);
|
||||
renderer.renderer2D.render(spriteScale);
|
||||
renderer.renderer2D.render(spriteStrech);
|
||||
renderer.renderer2D.render(spriteStretch);
|
||||
|
||||
font.DrawText("tests with sprite sheet",(512/2)-60,10,Color(255,255,255));
|
||||
font.DrawText("Press Cross for nearest filter",(512/2)-70,50,Color(255,255,255));
|
||||
font.DrawText("Press Circle for linear filter",(512/2)-65,70,Color(255,255,255));
|
||||
font.DrawText("Use left stick for move the offsets of the sprites",(512/2)-110,90,Color(255,255,255));
|
||||
font.DrawText("sprite 32x32\n scaled x3",sprite.position.x+16,sprite.position.y-40,Color(255,255,255));
|
||||
font.DrawText("sprite 32x32\nscaled x3 with flip",spriteFlip.position.x+4,spriteFlip.position.y-40,Color(255,255,255));
|
||||
font.DrawText("sprite 96x96 with\n repeat mode",spriteScale.position.x+6,spriteScale.position.y-40,Color(255,255,255));
|
||||
font.DrawText("sprite 96x96 with\n stretch mode",spriteStrech.position.x+6,spriteStrech.position.y-40,Color(255,255,255));
|
||||
|
||||
if(textureFilter == TyraLinear){ str_filter = "Filter: Linear";}
|
||||
else{ str_filter = "Filter: Nearest";}
|
||||
font.drawText("tests with sprite sheet", (512 / 2) - 60, 10,
|
||||
Color(255, 255, 255));
|
||||
font.drawText("Press Cross for nearest filter", (512 / 2) - 70, 50,
|
||||
Color(255, 255, 255));
|
||||
font.drawText("Press Circle for linear filter", (512 / 2) - 65, 70,
|
||||
Color(255, 255, 255));
|
||||
font.drawText("Use left stick for move the offsets of the sprites",
|
||||
(512 / 2) - 110, 90, Color(255, 255, 255));
|
||||
font.drawText("sprite 32x32\n scaled x3", sprite.position.x + 16,
|
||||
sprite.position.y - 40, Color(255, 255, 255));
|
||||
font.drawText("sprite 32x32\nscaled x3 with flip", spriteFlip.position.x + 4,
|
||||
spriteFlip.position.y - 40, Color(255, 255, 255));
|
||||
font.drawText("sprite 96x96 with\n repeat mode", spriteScale.position.x + 6,
|
||||
spriteScale.position.y - 40, Color(255, 255, 255));
|
||||
font.drawText("sprite 96x96 with\n stretch mode",
|
||||
spriteStretch.position.x + 6, spriteStretch.position.y - 40,
|
||||
Color(255, 255, 255));
|
||||
|
||||
static int posX1 = sprite.position.x + 16;
|
||||
static int posX2 = spriteFlip.position.x + 16;
|
||||
static int posX3 = spriteStrech.position.x + 16;
|
||||
static int posX4 = spriteScale.position.x + 16;
|
||||
if (textureFilter == TyraLinear) {
|
||||
strFilter = "Filter: Linear";
|
||||
} else {
|
||||
strFilter = "Filter: Nearest";
|
||||
}
|
||||
|
||||
static int posY1 = sprite.position.y + (sprite.size.y * sprite.scale) + 16;
|
||||
static int posY2 = spriteFlip.position.y + (spriteFlip.size.y * spriteFlip.scale) + 16;
|
||||
static int posY3 = spriteStrech.position.y + (spriteStrech.size.y * spriteStrech.scale) + 16;
|
||||
static int posY4 = spriteScale.position.y + (spriteScale.size.y * spriteScale.scale) + 16;
|
||||
int posX1 = sprite.position.x + 16;
|
||||
int posX2 = spriteFlip.position.x + 16;
|
||||
int posX3 = spriteStretch.position.x + 16;
|
||||
int posX4 = spriteScale.position.x + 16;
|
||||
|
||||
font.DrawText(str_filter,posX1,posY1,Color(255,255,255));
|
||||
font.DrawText("Filter: Linear",posX2,posY2,Color(255,255,255));
|
||||
font.DrawText(str_filter,posX3,posY3,Color(255,255,255));
|
||||
font.DrawText(str_filter,posX4,posY4,Color(255,255,255));
|
||||
int posY1 = sprite.position.y + (sprite.size.y * sprite.scale) + 16;
|
||||
int posY2 =
|
||||
spriteFlip.position.y + (spriteFlip.size.y * spriteFlip.scale) + 16;
|
||||
int posY3 = spriteStretch.position.y +
|
||||
(spriteStretch.size.y * spriteStretch.scale) + 16;
|
||||
int posY4 =
|
||||
spriteScale.position.y + (spriteScale.size.y * spriteScale.scale) + 16;
|
||||
|
||||
font.drawText(strFilter, posX1, posY1, Color(255, 255, 255));
|
||||
font.drawText("Filter: Linear", posX2, posY2, Color(255, 255, 255));
|
||||
font.drawText(strFilter, posX3, posY3, Color(255, 255, 255));
|
||||
font.drawText(strFilter, posX4, posY4, Color(255, 255, 255));
|
||||
|
||||
/** End frame will perform vsync. */
|
||||
renderer.endFrame();
|
||||
}
|
||||
|
||||
void Tutorial10::handlePad() {
|
||||
if (engine->pad.getClicked().Cross) {
|
||||
textureFilter = TyraNearest;
|
||||
} else if (engine->pad.getClicked().Circle) {
|
||||
textureFilter = TyraLinear;
|
||||
}
|
||||
|
||||
/** Move the offset of the sprites.
|
||||
*
|
||||
* The offset of the sprite need to be equal or greater to zero
|
||||
* or a graphical error occurs.
|
||||
*
|
||||
* And the sum of the sprite size and the offset must be less than 1024
|
||||
* or a graphical error occurs.
|
||||
*
|
||||
* Sum with repeat mode:
|
||||
* Max = sprite.size + sprite.offset.
|
||||
*
|
||||
* Sum with strecth mode:
|
||||
* Max = original size of the image + sprite.offset.
|
||||
*
|
||||
* If it continues moving past these values
|
||||
* in a moment it will return to normal but
|
||||
* the error will be repeated with another value.
|
||||
*/
|
||||
|
||||
if (padTimer <= 0) {
|
||||
if (pad->getLeftJoyPad().v <= 100) { // up
|
||||
sprite.offset -= Vec2(0, 16);
|
||||
spriteFlip.offset -= Vec2(0, 16);
|
||||
spriteScale.offset -= Vec2(0, 16);
|
||||
spriteStretch.offset -= Vec2(0, 16);
|
||||
padTimer = 20;
|
||||
printf("New offset: %f,%f\n", sprite.offset.x, sprite.offset.y);
|
||||
} else if (pad->getLeftJoyPad().v >= 200) { // down
|
||||
sprite.offset += Vec2(0, 16);
|
||||
spriteFlip.offset += Vec2(0, 16);
|
||||
spriteScale.offset += Vec2(0, 16);
|
||||
spriteStretch.offset += Vec2(0, 16);
|
||||
padTimer = 20;
|
||||
printf("New offset: %f,%f\n", sprite.offset.x, sprite.offset.y);
|
||||
}
|
||||
|
||||
if (pad->getLeftJoyPad().h <= 100) { // left
|
||||
sprite.offset -= Vec2(16, 0);
|
||||
spriteFlip.offset -= Vec2(16, 0);
|
||||
spriteScale.offset -= Vec2(16, 0);
|
||||
spriteStretch.offset -= Vec2(16, 0);
|
||||
padTimer = 20;
|
||||
printf("New offset: %f,%f\n", sprite.offset.x, sprite.offset.y);
|
||||
} else if (pad->getLeftJoyPad().h >= 200) { // right
|
||||
sprite.offset += Vec2(16, 0);
|
||||
spriteFlip.offset += Vec2(16, 0);
|
||||
spriteScale.offset += Vec2(16, 0);
|
||||
spriteStretch.offset += Vec2(16, 0);
|
||||
padTimer = 20;
|
||||
printf("New offset: %f,%f\n", sprite.offset.x, sprite.offset.y);
|
||||
}
|
||||
|
||||
} else {
|
||||
padTimer--;
|
||||
}
|
||||
}
|
||||
|
||||
void Tutorial10::loadSprite() {
|
||||
const auto& screenSettings = engine->renderer.core.getSettings();
|
||||
|
||||
@@ -173,9 +195,10 @@ void Tutorial10::loadSprite() {
|
||||
/** Let's scale it down */
|
||||
sprite.size = Vec2(32.0F, 32.0F);
|
||||
sprite.scale = 3;
|
||||
|
||||
|
||||
/** Set the position */
|
||||
sprite.position = Vec2(offset,screenSettings.getHeight() / 2.0F - sprite.size.y / 2.0F);
|
||||
sprite.position =
|
||||
Vec2(offset, screenSettings.getHeight() / 2.0F - sprite.size.y / 2.0F);
|
||||
|
||||
spriteFlip.mode = SpriteMode::MODE_REPEAT;
|
||||
|
||||
@@ -186,19 +209,25 @@ void Tutorial10::loadSprite() {
|
||||
|
||||
spriteFlip.scale = 3;
|
||||
|
||||
spriteFlip.position = Vec2(((offset*2) + (32.0F*3)),screenSettings.getHeight() / 2.0F - sprite.size.y / 2.0F);
|
||||
spriteFlip.position =
|
||||
Vec2(((offset * 2) + (32.0F * 3)),
|
||||
screenSettings.getHeight() / 2.0F - sprite.size.y / 2.0F);
|
||||
|
||||
spriteScale.mode = SpriteMode::MODE_REPEAT;
|
||||
|
||||
spriteScale.size = Vec2(96.0F,96.0F);
|
||||
spriteScale.size = Vec2(96.0F, 96.0F);
|
||||
|
||||
spriteScale.position = Vec2(((offset*3) + ((32.0F*3)*2)),screenSettings.getHeight() / 2.0F - sprite.size.y / 2.0F);
|
||||
spriteScale.position =
|
||||
Vec2(((offset * 3) + ((32.0F * 3) * 2)),
|
||||
screenSettings.getHeight() / 2.0F - sprite.size.y / 2.0F);
|
||||
|
||||
spriteStrech.mode = SpriteMode::MODE_STRETCH;
|
||||
spriteStretch.mode = SpriteMode::MODE_STRETCH;
|
||||
|
||||
spriteStrech.size = Vec2(96.0F,96.0F);
|
||||
spriteStretch.size = Vec2(96.0F, 96.0F);
|
||||
|
||||
spriteStrech.position = Vec2(((offset*4) + ((32.0F*3)*3)),screenSettings.getHeight() / 2.0F - sprite.size.y / 2.0F);
|
||||
spriteStretch.position =
|
||||
Vec2(((offset * 4) + ((32.0F * 3) * 3)),
|
||||
screenSettings.getHeight() / 2.0F - sprite.size.y / 2.0F);
|
||||
|
||||
TYRA_LOG("Sprite created!");
|
||||
}
|
||||
@@ -253,7 +282,7 @@ void Tutorial10::loadTexture() {
|
||||
|
||||
spriteFlip.id = sprite.id;
|
||||
spriteScale.id = sprite.id;
|
||||
spriteStrech.id = sprite.id;
|
||||
spriteStretch.id = sprite.id;
|
||||
|
||||
TYRA_LOG("Texture loaded!");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user