Menu

Show posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Show posts Menu

Messages - DoorKnobHandle

#241
Ultimately, you don't want to use characters or objects at all. In order to be completely free of any arbitrary limits (except performance at some point), you need to 'raw draw' your enemies, projectiles etc. (which, nowadays, is handled by dynamic sprites and drawing surfaces). Here's how I do this nowadays:

First of all, create a new script/header file by right-clicking the 'Scripts' node and clicking on 'New script'. Call it 'Renderer' and enter this into the new header file (Renderer.ash):

Code: AGS

struct Renderer
{
	import static DynamicSprite *registerRenderTarget(GUI *interface);
	import static DrawingSurface *getRenderTargetSurface(DynamicSprite *renderTarget);
	import static bool updateRenderTarget(GUI *interface, DynamicSprite *renderTarget);
	import static void destroyRenderTarget(DynamicSprite *renderTarget);
};


And paste this into the script file (Renderer.asc):

Code: AGS

static DynamicSprite *Renderer::registerRenderTarget(GUI *interface)
{
	if (interface != null)
	{
		if (interface.BackgroundGraphic > 0)
			return DynamicSprite.CreateFromExistingSprite(interface.BackgroundGraphic);
		else
			return DynamicSprite.Create(interface.Width, interface.Height);
	}
	
	return null;
}

static DrawingSurface *Renderer::getRenderTargetSurface(DynamicSprite *renderTarget)
{
	if (renderTarget == null)
		return null;
		
	return renderTarget.GetDrawingSurface();
}

static bool Renderer::updateRenderTarget(GUI *interface, DynamicSprite *renderTarget)
{
	if (interface == null || renderTarget == null)
		return false;
		
	interface.BackgroundGraphic = renderTarget.Graphic;
	
	return true;
}

static void Renderer::destroyRenderTarget(DynamicSprite *renderTarget)
{
	if (renderTarget != null)
		renderTarget.Delete();
}


As you can probably tell, this now gives you a Renderer structure to play with that includes four helpful functions. Here's how to use the new functionality:

- You are going to be drawing on GUIs with this code (in other words: GUIs are used as 'render targets'), that's a flexible and fast way to render and allows you to seperate the things you render into layers, move/rotate it and so on. For the time being, you should probably just create a new empty fullscreen interface by right-clicking on the 'GUIs' node, clicking on 'New GUI' and setting it up. You could call the GUI 'gRenderTarget' for example.

- You need a global variable (a pointer to a dynamic sprite) that represents your render target. For example, you could go to your global script (GlobalScript.asc) and add this line at the very top of the file:

Code: AGS

DynamicSprite *renderTarget;


- on game_start in GlobalScript.asc (ie. when your game starts, before you begin drawing anything), you need to register the render target GUI as follows (insert your global variable and GUI name if they differ):

Code: AGS

renderTarget = Renderer.registerRenderTarget(gRenderTarget);


- in repeatedly_execute in GlobalScript.asc (or whenever you want to draw something), this is how to render (note that you don't have to call 'surface.Clear()' if you don't want to clear what was previously on the render target from when you last rendered):

Code: AGS

DrawingSurface *surface = Renderer.getRenderTargetSurface(renderTarget);
surface.Clear();
	
// here you can use the surface.Draw*() functions to render
	
surface.Release();
Renderer.updateRenderTarget(gRenderTarget, renderTarget);


And then, when you exit the game, you should call Renderer.destroyRenderTarget to clean up the used memory:

Code: AGS

Renderer.destroyRenderTarget(renderTarget);


This might seem a bit daunting at first but it will enable you to have a high number of things on screen at the same time. Now you'd need to change your current code to not use characters or objects but instead draw a sprite instead. If you don't have that yet, you definitely need a struct for your enemies and your projectiles, an array of instances of each of these structs and then you can give each struct a render function for example that renders the enemy/projectile to the render target. Some pointers:

Code: AGS

// in Projectile.ash

struct Projectile
{
    int x, y;

    import void render(DrawingSurface *surface);
};

#define MAX_PROJECTILES 1024

Projectile projectile[MAX_PROJECTILES];


// in Projectile.asc

void Projectile::render(DrawingSurface *surface)
{
    surface.DrawImage(this.x, this.y, /*sprite slot*/ 12);
}


// in GlobalScript.asc

