Some Questions

For developers using the Construct 2 Javascript SDK

Post » Thu Aug 27, 2015 3:00 pm

Hey,

I'm wondering if someone can help me write a function. What I need to do is learn how to move objects that are already drawn on the layout. They would be placed there by the back end user. I think the function I'm writing would help a few people. It's really simple, and might be doable through events, but this one action plugin is cool. Maybe we could add to it for the other users. Likely one around, but what ever.

Thanks,
Jeremy.
B
7
S
2
Posts: 92
Reputation: 663

Post » Thu Aug 27, 2015 3:08 pm

To better suit the question. Is there an array of objects on the layout I can loop through, and access members and functions of those objects...

Code: Select all
for(key in objects)
{
      if(key == 'name') 
     {
        if objects[key] == 'Cat'
       {
           // do this.
       }

   }
}
B
7
S
2
Posts: 92
Reputation: 663

Post » Mon Aug 31, 2015 6:35 am

Look the source of mutuware Circle Behavior....
http://gigatron3k.free.fr/Intro/

https://www.shadertoy.com/user/gigatron

https://twitter.com/realistquantum

Ezekiel 1-4 ; ufo landing explanation ..

CONSTRUCT 2 THE ONLY FAST WAY TO HTML5

Image
B
61
S
20
G
29
Posts: 815
Reputation: 22,093

Post » Mon Aug 31, 2015 10:57 pm

Hey thanks Gigatron, what's mutuware Circle Behavior? Third party?
B
7
S
2
Posts: 92
Reputation: 663

Post » Mon Aug 31, 2015 11:11 pm

I'm not really seeing what I need in there. I'm looking for a way to loop through all the objects in a layout. So that I can run a specific operation on the object with a certain name.
B
7
S
2
Posts: 92
Reputation: 663

Post » Tue Sep 01, 2015 3:22 am

Message: JeremyBenson11 is not yet permitted to post plain text URLS (300 rep required). 1 URLS removed. Why?
I think I found something that might be useful to me.I need some clarification.

What I see is this:

runtime.types_by_index[]
An array of all the object types in the project.

What would be in that array? Would I be able to access objects from there?

Also the page says this:

The runtime object represents a single instance of a user's project running in the browser. It is usually accessed via this.runtime from an object instance. Remember only documented properties and methods should be used.

What does it mean. The run-time is accessed form an object instance? Does this mean an instance I would have to pass as a param? If so, that kind of defeats the purpose of what I'm trying to do.
B
7
S
2
Posts: 92
Reputation: 663

Post » Tue Sep 01, 2015 12:50 pm

The way to do this is to use an action with an object parameter, and only modify the instances passed to the action. That gives the user control over which objects to modify, as changing every instance in the whole layout (text, UI elements, etc) is obviously not useful.

An object parameter passes the object type which has an 'instances' array. For each instance you can directly assign its x and y properties, and then you must call set_bbox_changed() on the instance after any changes.
Scirra Founder
B
395
S
233
G
88
Posts: 24,376
Reputation: 193,842

Post » Tue Sep 01, 2015 6:35 pm

This is very confusing. Passing an object doesn't seem to help me in my case. I really need to access every object in a layout. I couldn't find a way in Construct to do something to an object by name. I could store text values in an array, as names of items, which are actually sprite names

array[0] = 'hat'
array[1] = 'boots'

You can loop through an array with a foreach... but there doesn't seem to be a simple way to move an object name.

I figured I could make a simple plugin for my game which created an action that moved an element to X,Y simply based on sprites name.

Also I would have a corresponding expression... Then I could use the foreach to loop through the elements of the array in my layout then for each value call the expression move(element, 12, 12), say.. that would put the item of that element at 12 12. I could call the expression for each value in my array and move a whole array of items where ever I wanted.

I'm not that good with this kind of stuff, so figured if I could loop through each object, that would do it.

Other wise I was stuck with a ton of events, acting as a pseudo switch.
B
7
S
2
Posts: 92
Reputation: 663


Return to Javascript SDK

Who is online

Users browsing this forum: No registered users and 2 guests