How to use/setup TexturePacker2 libgdx - animation

I have a difficulty with texturepacker2 from libgdx. I was trying to create textureAtlas using texturepakcer2 so that I can create animated images. However I could not use
TexturePacker2.process(Input Directory Path", "Output Directory Path", "texture_file");
Because it could not recognize TexturePacker2.
Even thought I import gdx-tool.jar file inside libs and also added libraries through
Project -> Properties -> Java Build Path -> Libraries -> Add jars, it still cannot resolve nor recognize the gdx-tool.jar.
How can I create texture atlas using TexturePakcer2? I heard there is a way to create using nightly-build from libgdx, how can I do it? When I unzip latest nightly-build there were so many jar, but I could only run setup-ui.

There are several ways. I used to take the way of implementing it into my Desktop application. Whenever i start it, the Atlas is generated. (If i changed something in it).
public class Main
{
public static void main(String[] args)
{
LwjglApplicationConfiguration cfg = new LwjglApplicationConfiguration();
cfg.title = "MyApp";
cfg.useGL20 = true;
cfg.fullscreen = false;
// switch for fullscreen
if (cfg.fullscreen)
{
cfg.width = Toolkit.getDefaultToolkit().getScreenSize().width;
cfg.height = Toolkit.getDefaultToolkit().getScreenSize().height;
}
else
{
cfg.width = 1280;
cfg.height = 720;
}
cfg.addIcon("data/appiconWindows.png", FileType.Internal);
// automatic packing of the textures and images and so on
Settings settings = new Settings();
settings.maxWidth = 2048;
settings.maxHeight = 2048;
settings.paddingX = 0;
settings.paddingY = 0;
TexturePacker2.process(settings, "directory with the files",
"output dir", "name of Atlas"); //third is outputdir
new LwjglApplication(new MainClass(), cfg);
}
}
Dont forget to add the tools lib to the Desktop project. gdx-tools.jar From the nightly or the Stable.
Else you can call it with the console. Like this:
java -cp gdx.jar;extensions/gdx-tools/gdx-tools.jar com.badlogic.gdx.tools.texturepacker.TexturePacker inputDir [outputDir] [packFileName]

Use TexturePacker from com.badlogic.gdx.tools.imagepacker.TexturePacker then create a class as below:
public class TextureSetup {
public static void main(String[] args) {
//TexturePacker; using default settings
TexturePacker.Settings packSettings = new TexturePacker.Settings();
TexturePacker.process(packSettings, "input-folder", "output-folder", "textures.pack");
}
}

Related

Getting a FileNotFoundException in VSCode, but not in JGrasp

Ok, so this is what's going on. I'm trying to learn how to use vscode (switching over from jgrasp). I'm trying to run this old school assignment that requires the use of outside .txt files. The .txt files, as well as other classes that I have written are in the same folder and everything. When I try to run this program in JGrasp, it works fine. Though, in VSCode, I get an exception. Not sure what is going wrong here. Thanks Here is an example:
import java.io.*;
public class HangmanMain {
public static final String DICTIONARY_FILE = "dictionary.txt";
public static final boolean SHOW_COUNT = true; // show # of choices left
public static void main(String[] args) throws FileNotFoundException {
System.out.println("Welcome to the cse143 hangman game.");
System.out.println();
// open the dictionary file and read dictionary into an ArrayList
Scanner input = new Scanner(new File(DICTIONARY_FILE));
List<String> dictionary = new ArrayList<String>();
while (input.hasNext()) {
dictionary.add(input.next().toLowerCase());
}
// set basic parameters
Scanner console = new Scanner(System.in);
System.out.print("What length word do you want to use? ");
int length = console.nextInt();
System.out.print("How many wrong answers allowed? ");
int max = console.nextInt();
System.out.println();
//The rest of the program is not shown. This was included just so you guys could see a little bit of it.
If you're not using a project, jGRASP makes the working directory for your program the same one that contains the source file. You are creating the file with a relative path, so it is assumed to be in the working directory. You can print new File(DICTIONARY_FILE).getAbsolutePath() to see where VSCode is looking (probably a separate "classes" directory) and move your data file there, or use an absolute path.

How to test BundleConfig

I have a problem with my bundles. Files .min is not being generated as reported on this link.
I have to create a test for it. How to do this?
[TestInitialize]
public void Setup()
{
BundleConfig.RegisterBundles(BundleTable.Bundles);
}
[TestMethod, Owner("Bundles")]
public void Deve_realizar_bundle_arquivos_min()
{
// Arrange
// Act
var bundle = BundleTable.Bundles.GetBundleFor("~/Scripts");
// Assert
// How to check if file "jquery.pnotify.min.js" is in bundle??
}
You can unit test bundles via the Optimizer/Optimization settings classes in the 1.1-beta1 package:
You will also need to implement a VirtualPathProvider if you want to truly unit test this, but then you should be able to do something like:
BundleCollection bundles = new BundleCollection();
OptimizationSettings config = new OptimizationSettings() {
ApplicationPath = TestContext.DeploymentDirectory,
BundleTable = BundleConfig.RegisterBundles(bundles)
};
BundleResponse response = Optimizer.BuildBundle("~/bundles/js", config);
Assert.IsNotNull(response);
Assert.AreEqual("alert(\"first\")", response.Content);
Assert.AreEqual(JsMinify.JsContentType, response.ContentType);
response = Optimizer.BuildBundle("~/bundles/css", config);
Assert.IsNotNull(response);
Assert.AreEqual("Css1{color:blue}", response.Content);
Assert.AreEqual(CssMinify.CssContentType, response.ContentType);

Getting "main" Assembly version number

I have a solution with libraries (DLLs) which are used in 2 identical projects (one for WP7, another for WP8). In one of the libraries I have the code which determines the version of the application.
private static Version mVersion;
public static Version Version {
get {
if (mVersion == default(Version)) {
var lcAssembly = Assembly.GetExecutingAssembly();
var parts = lcAssembly.FullName.Split(',');
var lcVersionStr = parts[1].Split('=')[1];
mVersion = new Version(lcVersionStr);
}
return mVersion;
}
}
The problem is that this code returns the version number of the library itself because of this Assembly.GetExecutingAssembly() code. How to get a MAIN Assembly version and not DLL's?
That's a great question on code-sharing between WP7 and WP8.
The simplest way for you to do that would be to read the AppManfiest.xml file at run-time, get the EntryType and use that to get at the entry point Assembly instance. Here's how a sample AppManfiest.xml looks like once MSBuild did its magic on it:
<Deployment xmlns="http://schemas.microsoft.com/client/2007/deployment" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" EntryPointAssembly="myAssembly" EntryPointType="myNamespace.App" RuntimeVersion="4.7.50308.0">
<Deployment.Parts>
<AssemblyPart x:Name="myAssembly" Source="myAssembly.dll" />
</Deployment.Parts>
</Deployment>
And here's how you would read the file, get the attributes, then get the entry point type and finally the entry point assembly:
private void MainPage_Loaded(object sender, RoutedEventArgs e)
{
var appManfiest = XElement.Load("AppManifest.xaml");
var entryAssemblyName = appManfiest.Attribute("EntryPointAssembly").Value;
var entryTypeName = appManfiest.Attribute("EntryPointType").Value;
Type entryType = Type.GetType(entryTypeName + "," + entryAssemblyName);
Assembly entryAssembly = entryType.Assembly;
}
That's a simple solution and it works. However, that isn't the cleanest architectural solution. The way I'd implement this solution is to have an interface declared in the shared library, both WP7 and WP8 implement that interface and register their implementation with an IoC container.
For example, let's say you need to "DoSomething" in the shared library that's platform version specific. First you'll create have an IDoSomething interface. Let's also assume you have an IoC standing by.
public interface IDoSomething
{
}
public static class IoC
{
public static void Register<T>(T t)
{
// use some IoC container
}
public static T Get<T>()
{
// use some IoC container
}
}
In your WP7 app you'll implement the shared Interface for WP7 and register it once the WP7 starts up.
public App()
{
MainPage.IoC.Register(new MainPage.DoSomethingWP7());
}
private class DoSomethingWP7 : IDoSomething
{
}
You'll also do the same for WP8 in the WP8 app. And in your shared library you can then ask for the relevant interface regardless of its platform version specific implementation:
IDoSomething sharedInterface = IoC.Get<IDoSomething>();
I have a simpler answer. I think you are close with what you are doing. I just used your code with one modification so I can use it with the Telerik controls. Here's what I did. I located your code in my project's App class (codebehind of App.Xaml). I made one change that I think will take care of your problem:
private static Version mVersion;
public static Version Version {
get {
if (mVersion == default(Version)) {
var lcAssembly = typeof(App);
var parts = lcAssembly.FullName.Split(',');
var lcVersionStr = parts[1].Split('=')[1];
mVersion = new Version(lcVersionStr);
}
return mVersion;
}
}
Now I can get the version number by calling "App.Version".
This worked for me:
var appAssembly = Application.Current.GetType().Assembly;
var appAssemblyVersion = appAssembly.GetName().Version;
I tested with WP7.1 and WP8.0.

C# load DLL from different folder?

I have a C# project that contains 1 EXE and about 7 DLLs. What I would like to have is a folder beside the EXE called "Library" (or something similar) that contains all the DLLs so that it is a bit more organized and looks better for the end user.
I know this can be done using an AppConfig but the I don't want another file beside the EXE. All I want is the main EXE and the folder.
Is it possible to use AppConfig and embed it or load the DLLs without using a AppConfig that won't change how I currently use my DLLs? I know you can load a DLL at run time but I don't think that is what I am looking for.
Thanks!
EDIT
I know the pros and cons to doing this, so please only answers on how to do this and no advice as to why I should or should not do this.
Use System.Reflection.Assembly.LoadFrom(path).
LoadFrom will allow it to look in the same folder as the targetted dll for any dependencies. If you use Load, then it will not consider dlls that are sitting in the same folder as the dll you Load.
I know this doesn't directly answer your question, but manually calling LoadFrom on the DLLs early in your process startup should do the trick if you want an "xcopy" installable .net app or something.
PrettyBin is your solution. It does this beautifully!
SetDllDirectory() + carefully coded AssemblyResolve. Works for me in a nontrivial project, with no DLL hell.
https://github.com/TASVideos/BizHawk/blob/d05ddabf5f22debf47369f94868462a75ea0b466/BizHawk.Client.EmuHawk/Program.cs
I created new console application-launcher. In app folder contains my EXE file - MyApp.exe and all DLLs.
static void Main(string[] args)
{
var process = new Process
{
StartInfo =
{
FileName = "app\\MyApp.exe",
}
};
process.Start();
}
If you want the application to be launched when you drag certain files onto the EXE:
class Program
{
static void Main(string[] args)
{
if (args.Length > 0)
{
String FileName = System.IO.Path.GetDirectoryName( System.Reflection.Assembly.GetExecutingAssembly().Location )
+ "\\app\\MyApp.exe";
ProcessStartInfo startInfo = new ProcessStartInfo(FileName);
startInfo.WindowStyle = ProcessWindowStyle.Normal;
startInfo.Arguments = args[0].ToString();
Process.Start(startInfo);
}
else {
var process = new Process
{
StartInfo =
{
FileName = "app\\MyApp.exe",
}
};
process.Start();
}
}
}

How can I add a button to the stage in flex using only as3?

I am using the Flex SDK within visual studio and trying to dynamically add a button to the stage. Here is a quick example of what I am doing.
public class Test extends Sprite
{
public function Test()
{
init();
}
private function init():void
{
var btnBrowse:Button = new Button();
btnBrowse.label = "Browse";
btnBrowse.x = 0;
btnBrowse.y = 0;
btnBrowse.width=100;
btnBrowse.height=100;
addChild(btnBrowse);
}
}
Nothing seems to show up and the screen is still empty. I am importing mx.controls.* for the button. Could that create an issue since I am not using mxml only as3?
You can't use Flex framework controls in an AS3 Only project. If you are trying to avoid MXML then just create a new Flex Project where the root tag is like:
<FooApplication xmlns="*"/>
And create a new AS3 Class like:
package {
import mx.core.Application;
public class FooApplication extends Application {
// now override something like createChildren to add a button.
}
}
Try changing the base class from Sprite to Canvas.

Resources