void repeatedly_execute()
{
    DrawingSurface *surface = Renderer.getRenderTargetSurface(renderTarget);
    surface.Clear();
	
    int i = 0;
    while (i < MAX_PROJECTILES)
    // loop through each projectile
    {
        // render the projectile
        projectile[i].render(surface);
        i++;
    }

    surface.Release();
    Renderer.updateRenderTarget(gRenderTarget, renderTarget);
}


Please note that the above pointers are rough and will not work when simply copy/pasted. You still need to import/export the array and keep track of which projectiles out of the 1024 are 'active' (ie. on the screen) and so on.

Hopefully this helps you and isn't too confusing! :p
#243
Yup that one works. Thanks again to Christina and you for organizing and hosting an amazing week!
#244
Hahaha nice shot. And one I didn't manage to photobomb! ;)
#245
Mittens was awesome, enjoyed it greatly - and I think everyone did. Now I read every post in the Mitteneer voices!

@Oldschool_Wolf: It's real names almost exclusively, except when newbies like me can't quite remember some real names yet in the first couple of days.
#246
Haha that's perfect! :p
#247
Quote from: Ascovel on Fri 09/08/2013 14:51:56
I'll be coming by train at Ostbahnhof at 11:00 AM. So if I won't arrive at the villa by night, it means something is wrong.

I'll be at Ostbahnhof (Berlin East Central Station) two hours after you! If you're still around there by then, I have short blond hair and will be wearing a black and red striped shirt!
#248
+1 on the HDMI cable, that would definitely be useful!

Also: note to self, don't forget to bring a quiz prize!
#249
General Discussion / Re: Tropes vs Women
Sat 03/08/2013 22:48:35
Hah, thanks!

I swear I tried that >.>
#250
General Discussion / Re: Tropes vs Women
Sat 03/08/2013 22:18:49
I found my own opinion on the matter pretty well-reflected and covered by this. Might be worth to watch for anybody interested in the matter.

(Looks like youtube embedding is broken again - or am I doing it wrong?)
#251
You tried CTRL+0, right?

EDIT: On second thought, it sounds like you probably did, so disregard, sorry!
#252
Clean #2 so clearly won the vote, I REALLY don't see the point in complicated this process but oh well.

Once "Tier 2" starts, it'll be Clean #2 for me again.
#253
Oh yeah sure, I thought you had to go there for some reason, B can be removed! Thank you so much!
#254
Sweet that would be perfect and awesome, Arj0n! :)

I added a pin for the east central station where I will arrive (it's pin C): http://goo.gl/maps/gGba0

It is pretty much exactly on the way! If you can aim to be there at 1:30, as you said, that'd be great! I have your phone number and you have mine, so if my train is delayed or whatever, we can get in touch!

Does that sound good?
#255
@Arj0n: You're at the central station, I'm at east! :p But I can take a train from east to central to meet up with you there, they seem to be travelling 10 minutes every 5 or so, so no big deal. When do you think you'll be at Berlin central station roughly on Saturday?

@abstauber: Thanks, those are definitely other good options, if getting picked up by Arj0n doesn't work out, I'll look into that!
#256
Okay, I will be arriving at the Berlin East Train Station on Saturday at 1:10 pm (Google Maps pin: http://goo.gl/maps/HkHLo). Can anybody pick me up from there? I'm willing to wait an hour or two of course. If nobody can come by the trainstation, I'll take a taxi or try and get closer with public transportation from there.
#257
Okay, looks like the Steam Summer Sale is over! In total, I spent 30 bucks on these 10 games:

Code: AGS

Counter-Strike: Global Offensive
Deus Ex: Game of the Year Edition
Deus Ex: Human Revolution
Deus Ex: Human Revolution - The Missing Link DLC
FTL: Faster Than Light
Grand Theft Auto IV
Hotline Miami
Retro City Rampage
System Shock 2
Wizorb


Can't wait for my vacation to start in a week!

What did you guys pick up?
#258
YES! CS:GO went on sale again a minute ago. Bought it right away!
#259
Having internet does not mean abandoning all social aspects! :p Obviously I don't want internet so that everybody is on their laptop or smartphone all day, but it would certainly be useful to show each other projects we're working on, to play and show other people music we like (via youtube) and so on.

EDIT: But yeah, if we can't get internet, it's not such a big deal as my previous post made it sound like. It'll be great fun regardless.
#260
You should be receiving my money in the next couple of days, abstauber, I send it over this morning.

And yeah, can we be sure we will have decent (ie. usable) internet there? Is there a statement/can we check or won't that be necessary? Having no connection there or have it be very limited would suck!
SMF spam blocked by CleanTalk