GameEngine2D

Reply

Level 2

Level 2
favi85
Posts: 32
Registered: ‎02-05-2012
Message 1 of 3 (223 Views)

ARghh!

I'm so close I can feel it.

 

I just need to get this square bouncing on the screen without having to make another class:

 

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.HighLevel.GameEngine2D;
using Sce.Pss.HighLevel.GameEngine2D.Base;

 

using System.Threading;
using System.Diagnostics;

 

namespace ss
{
public class AppMain
{

static GraphicsContext graphics;
static Texture2D rect;

float positionX;
float positionY;



static void Main (string[] args)
{
Director.Initialize();

Random rand = new System.Random();

int dirX = rand.Next(2) > 0 ? 1 : -1;;
int dirY = rand.Next(2) > 0 ? 1 : 1;
float addPosition;
var width = Director.Instance.GL.Context.GetViewport().Width;
var height = Director.Instance.GL.Context.GetViewport().Height;



var scene=new Scene();
scene.Camera.SetViewFromViewport();


var ti=new TextureInfo(
new Texture2D("/Application/rect.png", false));

var sprite=new SpriteUV() {TextureInfo=ti};
rect = new Texture2D("Application/rect.png", false);

sprite.Quad.S=ti.TextureSizef;

sprite.CenterSprite();

sprite.Position=scene.Camera.CalcBounds().Center;

var positionX=rand.Next (0, width);
var positionY=rand.Next (0, height);


dirX=rand.Next(2) > 0 ? 1 : -1;
dirY=rand.Next (2) > 0 ? 1 : 1;

addPosition = 0 + (float)rand.NextDouble() * 5.0f;

scene.AddChild(sprite);

Director.Instance.RunWithScene(scene, true);

bool gameOver = false;

while(!gameOver)
{
Sce.Pss.HighLevel.GameEngine2D.Director.Instance.Update();

if(Input2.GamePad0.Circle.Press == true)
gameOver = true;

Sce.Pss.HighLevel.GameEngine2D.Director.Instance.Render();
Sce.Pss.HighLevel.GameEngine2D.Director.Instance.GL.Context.SwapBuffers();
Sce.Pss.HighLevel.GameEngine2D.Director.Instance.PostSwap();






}
Director.Terminate();
}
}}

Please use plain text.

Re: ARghh!

[ Edited ]

Hi favi85,

 

To control the ball bouncing around the screen, you will need to implement some code which will check and move the ball in your update loop, which will be run each frame. On each frame, you want to put the ball along the X and Y axis a litle further, and when the ball reaches the edge of the screen then you want to reverse the horizontal or vertical direction. 

 

I've dropped the changes into your code and highlighted them (bold & italic). I've not fully tested it with your code, but the logic should be all there  :smileyhappy:

 

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.HighLevel.GameEngine2D;
using Sce.Pss.HighLevel.GameEngine2D.Base;
 
using System.Threading;
using System.Diagnostics;
 
namespace ss
{
public class AppMain
{

static GraphicsContext graphics;
static Texture2D rect;

float positionX;
float positionY;

// Adjust these to be the speed that you wish 
static float directionX = 2f;
static float directionY = 2f;
static void Main (string[] args) { Director.Initialize(); Random rand = new System.Random(); int dirX = rand.Next(2) > 0 ? 1 : -1;; int dirY = rand.Next(2) > 0 ? 1 : 1; float addPosition; var width = Director.Instance.GL.Context.GetViewport().Width; var height = Director.Instance.GL.Context.GetViewport().Height; var scene=new Scene(); scene.Camera.SetViewFromViewport(); var ti=new TextureInfo( new Texture2D("/Application/rect.png", false)); var sprite=new SpriteUV() {TextureInfo=ti}; rect = new Texture2D("Application/rect.png", false); sprite.Quad.S=ti.TextureSizef; sprite.CenterSprite(); sprite.Position=scene.Camera.CalcBounds().Center; var positionX=rand.Next (0, width); var positionY=rand.Next (0, height); dirX=rand.Next(2) > 0 ? 1 : -1; dirY=rand.Next (2) > 0 ? 1 : 1; addPosition = 0 + (float)rand.NextDouble() * 5.0f; scene.AddChild(sprite); Director.Instance.RunWithScene(scene, true); bool gameOver = false; while(!gameOver) { Sce.Pss.HighLevel.GameEngine2D.Director.Instance.Update(); if(Input2.GamePad0.Circle.Press == true) gameOver = true; tile.Position = new Vector2(tile.Position.X + directionX, tile.Position.Y + directionY);

// You may have to adjust the tile.Scale.* calculations if you stop calling CenterSprite()

// Going off the left of the screen.
if((sprite.Position.X - (sprite.Scale.X / 2)) < 0)
directionX *= -1;

// Going off the right of the screen
if((sprite.Position.X + (sprite.Scale.X / 2)) > Director.Instance.GL.Context.Screen.Width)
directionX *= -1;

// Going off the top of the screen
if((sprite.Position.Y + (sprite.Scale.Y / 2)) > Director.Instance.GL.Context.Screen.Height)
directionY *= -1;

// Going off the bottom of the screen
if((sprite.Position.Y - (sprite.Scale.Y / 2)) < 0)
directionY *= -1;
if(Input2.GamePad0.Circle.Press == true)
gameOver = true;
Sce.Pss.HighLevel.GameEngine2D.Director.Instance.Render(); Sce.Pss.HighLevel.GameEngine2D.Director.Instance.GL.Context.SwapBuffers(); Sce.Pss.HighLevel.GameEngine2D.Director.Instance.PostSwap(); } Director.Terminate(); } }}

 

Hope this helps

PlayStation®Mobile Dev Team
Please use plain text.

Level 2

Level 2
favi85
Posts: 32
Registered: ‎02-05-2012
Message 3 of 3 (173 Views)

Re: ARghh!

very cool!

Please use plain text.
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を一度ログアウトし、再度ログインしてください。