Christian Fischer avatar Christian Fischer committed d4cf8d1

added a text label to the sample project

Comments (0)

Files changed (2)

Add a comment to this file

samples/HelloWiesel/resources/common/images/font.png

Added
New image

samples/HelloWiesel/src/HelloWiesel.cpp

 #include <wiesel/gl/vbo.h>
 #include <wiesel/io/filesystem.h>
 #include <wiesel/graph/2d/sprite_node.h>
+#include <wiesel/ui/bitmapfont.h>
+#include <wiesel/ui/label_node.h>
 #include <wiesel.h>
 
 using namespace wiesel;
 		sprite->setScale(size / sprite->getContentSize().getMin());
 		sprite->retain();
 
+		// load the bitmap font
+		File*			font_file		= Engine::getCurrent()->getAssetFileSystem()->findFile("/images/font.png");
+		Texture*		font_texture	= Texture::fromFile(font_file);
+		SpriteSheet*	font_ss			= new SpriteSheet(font_texture);
+
+		// configure the font
+		font_ss->createRasterFrames(16, 8,  0, 26, 'A');
+		font_ss->createRasterFrames(16, 8, 32, 26, 'a');
+		font_ss->createRasterFrames(16, 8, 97, 31, '!');
+		BitmapFont *font = new BitmapFont(font_ss);
+
+		label = new LabelNode();
+		label->setFont(font);
+		label->setText("Hello Wiesel");
+		label->setPosition(center_x, 0.0f);
+		label->setPivot(0.5f, 0.0f);
+		label->setScale(screen.width / label->getContentSize().width * 0.95f);
+		label->retain();
+
 		Scene *scene = new Scene();
 		scene->addChild(sprite);
+		scene->addChild(label);
 		pushScene(scene);
 
 		return true;
 
 private:
 	Texture*		texture;
+	Font*			font;
+
 	SpriteNode*		sprite;
+	LabelNode*		label;
 };
 
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.