Graphics

Reply

Sprite Class

So I was looking through the samples last night, and I'm kind of surprised to see how much goes into getting a texture displayed on the screen. There's a lot more lower-level code than I expected, but I also see that there's an included sprite class in the tutorial libraries.

 

What I'm curious about is whether this is going to remain a separate library or be folded into the Sce.PSS.Core.Graphics namespace. There's a paragraph in the documentation (Programming Guide 2) that talks about future development on it in the next release, but it's not clear how it's going to be implemented:

 

"Note: this SimpleSprite class is a simplified version created for explanation in this program guide, its processing is not appropriate for rendering. A formal class is scheduled for release in an SDK after the next version."

 

What's going to be different in the "formal" sprite class? Will it be folded into the Graphics namespace?

-Sean McCafferty, Director, Factory-Eight
Blog and Projects
Please use plain text.

Re: Sprite Class

[ Edited ]

I'm messing around with the included sprite class from TutoLib, and I made an XNA-like SpriteBatch for it by reusing some of the sample code. It's VERY basic, but you can pass it a texture and a rect and get an image drawn on the screen. Here's the class if anyone's interested:

 

using System;
using System.Collections.Generic;

using Sce.Pss.Core;
using Sce.Pss.Core.Environment;

using Sce.Pss.Core.Graphics;
using Sce.Pss.Core.Imaging;
using Sce.Pss.Core.Input;
using Sce.Pss.Utility;

namespace Sample
{
	public class SpriteBatch
	{
		GraphicsContext graphics;
		ImageRect imageRect;
		Matrix4 unitScreenMatrix;
		SimpleSprite sprite;
		ShaderProgram shaderProgram;
		
		public SpriteBatch (GraphicsContext graphics)
		{
			this.graphics = graphics;
			imageRect = graphics.Screen.Rectangle;
			
			this.unitScreenMatrix = new Matrix4(
				 2.0f/imageRect.Width,	0.0f,	0.0f, 0.0f,
				 0.0f, -2.0f/imageRect.Height,	0.0f, 0.0f,
				 0.0f,  0.0f, 1.0f, 0.0f,
				-1.0f, 1.0f, 0.0f, 1.0f);
			
			shaderProgram = new ShaderProgram("shaders/sprite.cgx");
			shaderProgram.SetUniformBinding(0, "u_WorldMatrix");
		}
		
		public void Begin()
		{
			
		}
		
		public void End()
		{
			graphics.SwapBuffers();
		}
		
		public void Draw(Texture2D texture, ImageRect DestinationRect)
		{
			sprite = new SimpleSprite(this.graphics, texture);
			sprite.Position.X = DestinationRect.X;
			sprite.Position.Y = DestinationRect.Y;
			sprite.Position.Z = 0.0f;
			
			graphics.SetShaderProgram(shaderProgram);
			graphics.SetTexture(0, texture);
			shaderProgram.SetUniformValue(0, ref unitScreenMatrix);
			
			sprite.Render();
		}
		
	}
}

 

-Sean McCafferty, Director, Factory-Eight
Blog and Projects
Please use plain text.

Re: Sprite Class

@NayusDante,

 

Thank you for providing that code, I am sure that it will help alot of people out :smileyhappy:

 

Regarding you question about the future of the SimpleSprite class, we will be providing a 2D Game Engine library in our next release, and the tutorial will change to use the new library instead of Tutolib.

 

Thanks.

PlayStation®Mobile Dev Team
Please use plain text.

Re: Sprite Class

Thanks for the follow up. Do we have a timeframe on the 2D library?

And on that note, what's the estimated timeframe on the next major revision to PSS?
-Sean McCafferty, Director, Factory-Eight
Blog and Projects
Please use plain text.

Re: Sprite Class

For users that haven't seen the other thread ( http://community.eu.playstation.com/t5/Graphics/2D-Game-Engine/td-p/14335819 ), we'll be releasing this in January 2012.
PlayStation®Mobile Dev Team
Please use plain text.

Level 3

Level 3
Rogerdodger91
Posts: 235
Registered: ‎02-12-2011
Message 6 of 9 (607 Views)

Re: Sprite Class

Nayus what is that Sce.Pss.Utility library you are using?
Please use plain text.

Re: Sprite Class

I'm using the SimpleSprite class from one of the samples. The namespace on that file is Utility and I referenced it rather than change the namespace on the file. There is no Utility namespace in the core library.

Basically, this class depends on the SimpleSprite class.

I wrote this before I saw that there were yet more demo libraries, so SimpleSprite might not be the best one to use. I just wanted an XNA-like draw method to get images on the screen, and it worked well enough. This is the one that the documentation described as "not good for production; wait for the final 2D library," so that might explain why I needed to run GC.Collect() every frame to avoid overflows.
-Sean McCafferty, Director, Factory-Eight
Blog and Projects
Please use plain text.

Member

Member
IngMemin
Posts: 1
Registered: ‎09-05-2012
Message 8 of 9 (368 Views)

Re: Sprite Class

Hi there, I was trying this sample too but I can't understand what the constructor Matrix4 does so do you know any reference or further information about the Matrix4 class? Or if you can give an explanation will be great. I will appreciate your answer :smileyhappy: Thank you in advance.
Please use plain text.

Re: Sprite Class

Hey IngMemin,

 

Matrix4 is an implementation of a tranformation matrix. You can transform (scale, skew, translate, rotate, flip etc) a 2D or 3D point (Vector2D / Vector3D) with one of these tranformation matrices. 

 

A transformation matrix is (usually) constructed of 16 values, some of which represent rotation (and are generated based on values entered) and some of which represent translation.

 

The following page describes the concept of transformation matrices pretty well:

http://people.bath.ac.uk/sej20/transform.html

 

All in all, you dont *really* need to know the internals to them to be able to use them. For example, the point [x,y,z] can be multiplied by a tranformation matrix4 [1-16 vals] to tranform the original point.

 

Please use plain text.
This widget could not be displayed.
Announcements

Welcome to the PlayStation Mobile Developer Forums


This is a community for the discussion of technical topics with other developers and SCE engineers. Posting ideas/requests are also appreciated. Join the discussion!

PlayStation®Mobile開発者フォーラムでは世界中の開発者の皆様と一緒に、議論や情報交換が可能です。SCEも議論に参加し、皆様の開発をサポートします。アイデアやリクエストも大歓迎です。ぜひご参加ください。

PSM Developer Registration (for free) on PSM DevPortal is required to post on the forum.
Please sign out then sign in again to the forum and PSM DevPortal after you have completed the registration.

フォーラムへ投稿をするにはPSM DevPortalへの登録(無料)が必要です。
登録後はフォーラムと PSM DevPortalを一度ログアウトし、再度ログインしてください。






Recent News